svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extDataLocator / src / com / iver / gvsig / datalocator / gui / DataSelectionPanel.java @ 28916
History | View | Annotate | Download (27.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 22-jun-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.gvsig.datalocator.gui; |
45 |
|
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.event.ItemListener; |
48 |
import java.util.Comparator; |
49 |
import java.util.Date; |
50 |
import java.util.Iterator; |
51 |
import java.util.TreeSet; |
52 |
import java.util.Vector; |
53 |
import java.util.prefs.Preferences; |
54 |
|
55 |
import javax.swing.DefaultComboBoxModel; |
56 |
import javax.swing.JCheckBox; |
57 |
import javax.swing.JComboBox; |
58 |
import javax.swing.JDialog; |
59 |
import javax.swing.JLabel; |
60 |
import javax.swing.JPanel; |
61 |
|
62 |
import org.gvsig.fmap.dal.exception.DataException; |
63 |
import org.gvsig.fmap.dal.feature.Feature; |
64 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
65 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
66 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
67 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
69 |
import org.gvsig.fmap.mapcontext.MapContext; |
70 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
73 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
74 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
75 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
76 |
import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
77 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
78 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
79 |
import org.gvsig.fmap.mapcontext.rendering.strategies.SelectedZoomVisitor; |
80 |
import org.gvsig.gui.beans.swing.JButton; |
81 |
import org.gvsig.tools.evaluator.Evaluator; |
82 |
import org.gvsig.tools.evaluator.EvaluatorData; |
83 |
import org.gvsig.tools.evaluator.EvaluatorException; |
84 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
85 |
import org.gvsig.tools.exception.BaseException; |
86 |
|
87 |
import com.iver.andami.PluginServices; |
88 |
import com.iver.andami.ui.mdiManager.IWindow; |
89 |
import com.iver.andami.ui.mdiManager.IWindowListener; |
90 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
91 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
92 |
import com.iver.gvsig.datalocator.DataLocatorExtension; |
93 |
|
94 |
/**
|
95 |
* @author jmorell
|
96 |
*/
|
97 |
public class DataSelectionPanel extends JPanel implements IWindow, IWindowListener, SingletonWindow { |
98 |
|
99 |
private static final long serialVersionUID = 1L; |
100 |
private JComboBox jComboBox = null; |
101 |
private JLabel jLabel = null; // @jve:decl-index=0:visual-constraint="597,16" |
102 |
private JLabel jLabel1 = null; // @jve:decl-index=0:visual-constraint="873,44" |
103 |
private JComboBox jComboBox1 = null; |
104 |
private JLabel jLabel2 = null; // @jve:decl-index=0:visual-constraint="847,16" |
105 |
private JComboBox jComboBox2 = null; |
106 |
private WindowInfo viewInfo = null; |
107 |
private JButton jButton = null; |
108 |
private JButton jButton1 = null; |
109 |
private FLayer layerToZoom = null; |
110 |
private int fieldToZoomIndex = 0; |
111 |
private Object itemToZoom = null; |
112 |
private MapContext mapContext = null; |
113 |
private Preferences prefUsuario = null; |
114 |
private Vector<LayersListener> layersListenerList = new Vector<LayersListener>(); |
115 |
private Vector<FLayer> vectorialLayers = null; |
116 |
private JCheckBox jChkBoxOpenFirstTime = null; |
117 |
private JPanel jPanelButtons = null; |
118 |
|
119 |
/**
|
120 |
* This method initializes
|
121 |
*
|
122 |
*/
|
123 |
public DataSelectionPanel(MapContext mapContext) {
|
124 |
super();
|
125 |
this.mapContext = mapContext;
|
126 |
prefUsuario = Preferences.userRoot();
|
127 |
initializeVectorialLayers(); |
128 |
initializeLayerToZoom(); |
129 |
initializeFieldToZoomIndex(); |
130 |
initialize(); |
131 |
|
132 |
int userOpen = prefUsuario.getInt("gvSIG.DataLocator.open_first_time", -1); |
133 |
if (userOpen == 1) |
134 |
getJChkBoxOpenFirstTime().setSelected(true);
|
135 |
} |
136 |
private void initializeVectorialLayers() { |
137 |
unregisterLayersListener(); |
138 |
vectorialLayers = new Vector<FLayer>(); |
139 |
LayersIterator iter = DataLocatorExtension.newValidLayersIterator(mapContext.getLayers()); |
140 |
|
141 |
|
142 |
while (iter.hasNext()) {
|
143 |
vectorialLayers.add(iter.nextLayer()); |
144 |
} |
145 |
|
146 |
registerLayersListener(); |
147 |
} |
148 |
private void initializeLayerToZoom() { |
149 |
String layerName = prefUsuario.get("LAYERNAME_FOR_DATA_LOCATION", ""); |
150 |
if (layerName.equals("")) layerToZoom = (FLayer)vectorialLayers.get(0); |
151 |
boolean layerFound = false; |
152 |
for (int i=0;i<vectorialLayers.size();i++) { |
153 |
if (((FLayer)vectorialLayers.get(i)).getName().equals(layerName)) {
|
154 |
layerFound = true;
|
155 |
layerToZoom = (FLayer)vectorialLayers.get(i); |
156 |
break;
|
157 |
} |
158 |
} |
159 |
if (!layerFound) layerToZoom = (FLayer)vectorialLayers.get(0); |
160 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", layerToZoom.getName());
|
161 |
|
162 |
} |
163 |
private void initializeFieldToZoomIndex() { |
164 |
fieldToZoomIndex = prefUsuario.getInt("FIELDINDEX_FOR_DATA_LOCATION", 0); |
165 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
166 |
FeatureStore featureStore; |
167 |
try {
|
168 |
featureStore = lyr.getFeatureStore(); |
169 |
if (fieldToZoomIndex > (featureStore.getDefaultFeatureType().size()-1)) { |
170 |
fieldToZoomIndex = 0;
|
171 |
} else if (featureStore.getDefaultFeatureType().size() == 0) { |
172 |
fieldToZoomIndex = -1;
|
173 |
} |
174 |
} catch (DataException e) {
|
175 |
fieldToZoomIndex = -1;
|
176 |
e.printStackTrace(); |
177 |
} |
178 |
} |
179 |
/**
|
180 |
* This method initializes this
|
181 |
*
|
182 |
* @return void
|
183 |
*/
|
184 |
private void initialize() { |
185 |
jLabel2 = new JLabel(); |
186 |
jLabel1 = new JLabel(); |
187 |
jLabel = new JLabel(); |
188 |
this.setLayout(null); |
189 |
this.setSize(350, 161); |
190 |
jLabel.setBounds(6, 6, 80, 23); |
191 |
jLabel.setText(PluginServices.getText(this,"Capa") + ":"); |
192 |
jLabel1.setBounds(6, 34, 80, 23); |
193 |
jLabel1.setText(PluginServices.getText(this,"Campo") + ":"); |
194 |
jLabel2.setBounds(6, 61, 80, 23); |
195 |
jLabel2.setText(PluginServices.getText(this,"Valor") + ":"); |
196 |
this.add(getJComboBox(), null); |
197 |
this.add(jLabel, null); |
198 |
this.add(jLabel1, null); |
199 |
this.add(getJComboBox1(), null); |
200 |
this.add(jLabel2, null); |
201 |
this.add(getJComboBox2(), null); |
202 |
|
203 |
jPanelButtons = new JPanel(); |
204 |
FlowLayout flowLayor = new FlowLayout(FlowLayout.RIGHT); |
205 |
flowLayor.setHgap(5);
|
206 |
|
207 |
jPanelButtons.setLayout(flowLayor); |
208 |
jPanelButtons.setBounds(15,121,335,35); |
209 |
jPanelButtons.add(getJButton(), null);
|
210 |
jPanelButtons.add(getJButton1(), null);
|
211 |
|
212 |
this.add(jPanelButtons);
|
213 |
|
214 |
this.add(getJChkBoxOpenFirstTime(), null); |
215 |
|
216 |
|
217 |
} |
218 |
private void registerLayersListener() { |
219 |
int i,j;
|
220 |
FLayer layer; |
221 |
LayersListener listener; |
222 |
boolean found;
|
223 |
for (i=0;i< vectorialLayers.size();i++) { |
224 |
found = false;
|
225 |
layer = ((FLayer)vectorialLayers.get(i)); |
226 |
for (j=0;j < layersListenerList.size(); j++) { |
227 |
listener = (LayersListener)layersListenerList.get(j); |
228 |
if ( layer.getParentLayer() == listener.getLayerCollection()) {
|
229 |
found = true;
|
230 |
break;
|
231 |
} |
232 |
} |
233 |
if (!found) {
|
234 |
listener = new LayersListener(layer.getParentLayer());
|
235 |
layer.getParentLayer().addLayerCollectionListener(listener); |
236 |
layersListenerList.add(listener); |
237 |
} |
238 |
|
239 |
} |
240 |
} |
241 |
|
242 |
|
243 |
private void unregisterLayersListener() { |
244 |
int i;
|
245 |
LayersListener listener; |
246 |
for (i=0;i<layersListenerList.size();i++) { |
247 |
listener = (LayersListener)layersListenerList.get(i); |
248 |
listener.getLayerCollection().removeLayerCollectionListener(listener); |
249 |
} |
250 |
} |
251 |
|
252 |
private String[] getLayerNames() { |
253 |
String[] layerNames = new String[vectorialLayers.size()]; |
254 |
for (int i=0;i<vectorialLayers.size();i++) { |
255 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
256 |
} |
257 |
return layerNames;
|
258 |
} |
259 |
private String[] getFieldNames() { |
260 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
261 |
FeatureStore featureStore; |
262 |
String[] fieldNames = null; |
263 |
try {
|
264 |
featureStore = lyr.getFeatureStore(); |
265 |
fieldNames = new String[featureStore.getDefaultFeatureType().size()]; |
266 |
for (int i = 0; i < featureStore.getDefaultFeatureType().size(); i++) { |
267 |
fieldNames[i] = ((FeatureAttributeDescriptor)featureStore.getDefaultFeatureType().get(i)).getName(); |
268 |
} |
269 |
} catch (DataException e) {
|
270 |
e.printStackTrace(); |
271 |
} |
272 |
return fieldNames;
|
273 |
} |
274 |
|
275 |
|
276 |
private Object[] getNewValues() { |
277 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
278 |
FeatureStore featureStore; |
279 |
Object[] newValues = null; |
280 |
if (fieldToZoomIndex < 0) |
281 |
return null; |
282 |
try {
|
283 |
featureStore = lyr.getFeatureStore(); |
284 |
|
285 |
// String sql = "select " + ((FeatureAttributeDescriptor)featureStore.getDefaultFeatureType().get(fieldToZoomIndex)).getName() + " from " + featureStore.getName() + " where " + featureStore.getFieldName(fieldToZoomIndex) + " is not null;";
|
286 |
FeatureQuery query=featureStore.createFeatureQuery(); |
287 |
String field=((FeatureAttributeDescriptor)featureStore.getDefaultFeatureType().get(fieldToZoomIndex)).getName();
|
288 |
Evaluator myEvaluator=new MyEvaluator(field);
|
289 |
query.setFilter(myEvaluator); |
290 |
query.setAttributeNames(new String[]{field}); |
291 |
FeatureSet set = featureStore.getFeatureSet(query); |
292 |
// ds = ds.getDataSourceFactory().executeSQL(sql, DataSourceFactory.AUTOMATIC_OPENING);
|
293 |
|
294 |
//Quitar los nombres repetidos y ordenarlos
|
295 |
TreeSet<Object> treeSet = new TreeSet<Object>(new Comparator<Object>() { |
296 |
public int compare(Object o1, Object o2) { |
297 |
if (o1 instanceof Number && o2 instanceof Number){ |
298 |
if (((Number)o1).doubleValue()<((Number)o2).doubleValue()) |
299 |
return -1; |
300 |
if (((Number)o1).doubleValue()>((Number)o2).doubleValue()) |
301 |
return 1; |
302 |
}else if (o1 instanceof String && o2 instanceof String){ |
303 |
return ((String)o1).compareTo((String)o2); |
304 |
}else if (o1 instanceof Date && o2 instanceof Date){ |
305 |
return ((Date)o1).compareTo((Date)o2); |
306 |
} |
307 |
return 0; |
308 |
} |
309 |
}); |
310 |
Iterator<Feature> features=set.iterator();
|
311 |
while (features.hasNext()) {
|
312 |
Feature feature = (Feature) features.next(); |
313 |
Object obj=feature.get(0); |
314 |
treeSet.add(obj); |
315 |
} |
316 |
newValues = (Object[])treeSet.toArray(new Object[0]); |
317 |
} catch (DataException e) {
|
318 |
e.printStackTrace(); |
319 |
} |
320 |
return newValues;
|
321 |
} |
322 |
private class LayersListener implements LayerCollectionListener { |
323 |
private LayerCollection theLayerCollection;
|
324 |
public LayersListener(FLayers layers){
|
325 |
theLayerCollection = layers; |
326 |
} |
327 |
|
328 |
public LayerCollection getLayerCollection() {
|
329 |
return theLayerCollection;
|
330 |
} |
331 |
/* (non-Javadoc)
|
332 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
333 |
*/
|
334 |
public void layerAdded(LayerCollectionEvent e) { |
335 |
initializeVectorialLayers(); |
336 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
337 |
jComboBox.removeAllItems(); |
338 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
339 |
jComboBox.setModel(defaultModel); |
340 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
341 |
} |
342 |
/* (non-Javadoc)
|
343 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
344 |
*/
|
345 |
public void layerRemoved(LayerCollectionEvent e) { |
346 |
initializeVectorialLayers(); |
347 |
((ChangeLayerToZoomItemListener)jComboBox.getItemListeners()[0]).setLayers(vectorialLayers);
|
348 |
if (vectorialLayers.size()>0) { |
349 |
jComboBox.removeAllItems(); |
350 |
String[] layerNames = new String[vectorialLayers.size()]; |
351 |
boolean currentLayerRemoved = true; |
352 |
for (int i=0;i<vectorialLayers.size();i++) { |
353 |
layerNames[i] = ((FLayer)vectorialLayers.get(i)).getName(); |
354 |
if (layerToZoom.getName().equals(layerNames[i])) currentLayerRemoved = false; |
355 |
} |
356 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(layerNames); |
357 |
jComboBox.setModel(defaultModel); |
358 |
if (currentLayerRemoved) {
|
359 |
layerToZoom = ((FLayer)vectorialLayers.get(0));
|
360 |
defaultModel = new DefaultComboBoxModel(getFieldNames()); |
361 |
jComboBox1.setModel(defaultModel); |
362 |
fieldToZoomIndex = 0;
|
363 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
364 |
Object[] values =getNewValues(); |
365 |
defaultModel = new DefaultComboBoxModel(values); |
366 |
jComboBox2.setModel(defaultModel); |
367 |
if (values != null) { |
368 |
itemToZoom = getNewValues()[0];
|
369 |
jComboBox2.setSelectedItem(itemToZoom); |
370 |
}else {
|
371 |
itemToZoom = null;
|
372 |
} |
373 |
|
374 |
} |
375 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
376 |
}else {
|
377 |
if (PluginServices.getMainFrame() == null) |
378 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
379 |
else
|
380 |
PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this); |
381 |
} |
382 |
} |
383 |
/* (non-Javadoc)
|
384 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
385 |
*/
|
386 |
public void layerMoved(LayerPositionEvent e) { |
387 |
// TODO Auto-generated method stub
|
388 |
|
389 |
} |
390 |
/* (non-Javadoc)
|
391 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
392 |
*/
|
393 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
394 |
// TODO Auto-generated method stub
|
395 |
|
396 |
} |
397 |
/* (non-Javadoc)
|
398 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
399 |
*/
|
400 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
401 |
// TODO Auto-generated method stub
|
402 |
|
403 |
} |
404 |
/* (non-Javadoc)
|
405 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
406 |
*/
|
407 |
public void layerRemoving(LayerCollectionEvent e) throws CancelationException { |
408 |
// TODO Auto-generated method stub
|
409 |
|
410 |
} |
411 |
/* (non-Javadoc)
|
412 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
413 |
*/
|
414 |
public void activationChanged(LayerCollectionEvent e) throws CancelationException { |
415 |
// TODO Auto-generated method stub
|
416 |
|
417 |
} |
418 |
/* (non-Javadoc)
|
419 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
420 |
*/
|
421 |
public void visibilityChanged(LayerCollectionEvent e) throws CancelationException { |
422 |
// TODO Auto-generated method stub
|
423 |
|
424 |
} |
425 |
} |
426 |
/* (non-Javadoc)
|
427 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
428 |
*/
|
429 |
public WindowInfo getWindowInfo() {
|
430 |
if (viewInfo == null) { |
431 |
viewInfo=new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE);
|
432 |
viewInfo.setTitle(PluginServices.getText(this,"Localizador_por_atributo")); |
433 |
viewInfo.setHeight(getPreferredSize().height); |
434 |
viewInfo.setWidth(getPreferredSize().width); |
435 |
} |
436 |
return viewInfo;
|
437 |
} |
438 |
/**
|
439 |
* This method initializes jComboBox
|
440 |
*
|
441 |
* @return javax.swing.JComboBox
|
442 |
*/
|
443 |
private JComboBox getJComboBox() { |
444 |
if (jComboBox == null) { |
445 |
jComboBox = new JComboBox(); |
446 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getLayerNames()); |
447 |
jComboBox.setModel(defaultModel); |
448 |
jComboBox.setBounds(90, 6, 250, 23); |
449 |
jComboBox.setSelectedItem(layerToZoom.getName()); |
450 |
ChangeLayerToZoomItemListener changeLayerToZoomItemListener = new ChangeLayerToZoomItemListener(vectorialLayers);
|
451 |
jComboBox.addItemListener(changeLayerToZoomItemListener); |
452 |
} |
453 |
return jComboBox;
|
454 |
} |
455 |
private class ChangeLayerToZoomItemListener implements ItemListener { |
456 |
private Vector<FLayer> layers; |
457 |
public ChangeLayerToZoomItemListener(Vector<FLayer> layers) { |
458 |
this.layers = layers;
|
459 |
} |
460 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
461 |
if (jComboBox.getItemCount()>0) { |
462 |
for (int i=0;i<layers.size();i++) { |
463 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
464 |
layerToZoom = (FLayer)layers.get(i); |
465 |
break;
|
466 |
} |
467 |
} |
468 |
fieldToZoomIndex = 0;
|
469 |
prefUsuario.put("LAYERNAME_FOR_DATA_LOCATION", (String)jComboBox.getSelectedItem()); |
470 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
471 |
jComboBox1.setModel(defaultModel); |
472 |
Object[] values =getNewValues(); |
473 |
defaultModel = new DefaultComboBoxModel(values); |
474 |
jComboBox2.setModel(defaultModel); |
475 |
if ( values != null) { |
476 |
jComboBox2.setSelectedIndex(0);
|
477 |
itemToZoom = values[0];
|
478 |
} else {
|
479 |
itemToZoom = null;
|
480 |
} |
481 |
} |
482 |
} |
483 |
/**
|
484 |
* @param layers The layers to set.
|
485 |
*/
|
486 |
public void setLayers(Vector<FLayer> layers) { |
487 |
this.layers = layers;
|
488 |
} |
489 |
} |
490 |
/**
|
491 |
* This method initializes jComboBox1
|
492 |
*
|
493 |
* @return javax.swing.JComboBox
|
494 |
*/
|
495 |
private JComboBox getJComboBox1() { |
496 |
if (jComboBox1 == null) { |
497 |
jComboBox1 = new JComboBox(); |
498 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getFieldNames()); |
499 |
jComboBox1.setModel(defaultModel); |
500 |
jComboBox1.setBounds(90, 34, 250, 23); |
501 |
jComboBox1.setSelectedIndex(fieldToZoomIndex); |
502 |
ChangeFieldItemListener changeFieldItemListener = new ChangeFieldItemListener(vectorialLayers);
|
503 |
jComboBox1.addItemListener(changeFieldItemListener); |
504 |
} |
505 |
return jComboBox1;
|
506 |
} |
507 |
private class ChangeFieldItemListener implements ItemListener { |
508 |
public ChangeFieldItemListener(Vector<FLayer> layers) { |
509 |
} |
510 |
public void itemStateChanged(java.awt.event.ItemEvent itemEvent) { |
511 |
String fieldToZoom = ((String)jComboBox1.getSelectedItem()); |
512 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
513 |
FeatureStore featureStore; |
514 |
try {
|
515 |
featureStore = lyr.getFeatureStore(); |
516 |
fieldToZoomIndex = featureStore.getDefaultFeatureType().getIndex(fieldToZoom); |
517 |
prefUsuario.putInt("FIELDINDEX_FOR_DATA_LOCATION", fieldToZoomIndex);
|
518 |
|
519 |
//Quitar los nombres repetidos y ordenarlos
|
520 |
TreeSet<Object> treeSet = new TreeSet<Object>(new Comparator<Object>() { |
521 |
public int compare(Object o1, Object o2) { |
522 |
if (o1 instanceof Number && o2 instanceof Number){ |
523 |
if (((Number)o1).doubleValue()<((Number)o2).doubleValue()) |
524 |
return -1; |
525 |
if (((Number)o1).doubleValue()>((Number)o2).doubleValue()) |
526 |
return 1; |
527 |
}else if (o1 instanceof String && o2 instanceof String){ |
528 |
return ((String)o1).compareTo((String)o2); |
529 |
}else if (o1 instanceof Date && o2 instanceof Date){ |
530 |
return ((Date)o1).compareTo((Date)o2); |
531 |
} |
532 |
return 0; |
533 |
} |
534 |
}); |
535 |
|
536 |
Evaluator myEvaluator=new MyEvaluator(fieldToZoom);
|
537 |
FeatureQuery query=featureStore.createFeatureQuery(); |
538 |
query.setFilter(myEvaluator); |
539 |
FeatureSet set=featureStore.getFeatureSet(query); |
540 |
Iterator<Feature> features=set.iterator();
|
541 |
while (features.hasNext()) {
|
542 |
Feature feature = (Feature) features.next(); |
543 |
treeSet.add(feature.get(fieldToZoomIndex)); |
544 |
} |
545 |
Object[] newValues = (Object[])treeSet.toArray(new Object[0]); |
546 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(newValues); |
547 |
jComboBox2.setModel(defaultModel); |
548 |
if (newValues.length>0) jComboBox2.setSelectedIndex(0); |
549 |
if (newValues.length>0) { |
550 |
itemToZoom = newValues[0];
|
551 |
} else {
|
552 |
itemToZoom = null;
|
553 |
} |
554 |
} catch (DataException e) {
|
555 |
e.printStackTrace(); |
556 |
} |
557 |
} |
558 |
} |
559 |
/**
|
560 |
* This method initializes jComboBox2
|
561 |
*
|
562 |
* @return javax.swing.JComboBox
|
563 |
*/
|
564 |
private JComboBox getJComboBox2() { |
565 |
if (jComboBox2 == null) { |
566 |
jComboBox2 = new JComboBox(); |
567 |
DefaultComboBoxModel defaultModel = new DefaultComboBoxModel(getNewValues()); |
568 |
jComboBox2.setModel(defaultModel); |
569 |
jComboBox2.setSelectedIndex(-1);
|
570 |
jComboBox2.setBounds(90, 61, 250, 23); |
571 |
ChangeItemToZoomItemListener changeItemToZoomItemListener = new ChangeItemToZoomItemListener(vectorialLayers);
|
572 |
jComboBox2.addItemListener(changeItemToZoomItemListener); |
573 |
} |
574 |
return jComboBox2;
|
575 |
} |
576 |
private class ChangeItemToZoomItemListener implements ItemListener { |
577 |
private Vector<FLayer> layers; |
578 |
public ChangeItemToZoomItemListener(Vector<FLayer> layers) { |
579 |
this.layers = layers;
|
580 |
} |
581 |
public void itemStateChanged(java.awt.event.ItemEvent e) { |
582 |
for (int i=0;i<layers.size();i++) { |
583 |
if (((FLayer)layers.get(i)).getName().equals((String)jComboBox.getSelectedItem())) { |
584 |
layerToZoom = (FLayer)layers.get(i); |
585 |
break;
|
586 |
} |
587 |
} |
588 |
itemToZoom = ((Object)jComboBox2.getSelectedItem());
|
589 |
} |
590 |
} |
591 |
/**
|
592 |
* This method initializes jButton
|
593 |
*
|
594 |
* @return javax.swing.JButton
|
595 |
*/
|
596 |
private JButton getJButton() { |
597 |
if (jButton == null) { |
598 |
jButton = new JButton(); |
599 |
//jButton.setBounds(8, 121, 128, 23);
|
600 |
jButton.setText(PluginServices.getText(this,"Zoom")); |
601 |
jButton.addActionListener(new java.awt.event.ActionListener() {
|
602 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
603 |
if (layerToZoom == null || fieldToZoomIndex < 0 || itemToZoom == null) |
604 |
return;
|
605 |
if (jComboBox2.getSelectedIndex()!=-1) { |
606 |
FLyrVect lyr = (FLyrVect)layerToZoom; |
607 |
FeatureStore featureStore; |
608 |
try {
|
609 |
featureStore = lyr.getFeatureStore(); |
610 |
FeatureSelection selection = (FeatureSelection)featureStore.createFeatureSelection(); |
611 |
Iterator<Feature> features = featureStore.getFeatureSet().iterator();
|
612 |
while (features.hasNext()) {
|
613 |
Feature feature = (Feature) features.next(); |
614 |
if (itemToZoom.equals(feature.get(fieldToZoomIndex))){
|
615 |
selection.select(feature); |
616 |
} |
617 |
} |
618 |
// featureStore.setSelection(selection);
|
619 |
SelectedZoomVisitor visitor = new SelectedZoomVisitor();
|
620 |
selection.accept(visitor); |
621 |
mapContext.getViewPort().setEnvelope(visitor.getSelectBound()); |
622 |
|
623 |
} catch (DataException e1) {
|
624 |
e1.printStackTrace(); |
625 |
} catch (BaseException e1) {
|
626 |
e1.printStackTrace(); |
627 |
} |
628 |
} else if (itemToZoom == null) { |
629 |
System.out.println("Localizador por atributo: El campo valor debe tener elementos no nulos para hacer el Zoom."); |
630 |
} else {
|
631 |
System.out.println("Localizador por atributo: El campo valor debe estar inicializado antes de hacer Zoom."); |
632 |
} |
633 |
} |
634 |
}); |
635 |
} |
636 |
return jButton;
|
637 |
} |
638 |
/**
|
639 |
* This method initializes jButton1
|
640 |
*
|
641 |
* @return javax.swing.JButton
|
642 |
*/
|
643 |
private JButton getJButton1() { |
644 |
if (jButton1 == null) { |
645 |
jButton1 = new JButton(); |
646 |
//jButton1.setBounds(141, 121, 128, 23);
|
647 |
jButton1.setText(PluginServices.getText(this,"Salir")); |
648 |
jButton1.addActionListener(new java.awt.event.ActionListener() {
|
649 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
650 |
if (PluginServices.getMainFrame() == null) |
651 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
652 |
else
|
653 |
PluginServices.getMDIManager().closeWindow(DataSelectionPanel.this); |
654 |
} |
655 |
}); |
656 |
} |
657 |
return jButton1;
|
658 |
} |
659 |
/* (non-Javadoc)
|
660 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
661 |
*/
|
662 |
public void windowActivated() { |
663 |
// TODO Auto-generated method stub
|
664 |
|
665 |
} |
666 |
/* (non-Javadoc)
|
667 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
668 |
*/
|
669 |
public void windowClosed() { |
670 |
unregisterLayersListener(); |
671 |
// Guardamos la posici?n en las preferencias del usuario.
|
672 |
WindowInfo vi = PluginServices.getMDIManager().getWindowInfo(this);
|
673 |
prefUsuario.putInt("gvSIG.DataLocator.x", vi.getX());
|
674 |
prefUsuario.putInt("gvSIG.DataLocator.y", vi.getY());
|
675 |
prefUsuario.putInt("gvSIG.DataLocator.w", vi.getWidth());
|
676 |
prefUsuario.putInt("gvSIG.DataLocator.h", vi.getHeight());
|
677 |
vi.setClosed(true);
|
678 |
} |
679 |
/* (non-Javadoc)
|
680 |
* @see com.iver.andami.ui.mdiManager.SingletonView#getViewModel()
|
681 |
*/
|
682 |
public Object getWindowModel() { |
683 |
// Debe devolver una cadena. Mirar Console del CorePlugin
|
684 |
return "DataSelectionPanel"; |
685 |
} |
686 |
/**
|
687 |
* This method initializes jChkBoxOpenFirstTime
|
688 |
*
|
689 |
* @return javax.swing.JCheckBox
|
690 |
*/
|
691 |
private JCheckBox getJChkBoxOpenFirstTime() { |
692 |
if (jChkBoxOpenFirstTime == null) { |
693 |
jChkBoxOpenFirstTime = new JCheckBox(); |
694 |
jChkBoxOpenFirstTime.setBounds(new java.awt.Rectangle(90,89,179,23)); |
695 |
jChkBoxOpenFirstTime.setText(PluginServices.getText(this, "open_first_time")); |
696 |
jChkBoxOpenFirstTime.addActionListener(new java.awt.event.ActionListener() {
|
697 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
698 |
System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() |
699 |
if (jChkBoxOpenFirstTime.isSelected())
|
700 |
{ |
701 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",1); |
702 |
} |
703 |
else
|
704 |
{ |
705 |
prefUsuario.putInt("gvSIG.DataLocator.open_first_time",0); |
706 |
} |
707 |
} |
708 |
}); |
709 |
} |
710 |
return jChkBoxOpenFirstTime;
|
711 |
} |
712 |
public Object getWindowProfile() { |
713 |
return WindowInfo.TOOL_PROFILE;
|
714 |
} |
715 |
class MyEvaluator implements Evaluator{ |
716 |
private String name=null; |
717 |
private EvaluatorFieldsInfo info = null; |
718 |
|
719 |
public MyEvaluator(String name){ |
720 |
this.name=name;
|
721 |
info = new EvaluatorFieldsInfo();
|
722 |
this.info.addFieldValue(name);
|
723 |
} |
724 |
|
725 |
public Object evaluate(EvaluatorData data) |
726 |
throws EvaluatorException {
|
727 |
Feature feature = (Feature) data.getContextValue("feature");
|
728 |
if (feature.get(name)!=null) |
729 |
return new Boolean(true); |
730 |
return new Boolean(false); |
731 |
} |
732 |
|
733 |
public String getCQL() { |
734 |
return name + " is not null;"; |
735 |
} |
736 |
|
737 |
public String getDescription() { |
738 |
return "Evaluates if a field is not null"; |
739 |
} |
740 |
|
741 |
public EvaluatorFieldsInfo getFieldsInfo() {
|
742 |
return this.info; |
743 |
} |
744 |
|
745 |
public String getName() { |
746 |
return this.getClass().getName(); |
747 |
} |
748 |
|
749 |
} |
750 |
} // @jve:decl-index=0:visual-constraint="10,10"
|