svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extWFS2 / src / org / gvsig / wfs / gui / panels / WFSSelectFeaturePanel.java @ 36042
History | View | Annotate | Download (36.4 KB)
1 | 29645 | jpiera | package org.gvsig.wfs.gui.panels; |
---|---|---|---|
2 | 27885 | jpiera | |
3 | import java.awt.Color; |
||
4 | import java.awt.Component; |
||
5 | import java.awt.Graphics; |
||
6 | import java.awt.Point; |
||
7 | import java.awt.Rectangle; |
||
8 | import java.awt.event.MouseAdapter; |
||
9 | import java.awt.event.MouseEvent; |
||
10 | import java.text.Collator; |
||
11 | import java.util.Collections; |
||
12 | import java.util.Locale; |
||
13 | import java.util.Vector; |
||
14 | |||
15 | import javax.swing.DefaultListSelectionModel; |
||
16 | import javax.swing.JCheckBox; |
||
17 | import javax.swing.JComponent; |
||
18 | import javax.swing.JLabel; |
||
19 | import javax.swing.JPanel; |
||
20 | import javax.swing.JScrollPane; |
||
21 | import javax.swing.JTable; |
||
22 | import javax.swing.JTextField; |
||
23 | import javax.swing.ListSelectionModel; |
||
24 | import javax.swing.UIManager; |
||
25 | import javax.swing.event.DocumentEvent; |
||
26 | import javax.swing.event.DocumentListener; |
||
27 | import javax.swing.event.ListSelectionListener; |
||
28 | import javax.swing.plaf.basic.BasicTableHeaderUI; |
||
29 | import javax.swing.table.AbstractTableModel; |
||
30 | import javax.swing.table.DefaultTableCellRenderer; |
||
31 | import javax.swing.table.TableCellRenderer; |
||
32 | import javax.swing.table.TableColumn; |
||
33 | import javax.swing.table.TableColumnModel; |
||
34 | import javax.swing.table.TableModel; |
||
35 | |||
36 | 29645 | jpiera | import org.gvsig.andami.PluginServices; |
37 | import org.gvsig.andami.messages.NotificationManager; |
||
38 | 27885 | jpiera | import org.gvsig.gui.beans.panelGroup.IPanelGroup; |
39 | 34026 | jpiera | import org.gvsig.remoteclient.wfs.WFSFeatureField; |
40 | 29645 | jpiera | import org.gvsig.utils.StringComparator; |
41 | import org.gvsig.wfs.gui.panels.WFSSelectFeaturePanel.LayerTable.LayerTableModel; |
||
42 | import org.gvsig.wfs.gui.panels.model.WFSSelectedFeature; |
||
43 | 27885 | jpiera | |
44 | |||
45 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
46 | *
|
||
47 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
48 | *
|
||
49 | * This program is free software; you can redistribute it and/or
|
||
50 | * modify it under the terms of the GNU General Public License
|
||
51 | * as published by the Free Software Foundation; either version 2
|
||
52 | * of the License, or (at your option) any later version.
|
||
53 | *
|
||
54 | * This program is distributed in the hope that it will be useful,
|
||
55 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
56 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
57 | * GNU General Public License for more details.
|
||
58 | *
|
||
59 | * You should have received a copy of the GNU General Public License
|
||
60 | * along with this program; if not, write to the Free Software
|
||
61 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
62 | *
|
||
63 | * For more information, contact:
|
||
64 | *
|
||
65 | * Generalitat Valenciana
|
||
66 | * Conselleria d'Infraestructures i Transport
|
||
67 | * Av. Blasco Ib??ez, 50
|
||
68 | * 46010 VALENCIA
|
||
69 | * SPAIN
|
||
70 | *
|
||
71 | * +34 963862235
|
||
72 | * gvsig@gva.es
|
||
73 | * www.gvsig.gva.es
|
||
74 | *
|
||
75 | * or
|
||
76 | *
|
||
77 | * IVER T.I. S.A
|
||
78 | * Salamanca 50
|
||
79 | * 46005 Valencia
|
||
80 | * Spain
|
||
81 | *
|
||
82 | * +34 963163400
|
||
83 | * dac@iver.es
|
||
84 | */
|
||
85 | /* CVS MESSAGES:
|
||
86 | *
|
||
87 | * $Id: WFSSelectFeaturePanel.java 18799 2008-02-12 16:53:03Z vcaballero $
|
||
88 | * $Log$
|
||
89 | * Revision 1.19 2007-09-19 16:14:50 jaume
|
||
90 | * removed unnecessary imports
|
||
91 | *
|
||
92 | * Revision 1.18 2007/03/15 13:34:16 ppiqueras
|
||
93 | * Eliminado mensaje de aviso no necesario.
|
||
94 | *
|
||
95 | * Revision 1.17 2007/03/05 13:49:42 ppiqueras
|
||
96 | * Si una capa WFS no tiene campos (y por tanto no tiene un campo obligatorio de tipo geometr?a), que avise al usuario y no permita que se intente cargar dicha capa.
|
||
97 | *
|
||
98 | * Revision 1.16 2007/02/22 12:25:09 ppiqueras
|
||
99 | * A?adidas tool tip text.
|
||
100 | *
|
||
101 | * Revision 1.15 2007/02/09 14:12:39 jorpiell
|
||
102 | * Soporte para WFS 1.1 y WFS-T
|
||
103 | *
|
||
104 | * Revision 1.14 2007/02/07 13:26:23 ppiqueras
|
||
105 | * Corregido bug: al seleccionar una feature, pero sin cerrar el di?logo, se retrocede y se conecta a otro servidor, se manten?a la posici?n seleccionada en la tabla de features. Se ha solucionado haciendo que se quede deseleccionada toda la tabla de features.
|
||
106 | *
|
||
107 | * Revision 1.13 2007/01/23 13:12:43 ppiqueras
|
||
108 | * Corregido un peque?o bug: el ?rea de texto del nombre de la feature no debe ser editable, dado que si se edita no procesa el texto escrito.
|
||
109 | *
|
||
110 | * Revision 1.12 2007/01/15 14:16:22 ppiqueras
|
||
111 | * Corregido bug: no cargaba los campos al principio y adem?s se ejecutaba m?s de una vez.
|
||
112 | *
|
||
113 | * Revision 1.11 2006/12/15 13:57:34 ppiqueras
|
||
114 | * eliminado un import que sobraba
|
||
115 | *
|
||
116 | * Revision 1.10 2006/12/12 10:24:45 ppiqueras
|
||
117 | * Nueva funcionalidad: Pulsando doble 'click' sobre una capa de un servidor, se carga (igual que antes), pero adem?s se avanza a la siguiente pesta?a sin tener que pulsar el bot?n 'Siguiente'.
|
||
118 | *
|
||
119 | * Revision 1.9 2006/12/04 08:59:47 ppiqueras
|
||
120 | * Algunos bugs corregidos. A cambio hay 2 bugs relacionados que todav?a no han sido corregidos (ver PHPCollab) (los tiene asignados Jorge).
|
||
121 | *
|
||
122 | * Revision 1.8 2006/10/27 06:44:56 jorpiell
|
||
123 | * Se han cambiado algunas etiquetas de texto que sal?an recortadas
|
||
124 | *
|
||
125 | * Revision 1.7 2006/07/21 11:50:31 jaume
|
||
126 | * improved appearance
|
||
127 | *
|
||
128 | * Revision 1.6 2006/06/21 12:35:45 jorpiell
|
||
129 | * Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
|
||
130 | *
|
||
131 | * Revision 1.5 2006/05/25 10:31:06 jorpiell
|
||
132 | * Como ha cambiado la forma de mostrar las capas (una tabla, en lugar de una lista), los paneles han tenido que ser modificados
|
||
133 | *
|
||
134 | * Revision 1.4 2006/05/23 08:09:39 jorpiell
|
||
135 | * Se ha cambiado la forma en la que se leian los valores seleccionados en los paneles y se ha cambiado el comportamiento de los botones
|
||
136 | *
|
||
137 | * Revision 1.3 2006/05/19 12:57:08 jorpiell
|
||
138 | * Modificados algunos paneles
|
||
139 | *
|
||
140 | * Revision 1.2 2006/04/20 16:38:24 jorpiell
|
||
141 | * Ahora mismo ya se puede hacer un getCapabilities y un getDescribeType de la capa seleccionada para ver los atributos a dibujar. Queda implementar el panel de opciones y hacer el getFeature().
|
||
142 | *
|
||
143 | *
|
||
144 | */
|
||
145 | |||
146 | |||
147 | /**
|
||
148 | * <p>Panel where user can select a feature type to load as a WFS layer.</p>
|
||
149 | *
|
||
150 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
151 | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
||
152 | */
|
||
153 | public class WFSSelectFeaturePanel extends AbstractWFSPanel { |
||
154 | private static final long serialVersionUID = -3781080396069038450L; |
||
155 | 28083 | jpiera | private JPanel featureListPanel = null; |
156 | 27885 | jpiera | private JScrollPane jScrollPane = null; |
157 | private LayerTable lstFeatures = null; |
||
158 | private JTextField txtName = null; |
||
159 | private JCheckBox chkExtendedNames = null; |
||
160 | private JPanel layerNamePanel = null; |
||
161 | private WFSSelectedFeature layerNode = null; |
||
162 | private ListSelectionListener listSelectionListener = null; |
||
163 | |||
164 | /**
|
||
165 | * Creates a new WFS select feature panel.
|
||
166 | */
|
||
167 | public WFSSelectFeaturePanel() {
|
||
168 | super();
|
||
169 | initialize(); |
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * This method initializes coveragesListPanel
|
||
174 | *
|
||
175 | * @return javax.swing.JPanel
|
||
176 | */
|
||
177 | private JPanel getFeaturesListPanel() { |
||
178 | 28083 | jpiera | if (featureListPanel == null) { |
179 | java.awt.GridBagConstraints gridBagConstraints; |
||
180 | featureListPanel = new JPanel(); |
||
181 | featureListPanel.setLayout(new java.awt.GridBagLayout());
|
||
182 | featureListPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
||
183 | 27885 | jpiera | null, PluginServices.getText(this, "select_features"), |
184 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
185 | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
||
186 | 28083 | jpiera | |
187 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
188 | gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
||
189 | gridBagConstraints.weightx = 1.0;
|
||
190 | gridBagConstraints.weighty = 1.0;
|
||
191 | featureListPanel.add(getJScrollPane(), gridBagConstraints); |
||
192 | 27885 | jpiera | } |
193 | |||
194 | 28083 | jpiera | return featureListPanel;
|
195 | 27885 | jpiera | } |
196 | |||
197 | /**
|
||
198 | * This method initializes jScrollPane
|
||
199 | *
|
||
200 | * @return javax.swing.JScrollPane
|
||
201 | */
|
||
202 | private JScrollPane getJScrollPane() { |
||
203 | if (jScrollPane == null) { |
||
204 | 28083 | jpiera | jScrollPane = new JScrollPane(); |
205 | 27885 | jpiera | jScrollPane.setViewportView(getLstFeatures()); |
206 | jScrollPane.setToolTipText(PluginServices.getText(jScrollPane, "feature_Selection_Info"));
|
||
207 | } |
||
208 | |||
209 | return jScrollPane;
|
||
210 | } |
||
211 | |||
212 | /**
|
||
213 | * This method initializes lstFeatures
|
||
214 | *
|
||
215 | * @return javax.swing.LayerTable
|
||
216 | */
|
||
217 | public LayerTable getLstFeatures() {
|
||
218 | if (lstFeatures == null) { |
||
219 | lstFeatures = new LayerTable();
|
||
220 | lstFeatures.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
221 | lstFeatures.getSelectionModel().addListSelectionListener(getListSelectionListener()); |
||
222 | lstFeatures.setToolTipText(PluginServices.getText(lstFeatures, "feature_Selection_Info"));
|
||
223 | |||
224 | // Double-click -> click the 'Next' button
|
||
225 | lstFeatures.addMouseListener(new MouseAdapter() { |
||
226 | /*
|
||
227 | * (non-Javadoc)
|
||
228 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
229 | */
|
||
230 | public void mouseClicked(MouseEvent e) { |
||
231 | if (e.getClickCount() == 2) { |
||
232 | Object obj = getPanelGroup();
|
||
233 | |||
234 | if ((obj != null) && (obj instanceof WFSParamsPanel)) |
||
235 | ((WFSParamsPanel)obj).doClickOnNextButton(); |
||
236 | } |
||
237 | } |
||
238 | }); |
||
239 | } |
||
240 | |||
241 | return lstFeatures;
|
||
242 | } |
||
243 | |||
244 | /**
|
||
245 | * Creates the list selection listener for the layers list
|
||
246 | *
|
||
247 | * @return the listener
|
||
248 | */
|
||
249 | private ListSelectionListener getListSelectionListener(){ |
||
250 | if (listSelectionListener == null){ |
||
251 | listSelectionListener = new ListSelectionListener(){ |
||
252 | public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
||
253 | DefaultListSelectionModel model = (DefaultListSelectionModel) e.getSource(); |
||
254 | LayerTableModel t_model = ((LayerTableModel)lstFeatures.getModel()); |
||
255 | if (t_model.isUpdatingSelection())
|
||
256 | return;
|
||
257 | 28083 | jpiera | |
258 | 27885 | jpiera | // With this condition we force to execute the updating only when a row has been selected by the user
|
259 | if ((model.getMinSelectionIndex() > -1) && (e.getValueIsAdjusting() == false)) { |
||
260 | // Indicate that now we are loading a new layer
|
||
261 | IPanelGroup panelGroup = getPanelGroup(); |
||
262 | 28083 | jpiera | |
263 | 27885 | jpiera | if (panelGroup == null) |
264 | return;
|
||
265 | |||
266 | if (((WFSParamsPanel)panelGroup).getFilterPanel() == null) |
||
267 | return;
|
||
268 | 36036 | jpiera | |
269 | 27885 | jpiera | refreshData(); |
270 | } |
||
271 | } |
||
272 | }; |
||
273 | } |
||
274 | |||
275 | return listSelectionListener;
|
||
276 | } |
||
277 | |||
278 | /**
|
||
279 | * This method initializes jTextField
|
||
280 | *
|
||
281 | * @return javax.swing.JTextField
|
||
282 | */
|
||
283 | public JTextField getTxtName() { |
||
284 | if (txtName == null) { |
||
285 | txtName = new JTextField(); |
||
286 | txtName.setBounds(6, 19, 472, 20); |
||
287 | txtName.setText(PluginServices.getText(this, "WFSLayer")); |
||
288 | txtName.setEditable(false);
|
||
289 | txtName.setBackground(Color.WHITE);
|
||
290 | txtName.setToolTipText(PluginServices.getText(txtName, "feature_to_load"));
|
||
291 | |||
292 | txtName.getDocument().addDocumentListener(new DocumentListener() { |
||
293 | /*
|
||
294 | * (non-Javadoc)
|
||
295 | * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
|
||
296 | */
|
||
297 | public void changedUpdate(DocumentEvent e) { |
||
298 | } |
||
299 | |||
300 | /*
|
||
301 | * (non-Javadoc)
|
||
302 | * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
|
||
303 | */
|
||
304 | public void insertUpdate(DocumentEvent e) { |
||
305 | IPanelGroup panelGroup = getPanelGroup(); |
||
306 | |||
307 | if (panelGroup == null) |
||
308 | return;
|
||
309 | |||
310 | ((WFSParamsPanel)panelGroup).setApplicable(true);
|
||
311 | } |
||
312 | |||
313 | /*
|
||
314 | * (non-Javadoc)
|
||
315 | * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
|
||
316 | */
|
||
317 | public void removeUpdate(DocumentEvent e) { |
||
318 | } |
||
319 | }); |
||
320 | } |
||
321 | |||
322 | return txtName;
|
||
323 | } |
||
324 | |||
325 | /**
|
||
326 | * This method initializes chkExtendedNames
|
||
327 | *
|
||
328 | * @return javax.swing.JCheckBox
|
||
329 | */
|
||
330 | private JCheckBox getChkExtendedNames() { |
||
331 | if (chkExtendedNames == null) { |
||
332 | chkExtendedNames = new JCheckBox(); |
||
333 | chkExtendedNames.setText(PluginServices.getText(this, "show_layer_names")); |
||
334 | chkExtendedNames.setBounds(10, 372, 382, 20); |
||
335 | chkExtendedNames.addItemListener(new java.awt.event.ItemListener() {
|
||
336 | /*
|
||
337 | * (non-Javadoc)
|
||
338 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
||
339 | */
|
||
340 | public void itemStateChanged(java.awt.event.ItemEvent e) { |
||
341 | boolean b = chkExtendedNames.isSelected();
|
||
342 | getLstFeatures().setShowLayerNames(b); |
||
343 | getLstFeatures().repaint(); |
||
344 | } |
||
345 | }); |
||
346 | } |
||
347 | |||
348 | return chkExtendedNames;
|
||
349 | } |
||
350 | |||
351 | /**
|
||
352 | * Set the selected layer node
|
||
353 | *
|
||
354 | * @param layerNode the layer to select
|
||
355 | */
|
||
356 | public void setSelectedFeature(WFSSelectedFeature layerNode){ |
||
357 | int index = -1; |
||
358 | |||
359 | for (int i=0; i<getLstFeatures().getRowCount(); i++){ |
||
360 | WFSSelectedFeature node = (WFSSelectedFeature)getLstFeatures().getValueAt(i); |
||
361 | |||
362 | if (node != null && layerNode.getName().equals(node.getName())){ |
||
363 | index = i; |
||
364 | } |
||
365 | } |
||
366 | |||
367 | if (index != -1){ |
||
368 | getLstFeatures().changeSelection(index, 0, false, false); |
||
369 | } |
||
370 | } |
||
371 | |||
372 | /**
|
||
373 | * Refresh the features list
|
||
374 | */
|
||
375 | public void refresh(WFSSelectedFeature layer) { |
||
376 | // Unselects all features
|
||
377 | unselectAllFeatures(); |
||
378 | |||
379 | // Add the new features
|
||
380 | 27945 | jpiera | getLstFeatures().addFeatures(getSelectedFeatureManager().getLayerList()); |
381 | 27885 | jpiera | |
382 | if (layer != null) { |
||
383 | layerNode = layer; |
||
384 | setLayerName(layer.getName()); |
||
385 | setSelectedFeature(layer); |
||
386 | } |
||
387 | } |
||
388 | |||
389 | /**
|
||
390 | * Refreshes the wizard components data each time a feature
|
||
391 | * is selected. The <i>describeFeatureType</i> operation must be sent.
|
||
392 | */
|
||
393 | public void refreshData() { |
||
394 | WFSSelectedFeature lyr = (WFSSelectedFeature)getLstFeatures().getSelectedValue(); |
||
395 | |||
396 | try {
|
||
397 | getTxtName().setText(lyr.getTitle()); |
||
398 | } catch (NullPointerException e){ |
||
399 | getTxtName().setText(PluginServices.getText(this,"default_name")); |
||
400 | NotificationManager.addError(PluginServices.getText(this,"default_name"), e); |
||
401 | } |
||
402 | |||
403 | IPanelGroup panelGroup = getPanelGroup(); |
||
404 | |||
405 | if (panelGroup == null) |
||
406 | return;
|
||
407 | |||
408 | ((WFSParamsPanel)panelGroup).refresh(lyr); |
||
409 | |||
410 | repaint(); |
||
411 | } |
||
412 | |||
413 | /**
|
||
414 | * This method initializes layerNamePanel
|
||
415 | *
|
||
416 | * @return javax.swing.JPanel
|
||
417 | */
|
||
418 | private JPanel getLayerNamePanel() { |
||
419 | if (layerNamePanel == null) { |
||
420 | 28083 | jpiera | java.awt.GridBagConstraints gridBagConstraints; |
421 | 27885 | jpiera | layerNamePanel = new JPanel(); |
422 | 28083 | jpiera | layerNamePanel.setLayout(new java.awt.GridBagLayout());
|
423 | 27885 | jpiera | layerNamePanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
424 | null, PluginServices.getText(this, "layer_name"), |
||
425 | javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
||
426 | 28083 | jpiera | javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
427 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
428 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
429 | gridBagConstraints.weightx = 1.0;
|
||
430 | layerNamePanel.add(getTxtName(), gridBagConstraints); |
||
431 | 27885 | jpiera | } |
432 | |||
433 | return layerNamePanel;
|
||
434 | } |
||
435 | |||
436 | /**
|
||
437 | * Gets the name of the layer (feature) selected.
|
||
438 | *
|
||
439 | * @return the layer name
|
||
440 | */
|
||
441 | public String getLayerName() { |
||
442 | 31838 | jpiera | if ((WFSSelectedFeature)getLstFeatures().getSelectedValue() != null){ |
443 | return ((WFSSelectedFeature)getLstFeatures().getSelectedValue()).getName();
|
||
444 | } |
||
445 | return ""; |
||
446 | 27885 | jpiera | } |
447 | |||
448 | /**
|
||
449 | * Gets the name space of the layer (feature) selected.
|
||
450 | *
|
||
451 | * @return the name space
|
||
452 | */
|
||
453 | public String getLayerNameSpace(){ |
||
454 | return ((WFSSelectedFeature)getLstFeatures().getSelectedValue()).getNameSpace();
|
||
455 | } |
||
456 | |||
457 | /**
|
||
458 | * Gets the selected feature.
|
||
459 | *
|
||
460 | * @return the selected feature
|
||
461 | */
|
||
462 | public WFSSelectedFeature getSelectedFeature() {
|
||
463 | WFSSelectedFeature selectedFeature = (WFSSelectedFeature)getLstFeatures().getSelectedValue(); |
||
464 | |||
465 | if (selectedFeature != null) { |
||
466 | layerNode = selectedFeature; |
||
467 | } |
||
468 | |||
469 | return layerNode;
|
||
470 | } |
||
471 | |||
472 | /**
|
||
473 | * Sets the name of the feature selected.
|
||
474 | *
|
||
475 | * @param name the name of the feature selected
|
||
476 | */
|
||
477 | public void setLayerName(String name) { |
||
478 | getTxtName().setText(name); |
||
479 | } |
||
480 | |||
481 | /*
|
||
482 | * (non-Javadoc)
|
||
483 | * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#initialize()
|
||
484 | */
|
||
485 | protected void initialize() { |
||
486 | setLabel(PluginServices.getText(this, "feature")); |
||
487 | setLabelGroup(PluginServices.getText(this, "wfs")); |
||
488 | 28083 | jpiera | java.awt.GridBagConstraints gridBagConstraints; |
489 | this.setLayout(new java.awt.GridBagLayout()); |
||
490 | |||
491 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
492 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
493 | gridBagConstraints.weightx = 1.0;
|
||
494 | this.add(getLayerNamePanel(), gridBagConstraints);
|
||
495 | |||
496 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
497 | gridBagConstraints.gridx = 0;
|
||
498 | gridBagConstraints.gridy = 1;
|
||
499 | gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
||
500 | gridBagConstraints.weightx = 1.0;
|
||
501 | gridBagConstraints.weighty = 1.0;
|
||
502 | this.add(getFeaturesListPanel(), gridBagConstraints);
|
||
503 | |||
504 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
505 | gridBagConstraints.gridx = 0;
|
||
506 | gridBagConstraints.gridy = 2;
|
||
507 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
508 | gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
||
509 | gridBagConstraints.weightx = 1.0;
|
||
510 | this.add(getChkExtendedNames(), gridBagConstraints);
|
||
511 | |||
512 | 27885 | jpiera | } |
513 | 28083 | jpiera | |
514 | 27885 | jpiera | /*
|
515 | * (non-Javadoc)
|
||
516 | * @see com.iver.cit.gvsig.gui.panels.AbstractWFSPanel#setReference(java.lang.Object)
|
||
517 | */
|
||
518 | public void setReference(Object ref) { |
||
519 | super.setReference(ref);
|
||
520 | 28083 | jpiera | // if (ref instanceof FLyrWFS){
|
521 | // getPanelGroup().setEnabledApplyButton(false);
|
||
522 | // }
|
||
523 | 27885 | jpiera | } |
524 | 28083 | jpiera | |
525 | 27885 | jpiera | /**
|
526 | * Updates the list with no feature selected.
|
||
527 | */
|
||
528 | public void unselectAllFeatures() { |
||
529 | // Reset the last row selection of the features table
|
||
530 | int numberOfFeatures = getLstFeatures().getRowCount();
|
||
531 | |||
532 | if (numberOfFeatures > 0) { |
||
533 | ListSelectionModel model = getLstFeatures().getSelectionModel();
|
||
534 | model.removeSelectionInterval(0, numberOfFeatures - 1); // whatever row selection |
||
535 | } |
||
536 | } |
||
537 | |||
538 | /**
|
||
539 | * Table with the information of all layers which could be selected from the server connected.
|
||
540 | *
|
||
541 | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
||
542 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
543 | */
|
||
544 | public class LayerTable extends JTable { |
||
545 | private static final long serialVersionUID = 4700375945858283696L; |
||
546 | private int headerSelected = -1; |
||
547 | 28083 | jpiera | |
548 | 27885 | jpiera | /**
|
549 | * Creates a new instance of <code>LayerTable</code>
|
||
550 | */
|
||
551 | public LayerTable() {
|
||
552 | super();
|
||
553 | |||
554 | setModel(new LayerTableModel());
|
||
555 | |||
556 | getTableHeader().setUI(new BasicTableHeaderSelectableUI());
|
||
557 | 28083 | jpiera | |
558 | 27885 | jpiera | getTableHeader().addMouseListener(new MouseAdapter() { |
559 | /*
|
||
560 | * (non-Javadoc)
|
||
561 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
||
562 | */
|
||
563 | public void mouseClicked(MouseEvent e) { |
||
564 | // Sorts according the selected column
|
||
565 | ((LayerTableModel)getModel()).sort(getTableHeader().getColumnModel().getColumnIndexAtX(e.getX())); |
||
566 | } |
||
567 | |||
568 | /*
|
||
569 | * (non-Javadoc)
|
||
570 | * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
|
||
571 | */
|
||
572 | public void mousePressed(MouseEvent e) { |
||
573 | headerSelected = getTableHeader().getColumnModel().getColumnIndexAtX(e.getX()); |
||
574 | getTableHeader().repaint(); |
||
575 | } |
||
576 | |||
577 | /*
|
||
578 | * (non-Javadoc)
|
||
579 | * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
|
||
580 | */
|
||
581 | public void mouseReleased(MouseEvent e) { |
||
582 | headerSelected = -1;
|
||
583 | } |
||
584 | }); |
||
585 | } |
||
586 | |||
587 | 28083 | jpiera | /*
|
588 | * (non-Javadoc)
|
||
589 | * @see javax.swing.JTable#createDefaultColumnsFromModel()
|
||
590 | */
|
||
591 | public void createDefaultColumnsFromModel() { |
||
592 | TableModel m = getModel();
|
||
593 | if (m != null) { |
||
594 | // Remove any current columns
|
||
595 | TableColumnModel cm = getColumnModel();
|
||
596 | while (cm.getColumnCount() > 0) { |
||
597 | cm.removeColumn(cm.getColumn(0));
|
||
598 | } |
||
599 | 27885 | jpiera | |
600 | 28083 | jpiera | // Create new columns from the data model info
|
601 | for (int i = 0; i < m.getColumnCount(); i++) { |
||
602 | TableColumn newColumn = new TableColumn(i); |
||
603 | |||
604 | // Special renderer for supporting selection of a particular column header
|
||
605 | newColumn.setHeaderRenderer(new DefaultTableSelectableCellRenderer());
|
||
606 | addColumn(newColumn); |
||
607 | } |
||
608 | } |
||
609 | } |
||
610 | |||
611 | 27885 | jpiera | /**
|
612 | * Gets the selected <i>WFS</i> layer.
|
||
613 | *
|
||
614 | * @return node of the selected <i>WFS</i> layer
|
||
615 | */
|
||
616 | public WFSSelectedFeature getSelectedValue() {
|
||
617 | int selectedRow = getSelectedRow();
|
||
618 | LayerTableModel model = (LayerTableModel)getModel(); |
||
619 | |||
620 | return model.getLayerAt(selectedRow);
|
||
621 | } |
||
622 | |||
623 | /**
|
||
624 | * Gets the layer at a row position.
|
||
625 | *
|
||
626 | * @return node of the selected <i>WFS</i> layer
|
||
627 | */
|
||
628 | public WFSSelectedFeature getValueAt(int position) { |
||
629 | if (position < this.getRowCount()) { |
||
630 | LayerTableModel model = (LayerTableModel)getModel(); |
||
631 | |||
632 | return model.getLayerAt(position);
|
||
633 | } |
||
634 | |||
635 | return null; |
||
636 | } |
||
637 | |||
638 | /**
|
||
639 | * Adds the available features to load as a <i>WFS</i> layer.
|
||
640 | *
|
||
641 | * @param features available features
|
||
642 | */
|
||
643 | public void addFeatures(WFSSelectedFeature[] features) { |
||
644 | LayerTableModel model = (LayerTableModel)getModel(); |
||
645 | model.deleteAllRows(); |
||
646 | |||
647 | for (int i=0 ; i < features.length ; i++){ |
||
648 | model.addRow(features[i]); |
||
649 | } |
||
650 | } |
||
651 | |||
652 | /**
|
||
653 | * Shows the names of the features.
|
||
654 | *
|
||
655 | * @param showFeatureNameType The showLayerNames to set.
|
||
656 | */
|
||
657 | public void setShowLayerNames(boolean showFeatureNameType) { |
||
658 | LayerTableModel model = (LayerTableModel)getModel(); |
||
659 | model.setShowedFeatureNameType(showFeatureNameType); |
||
660 | } |
||
661 | 28083 | jpiera | |
662 | 27885 | jpiera | /**
|
663 | * Model of the <code>LayerTable</code> that stores the features available to load as a WFS layer.
|
||
664 | *
|
||
665 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
666 | * @author Pablo Piqueras Bartolome (pablo.piqueras@iver.es)
|
||
667 | */
|
||
668 | public class LayerTableModel extends AbstractTableModel { |
||
669 | private static final long serialVersionUID = 2722138264867593508L; |
||
670 | private Vector<WFSSelectedFeature> layers = new Vector<WFSSelectedFeature>(); |
||
671 | private boolean showFeatureNameType = false; |
||
672 | private WFSLayerStringComparator stringComparator;
|
||
673 | private boolean updatingSelection; |
||
674 | private short previousColumnSorted; |
||
675 | |||
676 | |||
677 | /**
|
||
678 | * Constructs an investment table model.
|
||
679 | */
|
||
680 | public LayerTableModel(){
|
||
681 | super();
|
||
682 | |||
683 | // Alphabetical sort ordering support
|
||
684 | updatingSelection = false;
|
||
685 | previousColumnSorted = -1;
|
||
686 | Collator collator = Collator.getInstance(new Locale("en_EN")); |
||
687 | stringComparator = new WFSLayerStringComparator();
|
||
688 | stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, collator));
|
||
689 | stringComparator.setCaseSensitive(false);
|
||
690 | stringComparator.setAscendingOrdering(true);
|
||
691 | } |
||
692 | 28083 | jpiera | |
693 | |||
694 | 27885 | jpiera | /*
|
695 | * (non-Javadoc)
|
||
696 | * @see javax.swing.table.TableModel#getRowCount()
|
||
697 | */
|
||
698 | public int getRowCount(){ |
||
699 | return layers.size();
|
||
700 | } |
||
701 | |||
702 | /*
|
||
703 | * (non-Javadoc)
|
||
704 | * @see javax.swing.table.TableModel#getColumnCount()
|
||
705 | */
|
||
706 | public int getColumnCount(){ |
||
707 | return 2; |
||
708 | } |
||
709 | |||
710 | /*
|
||
711 | * (non-Javadoc)
|
||
712 | * @see javax.swing.table.TableModel#getValueAt(int, int)
|
||
713 | */
|
||
714 | public Object getValueAt(int rowNumber, int columnNumber){ |
||
715 | if (rowNumber < layers.size()) {
|
||
716 | WFSSelectedFeature layer = (WFSSelectedFeature)layers.get(rowNumber); |
||
717 | |||
718 | if (columnNumber == 0) { |
||
719 | return getLayerName(layer);
|
||
720 | } else {
|
||
721 | 34026 | jpiera | if (layer.getGeometryField() != null){ |
722 | 34113 | jpiera | return PluginServices.getText(this, layer.getGeometryField().getType()); |
723 | 34026 | jpiera | } |
724 | return ""; |
||
725 | 27885 | jpiera | } |
726 | } else {
|
||
727 | return ""; |
||
728 | } |
||
729 | } |
||
730 | |||
731 | /**
|
||
732 | * Gets the layer name displaying the type name of the feature collection associated if it's needed.
|
||
733 | *
|
||
734 | * @param layer a <i>WFS</i> layer
|
||
735 | * @return the layer name
|
||
736 | */
|
||
737 | private String getLayerName(WFSSelectedFeature layer){ |
||
738 | if (showFeatureNameType){
|
||
739 | return "[" + layer.getName() + "] " + layer.getTitle(); |
||
740 | } else {
|
||
741 | return layer.getTitle();
|
||
742 | } |
||
743 | } |
||
744 | |||
745 | /**
|
||
746 | * Gets the layer at the specified position.
|
||
747 | *
|
||
748 | * @param rowNumber row position
|
||
749 | * @return <i>WFS</i> layer node
|
||
750 | */
|
||
751 | public WFSSelectedFeature getLayerAt(int rowNumber){ |
||
752 | try {
|
||
753 | if (rowNumber == -1) |
||
754 | return null; |
||
755 | |||
756 | return (WFSSelectedFeature)layers.get(rowNumber);
|
||
757 | } catch (ArrayIndexOutOfBoundsException e) { |
||
758 | NotificationManager.addError(e); |
||
759 | return null; |
||
760 | } |
||
761 | } |
||
762 | |||
763 | /**
|
||
764 | * Adds a new layer to the table model, each table will be represented as a row.
|
||
765 | *
|
||
766 | * @param layer a new <i>WFS</i> layer
|
||
767 | */
|
||
768 | public void addRow(WFSSelectedFeature layer){ |
||
769 | layers.add(layer); |
||
770 | fireTableRowsInserted(getRowCount(), getRowCount()); |
||
771 | fireTableRowsUpdated(0,getRowCount());
|
||
772 | } |
||
773 | |||
774 | /**
|
||
775 | * Deletes all the table rows.
|
||
776 | */
|
||
777 | public void deleteAllRows(){ |
||
778 | layers.clear(); |
||
779 | int rows = getRowCount();
|
||
780 | |||
781 | if (rows >= 1){ |
||
782 | fireTableRowsDeleted(0, rows - 1); |
||
783 | } |
||
784 | } |
||
785 | |||
786 | /**
|
||
787 | * Delete all the table rows
|
||
788 | */
|
||
789 | public void deleteRow(int rowPosition){ |
||
790 | layers.remove(rowPosition); |
||
791 | fireTableRowsDeleted(rowPosition, rowPosition); |
||
792 | fireTableRowsUpdated(0,getRowCount());
|
||
793 | } |
||
794 | |||
795 | /*
|
||
796 | * (non-Javadoc)
|
||
797 | * @see javax.swing.table.TableModel#getColumnName(int)
|
||
798 | */
|
||
799 | public String getColumnName(int columnIndex){ |
||
800 | if (columnIndex == 0){ |
||
801 | return PluginServices.getText(this, "layerName"); |
||
802 | }else{
|
||
803 | return PluginServices.getText(this, "layerType"); |
||
804 | } |
||
805 | } |
||
806 | |||
807 | /**
|
||
808 | * Gets if shows the feature name type.
|
||
809 | *
|
||
810 | * @return <code>true</code> if shows the feature name type; <code>false</code> otherwise
|
||
811 | */
|
||
812 | public boolean isShowedFeatureNameType() { |
||
813 | return showFeatureNameType;
|
||
814 | } |
||
815 | |||
816 | /**
|
||
817 | * Gets if shows the feature name type.
|
||
818 | *
|
||
819 | * @param showFeatureNameType <code>true</code> if shows the feature name type; <code>false</code> otherwise
|
||
820 | */
|
||
821 | public void setShowedFeatureNameType(boolean showFeatureNameType) { |
||
822 | this.showFeatureNameType = showFeatureNameType;
|
||
823 | 28083 | jpiera | |
824 | 27885 | jpiera | this.stringComparator.setShowFeatureNameType(showFeatureNameType);
|
825 | } |
||
826 | |||
827 | /**
|
||
828 | * Sorts the rows of the table alphabetically.
|
||
829 | *
|
||
830 | * @param column index of the column to sort. In this table there are only 2 columns.
|
||
831 | */
|
||
832 | public void sort(int column) { |
||
833 | 28083 | jpiera | // Orders the layer alphabetically according the Spanish alphabetically rules
|
834 | 27885 | jpiera | switch(column) {
|
835 | 28083 | jpiera | case 0: |
836 | stringComparator.setColumn(WFSLayerStringComparator.LAYER_NAME); |
||
837 | break;
|
||
838 | case 1: |
||
839 | stringComparator.setColumn(WFSLayerStringComparator.GEOMETRY_TYPE); |
||
840 | break;
|
||
841 | 27885 | jpiera | } |
842 | 28083 | jpiera | |
843 | 27885 | jpiera | if (previousColumnSorted != column)
|
844 | stringComparator.setAscendingOrdering(true);
|
||
845 | 28083 | jpiera | |
846 | 27885 | jpiera | previousColumnSorted = (short) column;
|
847 | |||
848 | WFSSelectedFeature layer = getSelectedValue(); |
||
849 | 28083 | jpiera | |
850 | 27885 | jpiera | Collections.sort(layers, stringComparator);
|
851 | |||
852 | if (layer != null) { |
||
853 | updatingSelection = true;
|
||
854 | unselectAllFeatures(); |
||
855 | int row = Collections.binarySearch(layers, layer, stringComparator); |
||
856 | 28083 | jpiera | |
857 | 27885 | jpiera | if (row != -1) { |
858 | ListSelectionModel model = getSelectionModel();
|
||
859 | model.setLeadSelectionIndex(row); |
||
860 | } |
||
861 | 28083 | jpiera | |
862 | 27885 | jpiera | updatingSelection = false;
|
863 | } |
||
864 | stringComparator.setAscendingOrdering(!stringComparator.isAscendingOrdering()); |
||
865 | } |
||
866 | 28083 | jpiera | |
867 | 27885 | jpiera | /**
|
868 | * Determines if now is updating the selection of the previous selected item.
|
||
869 | *
|
||
870 | * @return <code>true</code> if now is updating the selection of the previous selected item; otherwise <code>false</code>
|
||
871 | */
|
||
872 | public boolean isUpdatingSelection() { |
||
873 | return updatingSelection;
|
||
874 | } |
||
875 | } |
||
876 | |||
877 | /**
|
||
878 | * <p>Enhances {@link BasicTableHeaderUI BasicTableHeaderUI} adding support for column head selection.</p>
|
||
879 | *
|
||
880 | * @see BasicTableHeaderUI
|
||
881 | *
|
||
882 | * @version 29/01/2008
|
||
883 | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
||
884 | */
|
||
885 | 28083 | jpiera | private class BasicTableHeaderSelectableUI extends BasicTableHeaderUI { |
886 | 27885 | jpiera | /**
|
887 | * Creates a new BasicTableHeaderSelectableUI object
|
||
888 | */
|
||
889 | public BasicTableHeaderSelectableUI() {
|
||
890 | super();
|
||
891 | } |
||
892 | 28083 | jpiera | |
893 | 27885 | jpiera | //
|
894 | // Some Paint Methods and support re-implemented
|
||
895 | //
|
||
896 | 28083 | jpiera | |
897 | 27885 | jpiera | /*
|
898 | * (non-Javadoc)
|
||
899 | * @see javax.swing.plaf.basic.BasicTableHeaderUI#paint(java.awt.Graphics, javax.swing.JComponent)
|
||
900 | */
|
||
901 | 28083 | jpiera | public void paint(Graphics g, JComponent c) { |
902 | 27885 | jpiera | if (header.getColumnModel().getColumnCount() <= 0) { |
903 | 28083 | jpiera | return;
|
904 | 27885 | jpiera | } |
905 | 28083 | jpiera | |
906 | 27885 | jpiera | boolean ltr = header.getComponentOrientation().isLeftToRight();
|
907 | 28083 | jpiera | |
908 | 27885 | jpiera | Rectangle clip = g.getClipBounds();
|
909 | 28083 | jpiera | Point left = clip.getLocation();
|
910 | Point right = new Point( clip.x + clip.width - 1, clip.y ); |
||
911 | 27885 | jpiera | TableColumnModel cm = header.getColumnModel();
|
912 | 28083 | jpiera | int cMin = header.columnAtPoint( ltr ? left : right );
|
913 | int cMax = header.columnAtPoint( ltr ? right : left );
|
||
914 | // This should never happen.
|
||
915 | if (cMin == -1) { |
||
916 | cMin = 0;
|
||
917 | } |
||
918 | // If the table does not have enough columns to fill the view we'll get -1.
|
||
919 | // Replace this with the index of the last column.
|
||
920 | if (cMax == -1) { |
||
921 | cMax = cm.getColumnCount()-1;
|
||
922 | } |
||
923 | 27885 | jpiera | |
924 | TableColumn draggedColumn = header.getDraggedColumn();
|
||
925 | int columnWidth;
|
||
926 | 28083 | jpiera | Rectangle cellRect = header.getHeaderRect(ltr ? cMin : cMax);
|
927 | 27885 | jpiera | TableColumn aColumn;
|
928 | if (ltr) {
|
||
929 | 28083 | jpiera | for(int column = cMin; column <= cMax ; column++) { |
930 | aColumn = cm.getColumn(column); |
||
931 | columnWidth = aColumn.getWidth(); |
||
932 | cellRect.width = columnWidth; |
||
933 | if (aColumn != draggedColumn) {
|
||
934 | paintCell(g, cellRect, column); |
||
935 | } |
||
936 | cellRect.x += columnWidth; |
||
937 | } |
||
938 | 27885 | jpiera | } else {
|
939 | 28083 | jpiera | for(int column = cMax; column >= cMin; column--) { |
940 | aColumn = cm.getColumn(column); |
||
941 | columnWidth = aColumn.getWidth(); |
||
942 | cellRect.width = columnWidth; |
||
943 | if (aColumn != draggedColumn) {
|
||
944 | paintCell(g, cellRect, column); |
||
945 | } |
||
946 | cellRect.x += columnWidth; |
||
947 | 27885 | jpiera | } |
948 | } |
||
949 | |||
950 | 28083 | jpiera | // Paint the dragged column if we are dragging.
|
951 | if (draggedColumn != null) { |
||
952 | int draggedColumnIndex = viewIndexForColumn(draggedColumn);
|
||
953 | Rectangle draggedCellRect = header.getHeaderRect(draggedColumnIndex);
|
||
954 | 27885 | jpiera | |
955 | 28083 | jpiera | // Draw a gray well in place of the moving column.
|
956 | g.setColor(header.getParent().getBackground()); |
||
957 | g.fillRect(draggedCellRect.x, draggedCellRect.y, |
||
958 | draggedCellRect.width, draggedCellRect.height); |
||
959 | 27885 | jpiera | |
960 | 28083 | jpiera | draggedCellRect.x += header.getDraggedDistance(); |
961 | 27885 | jpiera | |
962 | 28083 | jpiera | // Fill the background.
|
963 | g.setColor(header.getBackground()); |
||
964 | g.fillRect(draggedCellRect.x, draggedCellRect.y, |
||
965 | draggedCellRect.width, draggedCellRect.height); |
||
966 | |||
967 | paintCell(g, draggedCellRect, draggedColumnIndex); |
||
968 | } |
||
969 | |||
970 | 27885 | jpiera | // Remove all components in the rendererPane.
|
971 | rendererPane.removeAll(); |
||
972 | } |
||
973 | |||
974 | 28083 | jpiera | private void paintCell(Graphics g, Rectangle cellRect, int columnIndex) { |
975 | Component component = getHeaderRenderer(columnIndex);
|
||
976 | rendererPane.paintComponent(g, component, header, cellRect.x, cellRect.y, |
||
977 | cellRect.width, cellRect.height, true);
|
||
978 | } |
||
979 | 27885 | jpiera | |
980 | 28083 | jpiera | private Component getHeaderRenderer(int columnIndex) { |
981 | TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
|
||
982 | TableCellRenderer renderer = aColumn.getHeaderRenderer();
|
||
983 | |||
984 | if (renderer == null) { |
||
985 | renderer = header.getDefaultRenderer(); |
||
986 | } |
||
987 | |||
988 | if (headerSelected == columnIndex) {
|
||
989 | headerSelected = -1;
|
||
990 | return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), true, false, -1, columnIndex); |
||
991 | } |
||
992 | else {
|
||
993 | return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, columnIndex); |
||
994 | } |
||
995 | } |
||
996 | |||
997 | private int viewIndexForColumn(TableColumn aColumn) { |
||
998 | TableColumnModel cm = header.getColumnModel();
|
||
999 | |||
1000 | for (int column = 0; column < cm.getColumnCount(); column++) { |
||
1001 | if (cm.getColumn(column) == aColumn) {
|
||
1002 | return column;
|
||
1003 | } |
||
1004 | } |
||
1005 | |||
1006 | return -1; |
||
1007 | } |
||
1008 | } |
||
1009 | |||
1010 | /**
|
||
1011 | * <p>Simulates the selection / unselection of the head of the column clicked.</p>
|
||
1012 | *
|
||
1013 | 27885 | jpiera | * @version 29/01/2008
|
1014 | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
||
1015 | 28083 | jpiera | */
|
1016 | 27885 | jpiera | private class DefaultTableSelectableCellRenderer extends DefaultTableCellRenderer { |
1017 | private static final long serialVersionUID = -3896516869747447668L; |
||
1018 | |||
1019 | /*
|
||
1020 | * (non-Javadoc)
|
||
1021 | * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
|
||
1022 | */
|
||
1023 | public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
||
1024 | Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
||
1025 | 28083 | jpiera | |
1026 | 27885 | jpiera | Color bgColor = getTableHeader().getBackground();
|
1027 | 28083 | jpiera | |
1028 | 27885 | jpiera | if (isSelected)
|
1029 | 28083 | jpiera | comp.setBackground(new Color(bgColor.getRed() - 10 , bgColor.getGreen() - 10, bgColor.getBlue() - 10)); |
1030 | 27885 | jpiera | else
|
1031 | comp.setBackground(bgColor); |
||
1032 | |||
1033 | 28083 | jpiera | ((JLabel)comp).setText((value == null) ? "" : value.toString()); |
1034 | ((JLabel)comp).setBorder(UIManager.getBorder("TableHeader.cellBorder")); |
||
1035 | |||
1036 | 27885 | jpiera | return comp;
|
1037 | } |
||
1038 | } |
||
1039 | 28083 | jpiera | |
1040 | 27885 | jpiera | /**
|
1041 | * Compares two chain of characters alphabetically, bearing in mind the information of a WFS layer.
|
||
1042 | *
|
||
1043 | * @version 24/01/2008
|
||
1044 | * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
||
1045 | */
|
||
1046 | private class WFSLayerStringComparator extends StringComparator { |
||
1047 | public static final short LAYER_NAME = 0; |
||
1048 | public static final short GEOMETRY_TYPE = 1; |
||
1049 | 28083 | jpiera | |
1050 | 27885 | jpiera | protected short column = LAYER_NAME; // by default the first column |
1051 | protected boolean showFeatureNameType = false; // by default doesn't shows the feature name type |
||
1052 | protected boolean ascendingOrdering = true; // by default: ascending ordering |
||
1053 | |||
1054 | 28083 | jpiera | /*
|
1055 | * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||
1056 | */
|
||
1057 | public int compare(Object o1, Object o2) { |
||
1058 | String s1 = null, s2 = null; |
||
1059 | 27885 | jpiera | |
1060 | 28083 | jpiera | switch(column) {
|
1061 | case LAYER_NAME:
|
||
1062 | if (ascendingOrdering) {
|
||
1063 | s1 = o1.toString(); |
||
1064 | s2 = o2.toString(); |
||
1065 | } |
||
1066 | else {
|
||
1067 | s1 = o2.toString(); |
||
1068 | s2 = o1.toString(); |
||
1069 | } |
||
1070 | 27885 | jpiera | |
1071 | 28083 | jpiera | if (showFeatureNameType) {
|
1072 | if (ascendingOrdering) {
|
||
1073 | return super.compare(o1, o2); |
||
1074 | } |
||
1075 | else {
|
||
1076 | return super.compare(o2, o1); |
||
1077 | } |
||
1078 | } |
||
1079 | 27885 | jpiera | |
1080 | 28083 | jpiera | // Only if "showFeatureNameType == true" :
|
1081 | int index = s1.indexOf(']'); |
||
1082 | 27885 | jpiera | |
1083 | 28083 | jpiera | if (index > 0) |
1084 | s1 = s1.substring(index, s1.length()).trim(); |
||
1085 | else
|
||
1086 | s1 = s1.trim(); |
||
1087 | |||
1088 | index = s2.indexOf(']');
|
||
1089 | |||
1090 | if (index > 0) |
||
1091 | s2 = s2.substring(index, s2.length()).trim(); |
||
1092 | else
|
||
1093 | s2 = s2.trim(); |
||
1094 | |||
1095 | break;
|
||
1096 | case GEOMETRY_TYPE:
|
||
1097 | 34026 | jpiera | WFSFeatureField gType = ((WFSSelectedFeature)o1).getGeometryField(); |
1098 | 28083 | jpiera | |
1099 | if (gType == null) |
||
1100 | s1 = "";
|
||
1101 | else
|
||
1102 | s1 = gType.getName(); |
||
1103 | |||
1104 | 34026 | jpiera | gType = ((WFSSelectedFeature)o2).getGeometryField(); |
1105 | 28083 | jpiera | |
1106 | if (gType == null) |
||
1107 | s2 = "";
|
||
1108 | else
|
||
1109 | s2 = gType.getName(); |
||
1110 | |||
1111 | if (ascendingOrdering)
|
||
1112 | return super.compare(s1, s2); |
||
1113 | else
|
||
1114 | return super.compare(s2, s1); |
||
1115 | default:
|
||
1116 | return 0; |
||
1117 | } |
||
1118 | |||
1119 | // If localeRules is null -> use the default rules
|
||
1120 | if (getLocaleRules() == null) { |
||
1121 | if (isCaseSensitive()) {
|
||
1122 | return s1.compareTo(s2);
|
||
1123 | } |
||
1124 | else {
|
||
1125 | return s1.compareToIgnoreCase(s2);
|
||
1126 | } |
||
1127 | } |
||
1128 | else {
|
||
1129 | if (getLocaleRules().isUseLocaleRules()) {
|
||
1130 | Collator collator = getLocaleRules().getCollator();
|
||
1131 | |||
1132 | if (isCaseSensitive()) {
|
||
1133 | return collator.compare(s1, s2);
|
||
1134 | } |
||
1135 | else {
|
||
1136 | //return collator.compare(s1.toLowerCase(), s2.toLowerCase());
|
||
1137 | return collator.compare(s1.toUpperCase(), s2.toUpperCase());
|
||
1138 | } |
||
1139 | } |
||
1140 | else {
|
||
1141 | if (isCaseSensitive()) {
|
||
1142 | return s1.compareTo(s2);
|
||
1143 | } |
||
1144 | else {
|
||
1145 | return s1.compareToIgnoreCase(s2);
|
||
1146 | } |
||
1147 | } |
||
1148 | } |
||
1149 | } |
||
1150 | |||
1151 | /**
|
||
1152 | * Determines if the name of each element includes the type name.
|
||
1153 | *
|
||
1154 | * @return <code>true</code> if the name of each element includes the type name; otherwise <code>false</code>
|
||
1155 | */
|
||
1156 | 27885 | jpiera | public boolean isShowFeatureNameType() { |
1157 | return showFeatureNameType;
|
||
1158 | } |
||
1159 | |||
1160 | /**
|
||
1161 | * Sets if the name of each element includes the type name.
|
||
1162 | *
|
||
1163 | * @param showFeatureNameType <code>true</code> if the name of each element includes the type name; otherwise <code>false</code>
|
||
1164 | */
|
||
1165 | public void setShowFeatureNameType(boolean showFeatureNameType) { |
||
1166 | this.showFeatureNameType = showFeatureNameType;
|
||
1167 | } |
||
1168 | 28083 | jpiera | |
1169 | 27885 | jpiera | /**
|
1170 | * <p>Sets which column well be alphabetically sort ordered.</p>
|
||
1171 | *
|
||
1172 | * <p>There are two columns:
|
||
1173 | * <ul>
|
||
1174 | * <li><i>LAYER_NAME</i>: name of the layer.</li>
|
||
1175 | * <li><i>GEOMETRY_TYPE</i>: geometry type that layer is.</li>
|
||
1176 | * </ul>
|
||
1177 | * </p>
|
||
1178 | *
|
||
1179 | * @param column
|
||
1180 | */
|
||
1181 | public void setColumn(short column) { |
||
1182 | this.column = column;
|
||
1183 | } |
||
1184 | 28083 | jpiera | |
1185 | 27885 | jpiera | /**
|
1186 | * <p>Sets if the alphabetical sort will be ascending or descending.</p>
|
||
1187 | *
|
||
1188 | * @param b <code>true</code> if the alphabetical sort will be ascending, <code>false</code> if descending
|
||
1189 | */
|
||
1190 | public void setAscendingOrdering(boolean b) { |
||
1191 | ascendingOrdering = b; |
||
1192 | } |
||
1193 | 28083 | jpiera | |
1194 | 27885 | jpiera | /**
|
1195 | * <p>Determines if the alphabetical sort will be ascending or descending.</p>
|
||
1196 | *
|
||
1197 | * @param b <code>true</code> if the alphabetical sort will be ascending, <code>false</code> if descending
|
||
1198 | */
|
||
1199 | public boolean isAscendingOrdering() { |
||
1200 | return ascendingOrdering;
|
||
1201 | } |
||
1202 | } |
||
1203 | } |
||
1204 | } |