Revision 42443
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.datalocator.app/org.gvsig.datalocator.app.mainplugin/src/main/java/org/gvsig/datalocator/gui/DataSelectionPanel.java | ||
---|---|---|
26 | 26 |
import java.awt.*; |
27 | 27 |
import java.awt.event.ActionEvent; |
28 | 28 |
import java.awt.event.ActionListener; |
29 |
import java.text.Collator; |
|
29 | 30 |
import java.util.ArrayList; |
30 | 31 |
import java.util.Comparator; |
31 | 32 |
import java.util.Date; |
... | ... | |
70 | 71 |
|
71 | 72 |
|
72 | 73 |
/** |
73 |
*
|
|
74 |
* |
|
74 | 75 |
* This panel lets the user choose a vector layer from a view and a field and a value |
75 | 76 |
* and then it zooms to the extent of the features which match the value. |
76 |
*
|
|
77 |
* |
|
77 | 78 |
* @author jldominguez |
78 | 79 |
*/ |
79 | 80 |
public class DataSelectionPanel extends JPanel |
80 | 81 |
implements IWindow, ActionListener { |
81 | 82 |
|
82 | 83 |
private static final long serialVersionUID = 1L; |
83 |
|
|
84 |
|
|
84 | 85 |
private static final Logger logger = |
85 | 86 |
LoggerFactory.getLogger(DataSelectionPanel.class); |
86 |
|
|
87 |
|
|
87 | 88 |
private JComboBox layerComboBox = null; |
88 |
private JLabel jLabel = null;
|
|
89 |
private JLabel jLabel1 = null;
|
|
89 |
private JLabel jLabel = null; |
|
90 |
private JLabel jLabel1 = null; |
|
90 | 91 |
private JComboBox fieldValueComboBox = null; |
91 |
private JLabel jLabel2 = null;
|
|
92 |
private JLabel jLabel2 = null; |
|
92 | 93 |
private JComboBox fieldNameComboBox = null; |
93 | 94 |
private WindowInfo viewInfo = null; |
94 | 95 |
private JButton goButton = null; |
... | ... | |
105 | 106 |
this.mapCtxt = mapContext; |
106 | 107 |
initialize(); |
107 | 108 |
} |
108 |
|
|
109 | 109 |
|
110 |
|
|
110 | 111 |
private void initialize() { |
111 | 112 |
jLabel2 = new JLabel(); |
112 | 113 |
jLabel1 = new JLabel(); |
113 | 114 |
jLabel = new JLabel(); |
114 | 115 |
this.setLayout(new BorderLayout()); |
115 | 116 |
this.setBorder(new EmptyBorder(new Insets(0,5,5,5))); |
116 |
this.setSize(275, 90);
|
|
117 |
this.setSize(275, 90); |
|
117 | 118 |
jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
118 | 119 |
jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
119 | 120 |
jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
... | ... | |
131 | 132 |
c.gridx = 0; |
132 | 133 |
c.gridy = 0; |
133 | 134 |
centerPanelGrid.add(jLabel, c); |
134 |
|
|
135 |
|
|
135 | 136 |
c.gridx = 0; |
136 | 137 |
c.gridy = 1; |
137 | 138 |
centerPanelGrid.add(jLabel1, c); |
138 |
|
|
139 |
|
|
139 | 140 |
c.gridx = 0; |
140 | 141 |
c.gridy = 2; |
141 | 142 |
centerPanelGrid.add(jLabel2, c); |
142 | 143 |
|
143 | 144 |
c.anchor = GridBagConstraints.CENTER; |
144 | 145 |
c.weightx = 1; |
145 |
|
|
146 |
|
|
146 | 147 |
c.gridx = 1; |
147 | 148 |
c.gridy = 0; |
148 | 149 |
centerPanelGrid.add(getLayersComboBox(), c); |
... | ... | |
154 | 155 |
c.gridx = 1; |
155 | 156 |
c.gridy = 2; |
156 | 157 |
centerPanelGrid.add(getValuesComboBox(), c); |
157 |
|
|
158 |
|
|
158 | 159 |
this.add(centerPanelGrid, BorderLayout.CENTER); |
159 |
|
|
160 |
|
|
160 |
|
|
161 |
|
|
161 | 162 |
// Panel Sur |
162 | 163 |
jPanelButtons = new JPanel(); |
163 | 164 |
FlowLayout flowLayor = new FlowLayout(FlowLayout.RIGHT); |
... | ... | |
166 | 167 |
jPanelButtons.add(getCloseButton(), null); |
167 | 168 |
this.add(jPanelButtons, BorderLayout.SOUTH); |
168 | 169 |
} |
169 |
|
|
170 | 170 |
|
171 |
|
|
171 | 172 |
private FeatureAttributeDescriptor[] getFields(FLyrVect vect) { |
172 |
|
|
173 |
|
|
173 | 174 |
FeatureStore featureStore; |
174 | 175 |
try { |
175 | 176 |
featureStore = vect.getFeatureStore(); |
... | ... | |
180 | 181 |
logger.error("While getting field names.", e); |
181 | 182 |
return new FeatureAttributeDescriptor[0]; |
182 | 183 |
} |
183 |
|
|
184 |
|
|
184 | 185 |
} |
185 | 186 |
|
186 | 187 |
|
187 | 188 |
private Object[] getNewValues(FLyrVect vlayer, String fname) { |
188 |
|
|
189 |
|
|
189 | 190 |
FeatureStore featureStore; |
190 | 191 |
if (vlayer == null || fname == null) { |
191 | 192 |
return new Object[0]; |
192 | 193 |
} |
193 |
|
|
194 |
|
|
194 | 195 |
FeatureSet set = null; |
195 | 196 |
|
196 | 197 |
try { |
... | ... | |
213 | 214 |
return 1; |
214 | 215 |
} else if (o1 instanceof String |
215 | 216 |
&& o2 instanceof String) { |
216 |
return ((String) o1).compareTo((String) o2); |
|
217 |
final Collator collator = Collator.getInstance(); |
|
218 |
collator.setStrength(Collator.NO_DECOMPOSITION); |
|
219 |
return collator.compare((String)o1, (String)o2); |
|
220 |
//return ((String) o1).compareTo((String) o2); |
|
217 | 221 |
} else if (o1 instanceof Date && o2 instanceof Date) { |
218 | 222 |
return ((Date) o1).compareTo((Date) o2); |
219 | 223 |
} |
... | ... | |
225 | 229 |
while (diter.hasNext()) { |
226 | 230 |
feat = (Feature) diter.next(); |
227 | 231 |
treeSet.add(feat.get(fname)); |
228 |
if (treeSet.size() > 200) { |
|
229 |
/* |
|
230 |
* Not more than 200 elements |
|
231 |
*/ |
|
232 |
break; |
|
233 |
} |
|
234 | 232 |
} |
235 | 233 |
diter.dispose(); |
236 | 234 |
return treeSet.toArray(); |
... | ... | |
259 | 257 |
private JComboBox getLayersComboBox() { |
260 | 258 |
if (layerComboBox == null) { |
261 | 259 |
layerComboBox = new JComboBox(); |
262 |
|
|
260 |
|
|
263 | 261 |
List<FLyrVect> vs = DataLocatorExtension.getVectorLayers(mapCtxt.getLayers()); |
264 | 262 |
LayersComboItem[] items = new LayersComboItem[vs.size()]; |
265 | 263 |
for (int i=0; i<vs.size(); i++) { |
... | ... | |
274 | 272 |
} |
275 | 273 |
return layerComboBox; |
276 | 274 |
} |
277 |
|
|
275 |
|
|
278 | 276 |
/** |
279 | 277 |
* This method initializes jComboBox1 |
280 | 278 |
* |
... | ... | |
303 | 301 |
} |
304 | 302 |
return fieldValueComboBox; |
305 | 303 |
} |
306 |
|
|
307 |
|
|
308 | 304 |
|
309 | 305 |
|
306 |
|
|
307 |
|
|
310 | 308 |
/** |
311 | 309 |
* This method initializes jButton |
312 | 310 |
* |
... | ... | |
341 | 339 |
public Object getWindowProfile() { |
342 | 340 |
return WindowInfo.DIALOG_PROFILE; |
343 | 341 |
} |
344 |
|
|
342 |
|
|
345 | 343 |
class ValueEvaluator implements Evaluator { |
346 |
|
|
344 |
|
|
347 | 345 |
private String fieldName = null; |
348 | 346 |
private Object value = null; |
349 | 347 |
private EvaluatorFieldsInfo info = null; |
... | ... | |
352 | 350 |
|
353 | 351 |
/** |
354 | 352 |
* Non null |
355 |
*
|
|
353 |
* |
|
356 | 354 |
* @param name |
357 | 355 |
*/ |
358 | 356 |
public ValueEvaluator(String name) { |
... | ... | |
368 | 366 |
* @param val |
369 | 367 |
*/ |
370 | 368 |
public ValueEvaluator(String name, Object val, DataType dtype) { |
371 |
|
|
369 |
|
|
372 | 370 |
fieldName = name; |
373 | 371 |
info = new EvaluatorFieldsInfo(); |
374 | 372 |
info.addFieldValue(name); |
... | ... | |
379 | 377 |
|
380 | 378 |
public Object evaluate(EvaluatorData data) |
381 | 379 |
throws EvaluatorException { |
382 |
|
|
380 |
|
|
383 | 381 |
Object obj = data.getDataValue(fieldName); |
384 | 382 |
if (nonnull) { |
385 | 383 |
/* |
... | ... | |
405 | 403 |
if (value == null) { |
406 | 404 |
resp = fieldName + " is null"; |
407 | 405 |
} else { |
408 |
String quote = dataType.isNumeric() ? "" : "'";
|
|
406 |
String quote = dataType.isNumeric() ? "" : "'"; |
|
409 | 407 |
resp = fieldName + " = " + quote + value.toString() + quote; |
410 | 408 |
} |
411 | 409 |
} |
... | ... | |
427 | 425 |
} |
428 | 426 |
|
429 | 427 |
public void actionPerformed(ActionEvent e) { |
430 |
|
|
428 |
|
|
431 | 429 |
Object src = e.getSource(); |
432 | 430 |
if (src == this.getLayersComboBox()) { |
433 |
|
|
431 |
|
|
434 | 432 |
LayersComboItem litem = |
435 | 433 |
(LayersComboItem) getLayersComboBox().getSelectedItem(); |
436 | 434 |
if (litem != null) { |
... | ... | |
438 | 436 |
if (atts.length > 0) { |
439 | 437 |
getFieldsComboBox().setEnabled(true); |
440 | 438 |
getFieldsComboBox().removeAllItems(); |
441 |
|
|
439 |
|
|
442 | 440 |
for (int i=0; i<atts.length; i++) { |
443 | 441 |
if (atts[i].getType() != DataTypes.GEOMETRY) { |
444 | 442 |
getFieldsComboBox().addItem(new FieldsComboItem(atts[i])); |
... | ... | |
458 | 456 |
getValuesComboBox().setEnabled(false); |
459 | 457 |
return; |
460 | 458 |
} |
461 |
|
|
459 |
|
|
462 | 460 |
// ========================================================== |
463 | 461 |
// ========================================================== |
464 |
|
|
462 |
|
|
465 | 463 |
if (src == this.getFieldsComboBox()) { |
466 |
|
|
464 |
|
|
467 | 465 |
LayersComboItem litem = |
468 | 466 |
(LayersComboItem) getLayersComboBox().getSelectedItem(); |
469 | 467 |
FieldsComboItem fatt = |
470 | 468 |
(FieldsComboItem) getFieldsComboBox().getSelectedItem(); |
471 | 469 |
if (litem != null && fatt != null) { |
472 |
|
|
470 |
|
|
473 | 471 |
Object[] vals = this.getNewValues(litem.getLayer(), fatt.toString()); |
474 | 472 |
if (vals.length > 0) { |
475 |
|
|
473 |
|
|
476 | 474 |
this.getValuesComboBox().setEnabled(true); |
477 | 475 |
this.getValuesComboBox().removeAllItems(); |
478 | 476 |
DefaultComboBoxModel model = new DefaultComboBoxModel(vals); |
... | ... | |
497 | 495 |
// ========================================================== |
498 | 496 |
|
499 | 497 |
if (src == this.getValuesComboBox()) { |
500 |
|
|
498 |
|
|
501 | 499 |
return; |
502 | 500 |
} |
503 | 501 |
|
... | ... | |
540 | 538 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor(); |
541 | 539 |
featureSet.accept(visitor); |
542 | 540 |
Envelope env_data = visitor.getSelectBound(); |
543 |
|
|
541 |
|
|
544 | 542 |
if (env_data != null) { |
545 | 543 |
if (lyr.getCoordTrans() != null) { |
546 | 544 |
env_data = env_data.convert(lyr.getCoordTrans()); |
547 | 545 |
} |
548 |
this.mapCtxt.getViewPort().setEnvelope(env_data);
|
|
546 |
this.mapCtxt.getViewPort().setEnvelope(env_data); |
|
549 | 547 |
} |
550 | 548 |
// ======================================= |
551 | 549 |
|
... | ... | |
554 | 552 |
} |
555 | 553 |
return; |
556 | 554 |
} |
557 |
|
|
555 |
|
|
558 | 556 |
} |
559 | 557 |
|
560 | 558 |
|
Also available in: Unified diff