Revision 42836
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.ui/src/main/java/org/gvsig/gui/beans/controls/comboscale/ComboScale.java | ||
---|---|---|
57 | 57 |
static private int eventId = Integer.MIN_VALUE; |
58 | 58 |
|
59 | 59 |
private Long lastValue = null; |
60 |
|
|
60 |
|
|
61 | 61 |
// jaume |
62 | 62 |
private class ComboScaleItem { |
63 | 63 |
|
64 | 64 |
private long value; |
65 |
private boolean temporal; |
|
65 | 66 |
|
66 | 67 |
public ComboScaleItem(long itemScale) { |
67 | 68 |
this.value = itemScale; |
69 |
this.temporal=false; |
|
68 | 70 |
} |
69 | 71 |
|
72 |
public ComboScaleItem(long itemScale, boolean temporal) { |
|
73 |
this.value = itemScale; |
|
74 |
this.temporal=temporal; |
|
75 |
} |
|
76 |
|
|
70 | 77 |
public String toString() { |
71 | 78 |
return NumberFormat.getNumberInstance().format(value); |
72 | 79 |
} |
... | ... | |
79 | 86 |
public long getValue() { |
80 | 87 |
return value; |
81 | 88 |
} |
89 |
|
|
90 |
public boolean isTemporal(){ |
|
91 |
return temporal; |
|
92 |
} |
|
82 | 93 |
} |
83 | 94 |
|
84 | 95 |
/** |
... | ... | |
91 | 102 |
|
92 | 103 |
/** |
93 | 104 |
* This method initializes this |
94 |
*
|
|
105 |
* |
|
95 | 106 |
* @return void |
96 | 107 |
*/ |
97 | 108 |
private void initialize() { |
... | ... | |
106 | 117 |
|
107 | 118 |
/** |
108 | 119 |
* This method initializes jComboBox |
109 |
*
|
|
120 |
* |
|
110 | 121 |
* @return javax.swing.JComboBox |
111 | 122 |
*/ |
112 | 123 |
private JComboBox getJComboBox() { |
... | ... | |
159 | 170 |
} |
160 | 171 |
return jComboBox; |
161 | 172 |
} |
162 |
|
|
173 |
|
|
163 | 174 |
public Object getValue() { |
164 | 175 |
return lastValue; |
165 | 176 |
} |
... | ... | |
175 | 186 |
|
176 | 187 |
/** |
177 | 188 |
* This funcion ONLY sets the text in combo. It will NOT call listeners. |
178 |
*
|
|
189 |
* |
|
179 | 190 |
* @param scale |
180 | 191 |
*/ |
181 |
public void setScale(long item) {
|
|
192 |
public void setScale(long scale) {
|
|
182 | 193 |
bDoCallListeners = false; |
183 |
getJComboBox().setSelectedItem(new ComboScaleItem(item));
|
|
194 |
getJComboBox().setSelectedItem(new ComboScaleItem(scale));
|
|
184 | 195 |
bDoCallListeners = true; |
196 |
|
|
197 |
DefaultComboBoxModel model = |
|
198 |
(DefaultComboBoxModel) jComboBox.getModel(); |
|
199 |
|
|
200 |
//The item is inserted in the data model but marked as temporal |
|
201 |
//Only one temporal can be in the data model |
|
202 |
for (int i = 0; i < model.getSize(); i++) { |
|
203 |
ComboScaleItem itemScale = (ComboScaleItem) model.getElementAt(i); |
|
204 |
if (itemScale.isTemporal()) { |
|
205 |
model.removeElement(itemScale); |
|
206 |
break; |
|
207 |
} |
|
208 |
} |
|
209 |
insertScaleIfNotPresent(scale, true); |
|
185 | 210 |
} |
186 | 211 |
|
187 |
/** |
|
188 |
* @param scale |
|
189 |
*/ |
|
190 |
private void insertScaleIfNotPresent(long scale) { |
|
191 |
// Si viene de un setScale, no insertamos la escala en el combo |
|
212 |
private void insertScaleIfNotPresent(long scale, boolean isTemporal) { |
|
213 |
// Si viene de un setScale, no insertamos la escala en el combo |
|
192 | 214 |
if (!bDoCallListeners) |
193 | 215 |
return; |
194 | 216 |
|
... | ... | |
203 | 225 |
break; |
204 | 226 |
} |
205 | 227 |
} |
228 |
ComboScaleItem newScaleItem = new ComboScaleItem(scale, isTemporal); |
|
206 | 229 |
if (!inserted) { |
207 | 230 |
for (int i = 0; i < model.getSize(); i++) { |
208 | 231 |
ComboScaleItem itemScale = |
209 | 232 |
(ComboScaleItem) model.getElementAt(i); |
210 | 233 |
if (scale < itemScale.getValue()) { |
211 |
model.insertElementAt(new ComboScaleItem(scale), i);
|
|
234 |
model.insertElementAt(newScaleItem, i);
|
|
212 | 235 |
inserted = true; |
213 | 236 |
break; |
214 | 237 |
} |
215 | 238 |
} |
216 | 239 |
if (!inserted) |
217 |
model.addElement(new ComboScaleItem(scale));
|
|
240 |
model.addElement(newScaleItem);
|
|
218 | 241 |
} |
219 |
jComboBox.setSelectedItem(new ComboScaleItem(scale)); |
|
242 |
jComboBox.setSelectedItem(newScaleItem); |
|
243 |
|
|
220 | 244 |
isScaleCombo = true; |
221 | 245 |
} |
222 | 246 |
|
247 |
/** |
|
248 |
* @param scale |
|
249 |
*/ |
|
250 |
private void insertScaleIfNotPresent(long scale) { |
|
251 |
insertScaleIfNotPresent(scale, false); |
|
252 |
} |
|
253 |
|
|
223 | 254 |
private void callActionCommandListeners(long scale) { |
224 | 255 |
if (!bDoCallListeners) |
225 | 256 |
return; |
... | ... | |
244 | 275 |
|
245 | 276 |
/** |
246 | 277 |
* Returns the current selected item. |
247 |
*
|
|
278 |
* |
|
248 | 279 |
* @return The value of the selected scale, or -1 if there was an invalid |
249 | 280 |
* value (ie. not long value). |
250 | 281 |
*/ |
Also available in: Unified diff