1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components.table.cells;
21
22
23
24
25
26
27
28 public class LongEnumCell extends LongCell
29 {
30
31 public static final String STATE_DESCRIPTION = "stateDescription";
32
33
34 public static final String STATE_VALUE = "stateValue";
35
36
37
38
39
40 public LongEnumCell()
41 {
42 super();
43
44 }
45
46
47
48
49
50
51
52
53
54 public LongEnumCell(String identifier, Object dataSource, long value,
55 Command[] commands)
56 {
57 super(identifier, dataSource, value, commands);
58 }
59
60
61
62
63
64
65
66
67
68
69
70 public LongEnumCell(String identifier, Object dataSource, long value,
71 Command[] commands, String[] descriptions, Object[] values)
72 {
73 super(identifier, dataSource, value, commands);
74
75 for (int i = 0; i < values.length; i++) {
76 putCharacteristic(STATE_VALUE + i, values[i]);
77 }
78
79 for (int i = 0; i < descriptions.length; i++) {
80 putCharacteristic(STATE_DESCRIPTION + i, descriptions[i]);
81 }
82 }
83
84
85
86
87
88
89
90
91 public String getStateDescription(long i)
92 {
93 return (String)getCharacteristic(STATE_DESCRIPTION + i);
94 }
95
96
97
98
99
100
101
102
103 public Object getStateValue(long i)
104 {
105 return getCharacteristic(STATE_DESCRIPTION + i);
106 }
107
108
109
110
111
112
113
114
115 public String getStateLabel(long l)
116 {
117 String s = getStateDescription(l);
118
119 if (s == null) {
120 StringBuffer sb = new StringBuffer(8);
121 sb.append('<');
122 sb.append(l);
123 sb.append('>');
124 s = sb.toString();
125 }
126
127 return s;
128 }
129
130
131
132
133
134
135
136
137
138 public long toLongValue(String label)
139 {
140 label = label.trim();
141
142 if (label == null || label.length() < 3) {
143 return -1;
144 }
145
146 if (label.charAt(0) == '<' && label.charAt(label.length() - 1) == '>') {
147
148 return Long.parseLong(label.substring(1, label.length() - 1));
149 }
150
151
152 int min = getMinimum(new Long(0)).intValue();
153 int max = getMaximum(new Long(15)).intValue();
154
155 for (int i = min; i <= max; i++) {
156 if (label.equals(getCharacteristic(STATE_DESCRIPTION + i))) {
157 return i;
158 }
159 }
160
161 return -1;
162 }
163 }
164
165