svn-gvsig-desktop / trunk / extensions / extTableImport / src / org / gvsig / tableImport / addgeominfo / gui / AddGeometricInfoPanel.java @ 37422
History | View | Annotate | Download (55.2 KB)
1 |
package org.gvsig.tableImport.addgeominfo.gui; |
---|---|
2 |
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government
|
4 |
*
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
6 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
21 |
* MA 02110-1301, USA.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
import java.awt.Color; |
26 |
import java.awt.Component; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.FlowLayout; |
29 |
import java.awt.Font; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.awt.event.ComponentAdapter; |
33 |
import java.awt.event.ComponentEvent; |
34 |
import java.awt.event.ItemEvent; |
35 |
import java.awt.event.ItemListener; |
36 |
import java.awt.event.MouseAdapter; |
37 |
import java.awt.event.MouseEvent; |
38 |
import java.util.ArrayList; |
39 |
import java.util.HashSet; |
40 |
|
41 |
import javax.swing.BorderFactory; |
42 |
import javax.swing.DefaultListModel; |
43 |
import javax.swing.Icon; |
44 |
import javax.swing.ImageIcon; |
45 |
import javax.swing.JButton; |
46 |
import javax.swing.JCheckBox; |
47 |
import javax.swing.JComponent; |
48 |
import javax.swing.JLabel; |
49 |
import javax.swing.JList; |
50 |
import javax.swing.JOptionPane; |
51 |
import javax.swing.JPanel; |
52 |
import javax.swing.JScrollPane; |
53 |
import javax.swing.JTree; |
54 |
import javax.swing.ListCellRenderer; |
55 |
import javax.swing.ListSelectionModel; |
56 |
import javax.swing.Spring; |
57 |
import javax.swing.SpringLayout; |
58 |
import javax.swing.UIManager; |
59 |
import javax.swing.event.ListDataEvent; |
60 |
import javax.swing.event.ListDataListener; |
61 |
import javax.swing.event.ListSelectionEvent; |
62 |
import javax.swing.event.ListSelectionListener; |
63 |
import javax.swing.tree.DefaultMutableTreeNode; |
64 |
import javax.swing.tree.TreePath; |
65 |
|
66 |
import org.apache.log4j.Logger; |
67 |
|
68 |
import org.gvsig.fmap.swing.toc.TOC; |
69 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
70 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.DefaultComboBoxConfigurableLookUpModel; |
71 |
import org.gvsig.gui.beans.comboboxconfigurablelookup.JComboBoxConfigurableLookUp; |
72 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
73 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
74 |
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP; |
75 |
import org.gvsig.gui.javax.swing.jLabelCellRenderer.JLabelCellRenderer; |
76 |
import org.gvsig.tableImport.addgeominfo.GeomInfo; |
77 |
import org.gvsig.tableImport.addgeominfo.GeomInfoFactory; |
78 |
import org.gvsig.tableImport.addgeominfo.process.AddGeometricInfoProcess; |
79 |
import org.gvsig.tableImport.addgeominfo.util.FShapeTypeNames; |
80 |
import org.gvsig.tableImport.addgeominfo.util.StringUtilitiesExtended; |
81 |
|
82 |
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException; |
83 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
84 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
85 |
import com.iver.andami.PluginServices; |
86 |
import com.iver.andami.messages.NotificationManager; |
87 |
import com.iver.andami.ui.mdiManager.IWindow; |
88 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
89 |
import com.iver.cit.gvsig.EditionUtilities; |
90 |
import com.iver.cit.gvsig.exceptions.visitors.StopWriterVisitorException; |
91 |
import com.iver.cit.gvsig.fmap.MapControl; |
92 |
import com.iver.cit.gvsig.fmap.core.FShape; |
93 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
94 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
95 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
96 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
97 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
98 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
99 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
100 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
101 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
102 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
103 |
import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
104 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
105 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
106 |
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch; |
107 |
import com.iver.utiles.swing.JComboBox; |
108 |
|
109 |
/**
|
110 |
* <p>Panel where user will select the geometric information of the layer, to be added.</p>
|
111 |
*
|
112 |
* @version 23/05/08
|
113 |
*
|
114 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
115 |
*/
|
116 |
public class AddGeometricInfoPanel extends JPanel implements IWindow { |
117 |
private static final long serialVersionUID = 3474731288674500621L; |
118 |
|
119 |
private View view; |
120 |
private MapControl mapControl;
|
121 |
private JLabel layersLabel = null; |
122 |
private JScrollPane southWestScrollPane = null; |
123 |
private JComboBox layersComboBox = null; |
124 |
private JPanel northPanel = null; |
125 |
private JPanel southPanel = null; |
126 |
private JPanel layersPanel = null; |
127 |
private JPanel southEastPanel = null; |
128 |
private JPanel southCenterPanel = null; |
129 |
private JPanel southEastCenterPanel = null; |
130 |
private JLabel isEditableLabel = null; |
131 |
private AdaptedAcceptCancelPanel acceptCancelPanel = null; |
132 |
private JScrollPane addedAttributesScrollPane = null; |
133 |
private JCheckBox newColumnCheckBox = null; |
134 |
private JTextFieldWithSCP nameOfColumnText = null; |
135 |
private JComboBoxConfigurableLookUp nameOfColumnCombo = null; |
136 |
private JList attributesList = null; |
137 |
private JList attributesAddedList = null; |
138 |
|
139 |
private ImageIcon bIcon; |
140 |
private ImageIcon rightIcon; |
141 |
private ImageIcon leftIcon; |
142 |
private ImageIcon doubleRightIcon; |
143 |
private ImageIcon doubleLeftIcon; |
144 |
private ImageIcon iconYes; |
145 |
private ImageIcon iconNo; |
146 |
private ImageIcon reloadIcon; |
147 |
private ImageIcon saveGPIcon; |
148 |
private JButton rightIconButton; |
149 |
private JButton leftIconButton; |
150 |
private JButton doubleRightIconButton; |
151 |
private JButton doubleLeftIconButton; |
152 |
private JButton reloadIconButton; |
153 |
private JButton saveGeomPropertyButton; |
154 |
private JComponent currentColumnNameComponent; |
155 |
|
156 |
private GeomInfo currentField;
|
157 |
|
158 |
private WindowInfo viewInfo = null; |
159 |
private final short Window_Width = 550; |
160 |
private final short Window_Height = 330; |
161 |
private final int layersComboBox_Width = 310; |
162 |
private final int layersComboBox_Height = 22; |
163 |
private HashSet fieldNames = new HashSet(); |
164 |
|
165 |
// Layer types:
|
166 |
private final short UNDEFINED = -1; |
167 |
// End Layer types
|
168 |
|
169 |
private int previous_Type = UNDEFINED; |
170 |
|
171 |
// Field name component type
|
172 |
// private final Class TEXT_TYPE = JTextFieldWithSCP.class;
|
173 |
// private final Class COMBO_TYPE = JComboBoxConfigurableLookUp.class;
|
174 |
// End field name component type
|
175 |
|
176 |
/**
|
177 |
* <p>Creates a new form where user could select the geometric information to add.</p>
|
178 |
*/
|
179 |
public AddGeometricInfoPanel(View view) { |
180 |
super();
|
181 |
|
182 |
this.view = view;
|
183 |
this.mapControl = view.getMapControl();
|
184 |
|
185 |
initialize(); |
186 |
} |
187 |
|
188 |
/**
|
189 |
* <p>Initializes this component.</p>
|
190 |
*/
|
191 |
private void initialize() { |
192 |
setLayout(new FlowLayout()); |
193 |
|
194 |
currentField = null;
|
195 |
|
196 |
bIcon = PluginServices.getIconTheme().get("layer-group");
|
197 |
|
198 |
add(getNorthPanel()); |
199 |
add(getSouthPanel()); |
200 |
add(getAdaptedAcceptCancelPanel()); |
201 |
|
202 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
203 |
|
204 |
setVisible(false);
|
205 |
if (!refreshVisibleVectorLayers()) {
|
206 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "No_vector_layer_can_be_save_changes"), PluginServices.getText(this, "Warning"), JOptionPane.WARNING_MESSAGE); |
207 |
} else {
|
208 |
setVisible(true);
|
209 |
PluginServices.getMDIManager().addWindow(this);
|
210 |
} |
211 |
} |
212 |
|
213 |
/**
|
214 |
* <p>This method initializes acceptCancelPanel.</p>
|
215 |
*
|
216 |
* @return an adapted {@link AcceptCancelPanel AcceptCancelPanel}
|
217 |
*/
|
218 |
private AdaptedAcceptCancelPanel getAdaptedAcceptCancelPanel() {
|
219 |
if (acceptCancelPanel == null) { |
220 |
acceptCancelPanel = new AdaptedAcceptCancelPanel();
|
221 |
} |
222 |
|
223 |
return acceptCancelPanel;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* <p>This method initializes northPanel.</p>
|
228 |
*
|
229 |
* @return javax.swing.JPanel
|
230 |
*/
|
231 |
private JPanel getNorthPanel() { |
232 |
if (northPanel == null) { |
233 |
northPanel = new JPanel(); |
234 |
northPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Select_layer"))); |
235 |
|
236 |
northPanel.setPreferredSize(new Dimension(540, 65)); |
237 |
northPanel.add(getLayersPanel()); |
238 |
northPanel.add(getIsEditableLabel()); |
239 |
} |
240 |
|
241 |
return northPanel;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* <p>This method initializes isEditableLabel.</p>
|
246 |
*
|
247 |
* @return javax.swing.JLabel
|
248 |
*/
|
249 |
private JLabel getIsEditableLabel() { |
250 |
if (isEditableLabel == null) { |
251 |
isEditableLabel = new JLabel(PluginServices.getText(this, "Writable")); |
252 |
isEditableLabel.setToolTipText(PluginServices.getText(this, "is_editable_TOOLTIP_HTML_explanation")); |
253 |
isEditableLabel.setPreferredSize(new Dimension(100, 28)); |
254 |
iconYes = PluginServices.getIconTheme().get("button-ok-icon");
|
255 |
iconNo = PluginServices.getIconTheme().get("button-cancel-icon");
|
256 |
} |
257 |
|
258 |
return isEditableLabel;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* <p>Updates the lists with the geometric properties of <code>layer</code>.</p>
|
263 |
*
|
264 |
* @param layer a vector layer
|
265 |
*/
|
266 |
private void updateEditableLabel(FLyrVect layer) { |
267 |
if (layer.isWritable()) {
|
268 |
// Only can save the changes if layer is writable and its driver is of a PostGree database,
|
269 |
// shape, or GML
|
270 |
VectorialDriver vd = layer.getSource().getDriver(); |
271 |
|
272 |
if (vd == null) |
273 |
return;
|
274 |
|
275 |
if ( vd.getName().equalsIgnoreCase("gvSIG shp driver") |
276 |
|| vd.getName().equalsIgnoreCase("PostGIS JDBC Driver")
|
277 |
|| vd.getName().equalsIgnoreCase("gvSIG GML Memory Driver")) {
|
278 |
isEditableLabel.setIcon(iconYes); |
279 |
refreshFields(layer); |
280 |
} |
281 |
else {
|
282 |
isEditableLabel.setIcon(iconYes); |
283 |
setEnabledFieldAttributeComponents(false);
|
284 |
|
285 |
DefaultListModel attrsListModel = (DefaultListModel) getAttributesList().getModel(); |
286 |
attrsListModel.removeAllElements(); |
287 |
|
288 |
DefaultListModel attrsAddedListModel = (DefaultListModel) getAttributesAddedList().getModel(); |
289 |
attrsAddedListModel.removeAllElements(); |
290 |
|
291 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "gvSIG_cant_save_changes_in_this_kind_of_format"), PluginServices.getText(this, "Information"), JOptionPane.INFORMATION_MESSAGE); |
292 |
} |
293 |
} |
294 |
else {
|
295 |
isEditableLabel.setIcon(iconNo); |
296 |
setEnabledFieldAttributeComponents(false);
|
297 |
|
298 |
DefaultListModel attrsListModel = (DefaultListModel) getAttributesList().getModel(); |
299 |
attrsListModel.removeAllElements(); |
300 |
|
301 |
DefaultListModel attrsAddedListModel = (DefaultListModel) getAttributesAddedList().getModel(); |
302 |
attrsAddedListModel.removeAllElements(); |
303 |
} |
304 |
} |
305 |
|
306 |
/**
|
307 |
* <p>This method initializes southPanel.</p>
|
308 |
*
|
309 |
* @return javax.swing.JPanel
|
310 |
*/
|
311 |
private JPanel getSouthPanel() { |
312 |
if (southPanel == null) { |
313 |
southPanel = new JPanel(); |
314 |
southPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "select_geometric_info"))); |
315 |
|
316 |
southPanel.setPreferredSize(new Dimension(540, 225)); |
317 |
southPanel.add(getSouthWestScrollPane());//getFieldNameLabel());
|
318 |
southPanel.add(getSouthCenterPanel()); |
319 |
southPanel.add(getSouthEastPanel()); |
320 |
} |
321 |
|
322 |
return southPanel;
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* <p>This method initializes southWestScrollPane.</p>
|
327 |
*
|
328 |
* @return javax.swing.JScrollPane
|
329 |
*/
|
330 |
private JScrollPane getSouthWestScrollPane() { |
331 |
if (southWestScrollPane == null) { |
332 |
southWestScrollPane = new JScrollPane(getAttributesList()); |
333 |
southWestScrollPane.setPreferredSize(new Dimension(214, 190)); |
334 |
} |
335 |
|
336 |
return southWestScrollPane;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* <p>This method initializes attributesList.</p>
|
341 |
*
|
342 |
* @return javax.swing.JList
|
343 |
*/
|
344 |
private JList getAttributesList() { |
345 |
if (attributesList == null) { |
346 |
attributesList = new JList(); |
347 |
attributesList.setToolTipText(PluginServices.getText(this, "select_geometric_properties_to_add_TOOLTIP_HTML_explanation")); |
348 |
attributesList.setModel(new DefaultListModel()); |
349 |
attributesList.setCellRenderer(new JLabelCellRenderer());
|
350 |
attributesList.setAlignmentX(JList.LEFT_ALIGNMENT);
|
351 |
attributesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
352 |
attributesList.addMouseListener(new MouseAdapter() { |
353 |
/*
|
354 |
* (non-Javadoc)
|
355 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
356 |
*/
|
357 |
public void mouseClicked(MouseEvent e) { |
358 |
if (e.getClickCount() == 2) { |
359 |
rightIconButton.doClick(); |
360 |
|
361 |
return;
|
362 |
} |
363 |
} |
364 |
}); |
365 |
} |
366 |
|
367 |
return attributesList;
|
368 |
} |
369 |
|
370 |
/**
|
371 |
* <p>This method initializes southCenterPanel.</p>
|
372 |
*
|
373 |
* @return javax.swing.JPanel
|
374 |
*/
|
375 |
private JPanel getSouthCenterPanel() { |
376 |
if (southCenterPanel == null) { |
377 |
southCenterPanel = new JPanel(); |
378 |
southCenterPanel.setLayout(new SpringLayout()); |
379 |
|
380 |
rightIcon = PluginServices.getIconTheme().get("right-arrow-icon");
|
381 |
leftIcon = PluginServices.getIconTheme().get("left-arrow-icon");
|
382 |
|
383 |
rightIconButton = new JButton(rightIcon); |
384 |
rightIconButton.setToolTipText(PluginServices.getText(this, "add_selected_button_TOOLTIP_HTML_explanation")); |
385 |
rightIconButton.setPreferredSize(new Dimension(40, 32)); |
386 |
rightIconButton.addActionListener(new ActionListener() { |
387 |
/*
|
388 |
* (non-Javadoc)
|
389 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
390 |
*/
|
391 |
public void actionPerformed(ActionEvent e) { |
392 |
Object[] values = getAttributesList().getSelectedValues(); |
393 |
|
394 |
DefaultListModel listModel = (DefaultListModel)getAttributesList().getModel(); |
395 |
int firstIndex = -1; |
396 |
|
397 |
if (values.length > 0) { |
398 |
firstIndex = listModel.indexOf(values[0]);
|
399 |
|
400 |
for (int i = 0; i < values.length; i++) { |
401 |
((DefaultListModel)getAttributesAddedList().getModel()).addElement(values[i]);
|
402 |
listModel.removeElement(values[i]); |
403 |
} |
404 |
} |
405 |
|
406 |
// Select another to improve the usability
|
407 |
if (listModel.size() > 0) { |
408 |
if (firstIndex >= listModel.size())
|
409 |
getAttributesList().setSelectedIndex(listModel.size() -1);
|
410 |
else {
|
411 |
getAttributesList().setSelectedIndex(firstIndex); |
412 |
} |
413 |
} |
414 |
} |
415 |
}); |
416 |
|
417 |
leftIconButton = new JButton(leftIcon); |
418 |
leftIconButton.setToolTipText(PluginServices.getText(this, "remove_selected_button_TOOLTIP_HTML_explanation")); |
419 |
leftIconButton.setPreferredSize(new Dimension(40, 32)); |
420 |
leftIconButton.addActionListener(new ActionListener() { |
421 |
/*
|
422 |
* (non-Javadoc)
|
423 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
424 |
*/
|
425 |
public void actionPerformed(ActionEvent e) { |
426 |
Object[] values = getAttributesAddedList().getSelectedValues(); |
427 |
|
428 |
DefaultListModel listModel = (DefaultListModel)getAttributesAddedList().getModel(); |
429 |
int firstIndex = -1; |
430 |
|
431 |
if (values.length > 0) { |
432 |
firstIndex = listModel.indexOf(values[0]);
|
433 |
|
434 |
for (int i = 0; i < values.length; i++) { |
435 |
((DefaultListModel)getAttributesList().getModel()).addElement(values[i]);
|
436 |
listModel.removeElement(values[i]); |
437 |
} |
438 |
} |
439 |
|
440 |
// Select another to improve the usability
|
441 |
if (listModel.size() > 0) { |
442 |
if (firstIndex >= listModel.size())
|
443 |
getAttributesAddedList().setSelectedIndex(listModel.size() -1);
|
444 |
else {
|
445 |
getAttributesAddedList().setSelectedIndex(firstIndex); |
446 |
} |
447 |
} |
448 |
else {
|
449 |
setEnabledFieldAttributeComponents(false);
|
450 |
} |
451 |
} |
452 |
}); |
453 |
|
454 |
doubleRightIcon = PluginServices.getIconTheme().get("double-right-arrow-icon");
|
455 |
doubleLeftIcon = PluginServices.getIconTheme().get("double-left-arrow-icon");
|
456 |
doubleRightIconButton = new JButton(doubleRightIcon); |
457 |
doubleRightIconButton.setToolTipText(PluginServices.getText(this, "add_all_button_TOOLTIP_HTML_explanation")); |
458 |
doubleRightIconButton.setPreferredSize(new Dimension(40, 32)); |
459 |
doubleRightIconButton.addActionListener(new ActionListener() { |
460 |
/*
|
461 |
* (non-Javadoc)
|
462 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
463 |
*/
|
464 |
public void actionPerformed(ActionEvent e) { |
465 |
Object[] values = ((DefaultListModel)getAttributesList().getModel()).toArray(); |
466 |
|
467 |
if (values.length > 0) { |
468 |
for (int i = 0; i < values.length; i++) { |
469 |
((DefaultListModel)getAttributesAddedList().getModel()).addElement(values[i]);
|
470 |
((DefaultListModel)getAttributesList().getModel()).removeElement(values[i]);
|
471 |
} |
472 |
} |
473 |
} |
474 |
}); |
475 |
|
476 |
doubleLeftIconButton = new JButton(doubleLeftIcon); |
477 |
doubleLeftIconButton.setToolTipText(PluginServices.getText(this, "remove_all_button_TOOLTIP_HTML_explanation")); |
478 |
doubleLeftIconButton.setPreferredSize(new Dimension(40, 32)); |
479 |
doubleLeftIconButton.addActionListener(new ActionListener() { |
480 |
/*
|
481 |
* (non-Javadoc)
|
482 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
483 |
*/
|
484 |
public void actionPerformed(ActionEvent e) { |
485 |
Object[] values = ((DefaultListModel)getAttributesAddedList().getModel()).toArray(); |
486 |
|
487 |
if (values.length > 0) { |
488 |
for (int i = 0; i < values.length; i++) { |
489 |
((DefaultListModel)getAttributesList().getModel()).addElement(values[i]);
|
490 |
((DefaultListModel)getAttributesAddedList().getModel()).removeElement(values[i]);
|
491 |
} |
492 |
} |
493 |
|
494 |
setEnabledFieldAttributeComponents(false);
|
495 |
} |
496 |
}); |
497 |
|
498 |
southCenterPanel.add(doubleRightIconButton); |
499 |
southCenterPanel.add(rightIconButton); |
500 |
southCenterPanel.add(leftIconButton); |
501 |
southCenterPanel.add(doubleLeftIconButton); |
502 |
southCenterPanel.add(getReloadIconButton()); |
503 |
doSpringLayoutOfSouthCenterPanel(); |
504 |
southCenterPanel.setPreferredSize(new Dimension(40, 190)); |
505 |
} |
506 |
|
507 |
return southCenterPanel;
|
508 |
} |
509 |
|
510 |
/**
|
511 |
* <p>This method initializes reloadIconButton.</p>
|
512 |
*
|
513 |
* @return javax.swing.JButton
|
514 |
*/
|
515 |
private JButton getReloadIconButton() { |
516 |
if (reloadIconButton == null) { |
517 |
reloadIcon = PluginServices.getIconTheme().get("reload-icon");
|
518 |
|
519 |
reloadIconButton = new JButton(reloadIcon); |
520 |
reloadIconButton.setToolTipText(PluginServices.getText(this, "reload_button_TOOLTIP_HTML_explanation")); |
521 |
reloadIconButton.setPreferredSize(new Dimension(40, 52)); |
522 |
reloadIconButton.addActionListener(new ActionListener() { |
523 |
/*
|
524 |
* (non-Javadoc)
|
525 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
526 |
*/
|
527 |
public void actionPerformed(ActionEvent e) { |
528 |
refreshVisibleVectorLayers(); |
529 |
|
530 |
if (getLayersComboBox().getItemCount() > 0) { |
531 |
FLayerWrapper fW = (FLayerWrapper)getLayersComboBox().getItemAt(0);
|
532 |
((DefaultListModel)getAttributesList().getModel()).removeAllElements();
|
533 |
((DefaultListModel)getAttributesAddedList().getModel()).removeAllElements();
|
534 |
|
535 |
if (fW != null) { |
536 |
updateEditableLabel(fW.getLayer()); |
537 |
} |
538 |
} |
539 |
|
540 |
getNewColumnCheckBox().setSelected(true);
|
541 |
currentColumnNameComponent = getNameOfColumnText(); |
542 |
getNameOfColumnText().setText("");
|
543 |
getNameOfColumnText().setEnabled(false);
|
544 |
getSouthEastPanel().add(currentColumnNameComponent); |
545 |
setEnabledFieldAttributeComponents(false);
|
546 |
getSouthEastPanel().updateUI(); |
547 |
} |
548 |
}); |
549 |
} |
550 |
|
551 |
return reloadIconButton;
|
552 |
} |
553 |
|
554 |
/**
|
555 |
* <p>Sets the GUI components to <code>b</code>.</p>
|
556 |
*
|
557 |
* @param b <code>true</code> to enable the GUI components, <code>false</code> to disable them
|
558 |
*/
|
559 |
private void setEnabledFieldAttributeComponents(boolean b) { |
560 |
getNewColumnCheckBox().setEnabled(b); |
561 |
getSaveGeomPropertyButton().setEnabled(b); |
562 |
|
563 |
if (b == false) { |
564 |
getSouthEastPanel().remove(currentColumnNameComponent); |
565 |
getNameOfColumnText().setText("");
|
566 |
currentColumnNameComponent = getNameOfColumnText(); |
567 |
getSouthEastPanel().add(currentColumnNameComponent); |
568 |
currentColumnNameComponent.setEnabled(b); |
569 |
getSouthEastPanel().updateUI(); |
570 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
571 |
} |
572 |
} |
573 |
|
574 |
/**
|
575 |
* <p>Creates the <code>Spring</code> layout of the south center panel.</p>
|
576 |
*/
|
577 |
private void doSpringLayoutOfSouthCenterPanel() { |
578 |
Component[] components = getSouthCenterPanel().getComponents(); |
579 |
SpringLayout layout = (SpringLayout)getSouthCenterPanel().getLayout(); |
580 |
Spring yPad = Spring.constant(2); |
581 |
Spring xSpring = Spring.constant(0); |
582 |
Spring ySpring = yPad;
|
583 |
|
584 |
// Make every component 5 pixels away from the component to its down.
|
585 |
for (int i = 0; i < components.length; i++) { |
586 |
SpringLayout.Constraints cons = layout.getConstraints(components[i]);
|
587 |
cons.setY(ySpring); |
588 |
ySpring = Spring.sum(yPad, cons.getConstraint("South")); |
589 |
|
590 |
cons.setX(xSpring); |
591 |
} |
592 |
} |
593 |
|
594 |
/**
|
595 |
* <p>This method initializes southEastPanel.</p>
|
596 |
*
|
597 |
* @return javax.swing.JPanel
|
598 |
*/
|
599 |
private JPanel getSouthEastPanel() { |
600 |
if (southEastPanel == null) { |
601 |
southEastPanel = new JPanel(); |
602 |
southEastPanel.setPreferredSize(new Dimension(215, 190)); |
603 |
southEastPanel.add(getAddedAttributesScrollPane()); |
604 |
southEastPanel.add(getSouthEastCenterPanel()); |
605 |
southEastPanel.add(getNameOfColumnText()); |
606 |
currentColumnNameComponent = getNameOfColumnText(); |
607 |
} |
608 |
|
609 |
return southEastPanel;
|
610 |
} |
611 |
|
612 |
/**
|
613 |
* <p>This method initializes southEastCenterPanel.</p>
|
614 |
*
|
615 |
* @return javax.swing.JPanel
|
616 |
*/
|
617 |
private JPanel getSouthEastCenterPanel() { |
618 |
if (southEastCenterPanel == null) { |
619 |
southEastCenterPanel = new JPanel(); |
620 |
southEastCenterPanel.setPreferredSize(new Dimension(215, 26)); |
621 |
|
622 |
southEastCenterPanel.add(getNewColumnCheckBox()); |
623 |
southEastCenterPanel.add(getSaveGeomPropertyButton()); |
624 |
} |
625 |
|
626 |
return southEastCenterPanel;
|
627 |
} |
628 |
|
629 |
/**
|
630 |
* <p>This method initializes saveGeomPropertyButton.</p>
|
631 |
*
|
632 |
* @return javax.swing.JButton
|
633 |
*/
|
634 |
private JButton getSaveGeomPropertyButton() { |
635 |
if (saveGeomPropertyButton == null) { |
636 |
saveGPIcon = PluginServices.getIconTheme().get("save-icon");
|
637 |
|
638 |
saveGeomPropertyButton = new JButton(saveGPIcon); |
639 |
saveGeomPropertyButton.setPreferredSize(new Dimension(20, 20)); |
640 |
saveGeomPropertyButton.setToolTipText(PluginServices.getText(this, "save_changes_TOOLTIP_HTML_explanation")); |
641 |
saveGeomPropertyButton.addActionListener(new ActionListener() { |
642 |
/*
|
643 |
* (non-Javadoc)
|
644 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
645 |
*/
|
646 |
public void actionPerformed(ActionEvent e) { |
647 |
updateAttributesToCurrentField(); |
648 |
} |
649 |
}); |
650 |
} |
651 |
|
652 |
return saveGeomPropertyButton;
|
653 |
} |
654 |
|
655 |
/**
|
656 |
* <p>This method initializes addedAttributesScrollPane.</p>
|
657 |
*
|
658 |
* @return javax.swing.JScrollPane
|
659 |
*/
|
660 |
private JScrollPane getAddedAttributesScrollPane() { |
661 |
if (addedAttributesScrollPane == null) { |
662 |
addedAttributesScrollPane = new JScrollPane(getAttributesAddedList()); |
663 |
addedAttributesScrollPane.setPreferredSize(new Dimension(214, 126)); |
664 |
} |
665 |
|
666 |
return addedAttributesScrollPane;
|
667 |
} |
668 |
|
669 |
/**
|
670 |
* <p>This method initializes attributesAddedList.</p>
|
671 |
*
|
672 |
* @return javax.swing.JList
|
673 |
*/
|
674 |
private JList getAttributesAddedList() { |
675 |
if (attributesAddedList == null) { |
676 |
attributesAddedList = new JList(); |
677 |
attributesAddedList.setToolTipText(PluginServices.getText(this, "select_how_add_each_geometric_property_TOOLTIP_HTML_explanation")); |
678 |
attributesAddedList.setModel(new DefaultListModel()); |
679 |
attributesAddedList.setCellRenderer(new JLabelCellRenderer());
|
680 |
attributesAddedList.setAlignmentX(JList.LEFT_ALIGNMENT);
|
681 |
DefaultListModel listModel = ((DefaultListModel)attributesAddedList.getModel()); |
682 |
final DefaultListModel f_listModel = listModel; |
683 |
|
684 |
listModel.addListDataListener(new ListDataListener() { |
685 |
/*
|
686 |
* (non-Javadoc)
|
687 |
* @see javax.swing.event.ListDataListener#contentsChanged(javax.swing.event.ListDataEvent)
|
688 |
*/
|
689 |
public void contentsChanged(ListDataEvent e) { |
690 |
} |
691 |
|
692 |
/*
|
693 |
* (non-Javadoc)
|
694 |
* @see javax.swing.event.ListDataListener#intervalAdded(javax.swing.event.ListDataEvent)
|
695 |
*/
|
696 |
public void intervalAdded(ListDataEvent e) { |
697 |
if (f_listModel.size() > 0) |
698 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(true);
|
699 |
} |
700 |
|
701 |
/*
|
702 |
* (non-Javadoc)
|
703 |
* @see javax.swing.event.ListDataListener#intervalRemoved(javax.swing.event.ListDataEvent)
|
704 |
*/
|
705 |
public void intervalRemoved(ListDataEvent e) { |
706 |
if (f_listModel.size() == 0) |
707 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
708 |
} |
709 |
}); |
710 |
|
711 |
attributesAddedList.addListSelectionListener(new ListSelectionListener() { |
712 |
/*
|
713 |
* (non-Javadoc)
|
714 |
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
|
715 |
*/
|
716 |
public void valueChanged(ListSelectionEvent e) { |
717 |
if (! e.getValueIsAdjusting()) {
|
718 |
Object[] values = attributesAddedList.getSelectedValues(); |
719 |
if (values.length == 1) { |
720 |
currentField = ((GeomInfo)values[0]);
|
721 |
setEnabledFieldAttributeComponents(true);
|
722 |
updateAttributesFromCurrentField(); |
723 |
} |
724 |
} |
725 |
} |
726 |
}); |
727 |
|
728 |
attributesAddedList.addMouseListener(new MouseAdapter() { |
729 |
/*
|
730 |
* (non-Javadoc)
|
731 |
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
|
732 |
*/
|
733 |
public void mouseClicked(MouseEvent e) { |
734 |
if (e.getClickCount() == 2) { |
735 |
leftIconButton.doClick(); |
736 |
|
737 |
return;
|
738 |
} |
739 |
} |
740 |
}); |
741 |
} |
742 |
|
743 |
return attributesAddedList;
|
744 |
} |
745 |
|
746 |
/**
|
747 |
* <p>This method initializes newColumnCheckBox.</p>
|
748 |
*
|
749 |
* @return javax.swing.JCheckBox
|
750 |
*/
|
751 |
private JCheckBox getNewColumnCheckBox() { |
752 |
if (newColumnCheckBox == null) { |
753 |
newColumnCheckBox = new JCheckBox(PluginServices.getText(this, "New_field")); |
754 |
newColumnCheckBox.setToolTipText(PluginServices.getText(this, "new_property_checkbox_TOOLTIP_HTML_explanation")); |
755 |
newColumnCheckBox.setPreferredSize(new Dimension(175, 22)); |
756 |
newColumnCheckBox.setEnabled(false);
|
757 |
newColumnCheckBox.setSelected(true);
|
758 |
newColumnCheckBox.addItemListener(new ItemListener() { |
759 |
public void itemStateChanged(ItemEvent e) { |
760 |
updateColumnNameFromField(); |
761 |
} |
762 |
}); |
763 |
} |
764 |
|
765 |
return newColumnCheckBox;
|
766 |
} |
767 |
|
768 |
/**
|
769 |
* <p>Updates the component that has the name of the field selected.</p>
|
770 |
*/
|
771 |
private void updateColumnNameFromField() { |
772 |
getSouthEastPanel().remove(currentColumnNameComponent); |
773 |
|
774 |
// Adds all the field names of the layer
|
775 |
if (getNewColumnCheckBox().isSelected()) {
|
776 |
currentColumnNameComponent = getNameOfColumnText(); |
777 |
currentColumnNameComponent.setEnabled(true);
|
778 |
|
779 |
if (currentField == null) { |
780 |
getNameOfColumnText().setText("");
|
781 |
} |
782 |
else {
|
783 |
getNameOfColumnText().setText(currentField.getName()); |
784 |
} |
785 |
} |
786 |
else {
|
787 |
currentColumnNameComponent = getNameOfColumnCombo(); |
788 |
|
789 |
try {
|
790 |
DefaultComboBoxConfigurableLookUpModel model = ((DefaultComboBoxConfigurableLookUpModel)((JComboBoxConfigurableLookUp)getNameOfColumnCombo()).getModel()); |
791 |
model.removeAllElements(); |
792 |
|
793 |
FLyrVect layer = ((FLyrVect)((FLayerWrapper)getLayersComboBox().getSelectedItem()).getLayer()); |
794 |
|
795 |
SelectableDataSource sds = layer.getRecordset(); |
796 |
|
797 |
for (int i = 0; i < sds.getFieldCount(); i ++) { |
798 |
model.addElement(sds.getFieldName(i)); |
799 |
} |
800 |
|
801 |
if (model.getSize() > 0) { |
802 |
if ((currentField.getName() == null) || (((DefaultComboBoxConfigurableLookUpModel)getNameOfColumnCombo().getModel()).getIndexOf(currentField.getName()) == -1)) |
803 |
getNameOfColumnCombo().setSelectedItem(model.getElementAt(0));
|
804 |
else {
|
805 |
getNameOfColumnCombo().setSelectedItem(currentField.getName()); |
806 |
} |
807 |
} |
808 |
} |
809 |
catch (Exception ex) { |
810 |
JOptionPane.showMessageDialog(null, PluginServices.getText(null, "Failed_loading_fields"), PluginServices.getText(null, "Error"), JOptionPane.ERROR_MESSAGE); |
811 |
} |
812 |
} |
813 |
|
814 |
getSouthEastPanel().add(currentColumnNameComponent); |
815 |
getSouthEastPanel().updateUI(); |
816 |
} |
817 |
|
818 |
/**
|
819 |
* <p>Updates the component that has the name of the field selected.</p>
|
820 |
*/
|
821 |
private void updateAttributesToCurrentField() { |
822 |
if (currentField != null) { |
823 |
currentField.setNewColumn(getNewColumnCheckBox().isSelected()); |
824 |
|
825 |
if (currentColumnNameComponent instanceof JTextFieldWithSCP) { |
826 |
String userName = applyReplaces(getNameOfColumnText().getText());
|
827 |
String newName = getNewFieldName(fieldNames, userName);
|
828 |
if (!newName.equals(userName)) {
|
829 |
JOptionPane.showMessageDialog(this, |
830 |
PluginServices.getText(this, "Field_already_exists__")+userName+"\n" |
831 |
+ PluginServices.getText(this, "New_field_name_proposed__"+newName+"\n") |
832 |
+ PluginServices.getText(this, "Uncheck_New_Field_Option_if_you_want_to_update_an_existing_field"), |
833 |
PluginServices.getText(this, "Warning_Field_exists"), |
834 |
JOptionPane.WARNING_MESSAGE);
|
835 |
getNameOfColumnText().setText(newName); |
836 |
} |
837 |
currentField.setName(newName); |
838 |
} |
839 |
else {
|
840 |
currentField.setName(applyReplaces(((String) getNameOfColumnCombo().getSelectedItem())));
|
841 |
} |
842 |
} |
843 |
} |
844 |
|
845 |
/**
|
846 |
* <p>Applies the different kinds of replacement defined in
|
847 |
* {@link StringUtilitiesExtension StringUtilitiesExtension} to <code>s</code>.</p>
|
848 |
*
|
849 |
* @param s text to be formatted
|
850 |
* @return t text formatted
|
851 |
*/
|
852 |
private String applyReplaces(String s) { |
853 |
return StringUtilitiesExtended.replaceAllAccents(
|
854 |
StringUtilitiesExtended.replaceAllCedilla( |
855 |
StringUtilitiesExtended.replaceAllNWithTilde(s))); |
856 |
} |
857 |
|
858 |
/**
|
859 |
* <p>Updates the current field properties with the configuration in the GUI.</p>
|
860 |
*/
|
861 |
private void updateAttributesFromCurrentField() { |
862 |
if (currentField != null) { |
863 |
getNewColumnCheckBox().setSelected(currentField.isNewColumn()); |
864 |
updateColumnNameFromField(); |
865 |
} |
866 |
} |
867 |
|
868 |
/**
|
869 |
* <p>This method initializes nameOfColumnText.</p>
|
870 |
*
|
871 |
* @return JTextFieldWithSCP
|
872 |
*/
|
873 |
private JTextFieldWithSCP getNameOfColumnText() {
|
874 |
if (nameOfColumnText == null) { |
875 |
nameOfColumnText = new JTextFieldWithSCP();
|
876 |
nameOfColumnText.setPreferredSize(new Dimension(215, 22)); |
877 |
nameOfColumnText.setToolTipText(PluginServices.getText(this, "name_of_the_new_property_TOOLTIP_HTML_explanation")); |
878 |
} |
879 |
|
880 |
return nameOfColumnText;
|
881 |
} |
882 |
|
883 |
/**
|
884 |
* <p>This method initializes nameOfColumnCombo.</p>
|
885 |
*
|
886 |
* @return JComboBoxConfigurableLookUp
|
887 |
*/
|
888 |
private JComboBoxConfigurableLookUp getNameOfColumnCombo() {
|
889 |
if (nameOfColumnCombo == null) { |
890 |
nameOfColumnCombo = new JComboBoxConfigurableLookUp();
|
891 |
DefaultComboBoxConfigurableLookUpModel model = ((DefaultComboBoxConfigurableLookUpModel)((JComboBoxConfigurableLookUp)nameOfColumnCombo).getModel()); |
892 |
model.setShowAllItemsInListBox(true);
|
893 |
nameOfColumnCombo.setPreferredSize(new Dimension(215, 22)); |
894 |
nameOfColumnCombo.setToolTipText(PluginServices.getText(this, "name_of_the_new_property_TOOLTIP_HTML_explanation")); |
895 |
} |
896 |
|
897 |
return nameOfColumnCombo;
|
898 |
} |
899 |
|
900 |
/**
|
901 |
* <p>This method initializes layersPanel.</p>
|
902 |
*
|
903 |
* @return javax.swing.JPanel
|
904 |
*/
|
905 |
private JPanel getLayersPanel() { |
906 |
if (layersPanel == null) { |
907 |
layersPanel = new JPanel(); |
908 |
layersPanel.setLayout(new FlowLayout()); |
909 |
layersPanel.setPreferredSize(new Dimension(380, 28)); |
910 |
layersPanel.add(getLayersLabel()); |
911 |
layersPanel.add(getLayersComboBox()); |
912 |
} |
913 |
|
914 |
return layersPanel;
|
915 |
} |
916 |
|
917 |
/**
|
918 |
* <p>This method initializes layersLabel.</p>
|
919 |
*
|
920 |
* @return javax.swing.JLabel
|
921 |
*/
|
922 |
private JLabel getLayersLabel() { |
923 |
if (layersLabel == null) { |
924 |
layersLabel = new JLabel(PluginServices.getText(this, "Layer")); |
925 |
layersLabel.setPreferredSize(new Dimension(40, 20)); |
926 |
layersLabel.setToolTipText(PluginServices.getText(this, "Layer")); |
927 |
} |
928 |
|
929 |
return layersLabel;
|
930 |
} |
931 |
|
932 |
/**
|
933 |
* <p>This method initializes layersComboBox.</p>
|
934 |
*
|
935 |
* @return javax.swing.JComboBox
|
936 |
*/
|
937 |
private JComboBox getLayersComboBox() { |
938 |
if (layersComboBox == null) { |
939 |
layersComboBox = new JComboBox(); |
940 |
layersComboBox.setPreferredSize(new Dimension(layersComboBox_Width, layersComboBox_Height)); |
941 |
layersComboBox.addItemListener(new ItemListener() { |
942 |
/*
|
943 |
* (non-Javadoc)
|
944 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
945 |
*/
|
946 |
public void itemStateChanged(ItemEvent e) { |
947 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
948 |
try {
|
949 |
FLayerWrapper fW = (FLayerWrapper)e.getItem(); |
950 |
|
951 |
if (fW != null) { |
952 |
FLayer layer = fW.getLayer(); |
953 |
|
954 |
if (layer != null) { |
955 |
layersComboBox.setToolTipText("<html>" + PluginServices.getText(this, "Layer") + ": " + layer.getName() + "<br>" + |
956 |
PluginServices.getText(this, "Type") + ": " + FShapeTypeNames.getFShapeTypeName(((FLyrVect)layer).getShapeType()) + "</html>"); |
957 |
|
958 |
updateEditableLabel((FLyrVect)layer); |
959 |
} |
960 |
} |
961 |
} catch (ReadDriverException dE) {
|
962 |
NotificationManager.showMessageError(PluginServices.getText(this, "problem_loading_layers"), dE); |
963 |
} |
964 |
} |
965 |
} |
966 |
}); |
967 |
} |
968 |
|
969 |
return layersComboBox;
|
970 |
} |
971 |
|
972 |
/**
|
973 |
* <p>Updates "layersComboBox" with the name of visible layers of the associated <code>MapControl</code> instance.</p>
|
974 |
*
|
975 |
* @see #refreshVisibleVectorLayers(FLayer, int)
|
976 |
*
|
977 |
* @return <code>true</code> if there is any layer added that can be written, otherwise <code>false</code>
|
978 |
*/
|
979 |
private boolean refreshVisibleVectorLayers() { |
980 |
FLayer rootNode = mapControl.getMapContext().getLayers(); |
981 |
|
982 |
getLayersComboBox().removeAllItems(); |
983 |
|
984 |
boolean b = refreshVisibleVectorLayers(rootNode, -1); |
985 |
|
986 |
// The selectedLayer will be, by default, the first being added.
|
987 |
if (getLayersComboBox().getItemCount() > 0) { |
988 |
getLayersComboBox().setRenderer(new LayersComboBoxCellRenderer());
|
989 |
getLayersComboBox().setSelectedIndex(0);
|
990 |
} |
991 |
|
992 |
// If there is only one layer -> disable the possibility of selection by the user
|
993 |
if (getLayersComboBox().getItemCount() <= 1) { |
994 |
getLayersComboBox().setEnabled(false);
|
995 |
} |
996 |
|
997 |
return b;
|
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* <p>Updates "layersComboBox" with the name of visible layers down <code>node</code>.</p>
|
1002 |
*
|
1003 |
* @param node parent node
|
1004 |
* @param level <code>node</code> level from the root
|
1005 |
*
|
1006 |
* @return <code>true</code> if some layer added can be edited, otherwise <code>false</code>
|
1007 |
*/
|
1008 |
private boolean refreshVisibleVectorLayers(FLayer node, int level) { |
1009 |
if (node instanceof FLayers) { |
1010 |
FLayers root = (FLayers)node; |
1011 |
boolean b = false; |
1012 |
|
1013 |
for (int i = root.getLayersCount() - 1; i >= 0 ; i--) { |
1014 |
if (root.getLayer(i).isVisible()) {
|
1015 |
b |= refreshVisibleVectorLayers(root.getLayer(i), level + 1);
|
1016 |
} |
1017 |
} |
1018 |
|
1019 |
return b;
|
1020 |
} |
1021 |
else {
|
1022 |
String layerName = node.getName();
|
1023 |
|
1024 |
if ((node.isVisible()) && (node instanceof FLyrVect) && (layerName != null)) { |
1025 |
getLayersComboBox().addItem(new FLayerWrapper((FLyrVect)node, level, bIcon, getLayerIcon(node)));
|
1026 |
|
1027 |
return node.isWritable();
|
1028 |
} |
1029 |
} |
1030 |
|
1031 |
return false; |
1032 |
} |
1033 |
|
1034 |
/**
|
1035 |
* <p>Returns the icon that represents the layer in the current active view's TOC.</p>
|
1036 |
*
|
1037 |
* @param layer the layer
|
1038 |
* @return the layer's icon in the current active view's TOC
|
1039 |
*/
|
1040 |
private Icon getLayerIcon(FLayer layer) { |
1041 |
if (layer.getTocImageIcon() != null) { |
1042 |
return layer.getTocImageIcon();
|
1043 |
} |
1044 |
else {
|
1045 |
TocItemBranch branch = new TocItemBranch(layer);
|
1046 |
|
1047 |
return branch.getIcon();
|
1048 |
} |
1049 |
} |
1050 |
|
1051 |
/**
|
1052 |
* <p>Updates attrsListModel with the geometric attributes according the shape type of the current selected layer.</p>
|
1053 |
*
|
1054 |
* @throws DriverException if fails working with the data driver
|
1055 |
*/
|
1056 |
private void refreshFields(FLyrVect seletedLayer) { |
1057 |
try {
|
1058 |
previous_Type = seletedLayer.getShapeType(); |
1059 |
|
1060 |
SelectableDataSource ds = seletedLayer.getSource().getRecordset(); |
1061 |
fieldNames = new HashSet(); |
1062 |
try {
|
1063 |
String[] fn = ds.getFieldNames(); |
1064 |
for (int i=0; i<fn.length; i++) { |
1065 |
fieldNames.add(fn[i]); |
1066 |
} |
1067 |
} catch (ReadDriverException e) {
|
1068 |
PluginServices.getLogger().error(e); |
1069 |
} |
1070 |
|
1071 |
setEnabledFieldAttributeComponents(false);
|
1072 |
|
1073 |
DefaultListModel attrsListModel = (DefaultListModel) getAttributesList().getModel(); |
1074 |
attrsListModel.removeAllElements(); |
1075 |
|
1076 |
DefaultListModel attrsAddedListModel = (DefaultListModel) getAttributesAddedList().getModel(); |
1077 |
attrsAddedListModel.removeAllElements(); |
1078 |
|
1079 |
GeomInfo geomInfo = null;
|
1080 |
|
1081 |
switch (previous_Type) {
|
1082 |
case FShape.NULL:
|
1083 |
break;
|
1084 |
case FShape.POINT:
|
1085 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "X_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "X")), FShape.POINT); |
1086 |
geomInfo.setGeomSubType(GeomInfo.X); |
1087 |
attrsListModel.addElement(geomInfo); |
1088 |
|
1089 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Y_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "Y")), FShape.POINT); |
1090 |
geomInfo.setGeomSubType(GeomInfo.Y); |
1091 |
attrsListModel.addElement(geomInfo); |
1092 |
|
1093 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Z_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "Z")), FShape.POINT); |
1094 |
geomInfo.setGeomSubType(GeomInfo.Z); |
1095 |
attrsListModel.addElement(geomInfo); |
1096 |
break;
|
1097 |
case FShape.LINE:
|
1098 |
attrsListModel.addElement(GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Length"), getNewFieldName(fieldNames, PluginServices.getText(this, "Length")), FShape.LINE)); |
1099 |
break;
|
1100 |
case FShape.POLYGON:
|
1101 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Area"), getNewFieldName(fieldNames, PluginServices.getText(this, "Area")), FShape.POLYGON); |
1102 |
geomInfo.setGeomSubType(GeomInfo.AREA); |
1103 |
attrsListModel.addElement(geomInfo); |
1104 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Perimeter"), getNewFieldName(fieldNames, PluginServices.getText(this, "Perimeter")), FShape.POLYGON); |
1105 |
geomInfo.setGeomSubType(GeomInfo.PERIMETER); |
1106 |
attrsListModel.addElement(geomInfo); |
1107 |
break;
|
1108 |
case FShape.TEXT:
|
1109 |
break;
|
1110 |
case FShape.MULTI: // Can have points, multipoints, lines and polygons |
1111 |
/* POINT */
|
1112 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "X_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "X")), FShape.POINT); |
1113 |
geomInfo.setGeomSubType(GeomInfo.X); |
1114 |
attrsListModel.addElement(geomInfo); |
1115 |
|
1116 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Y_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "Y")), FShape.POINT); |
1117 |
geomInfo.setGeomSubType(GeomInfo.Y); |
1118 |
attrsListModel.addElement(geomInfo); |
1119 |
|
1120 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Z_coordinate"), getNewFieldName(fieldNames, PluginServices.getText(this, "Z")), FShape.POINT); |
1121 |
geomInfo.setGeomSubType(GeomInfo.Z); |
1122 |
attrsListModel.addElement(geomInfo); |
1123 |
|
1124 |
/* LINE */
|
1125 |
attrsListModel.addElement(GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Length"), getNewFieldName(fieldNames, PluginServices.getText(this, "Length")), FShape.LINE)); |
1126 |
|
1127 |
/* POLYGON */
|
1128 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Area"), getNewFieldName(fieldNames, PluginServices.getText(this, "Area")), FShape.POLYGON); |
1129 |
geomInfo.setGeomSubType(GeomInfo.AREA); |
1130 |
attrsListModel.addElement(geomInfo); |
1131 |
|
1132 |
geomInfo = GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Perimeter"), getNewFieldName(fieldNames, PluginServices.getText(this, "Perimeter")), FShape.POLYGON); |
1133 |
geomInfo.setGeomSubType(GeomInfo.PERIMETER); |
1134 |
attrsListModel.addElement(geomInfo); |
1135 |
|
1136 |
/* MULTIPOINT */
|
1137 |
attrsListModel.addElement(GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Number_of_points"), getNewFieldName(fieldNames, PluginServices.getText(this, "N_points")), FShape.MULTIPOINT)); |
1138 |
break;
|
1139 |
case FShape.MULTIPOINT:
|
1140 |
attrsListModel.addElement(GeomInfoFactory.createGeomInfo(PluginServices.getText(this, "Number_of_points"), getNewFieldName(fieldNames, PluginServices.getText(this, "N_points")), FShape.MULTIPOINT)); |
1141 |
break;
|
1142 |
case FShape.CIRCLE:
|
1143 |
break;
|
1144 |
case FShape.ARC:
|
1145 |
break;
|
1146 |
case FShape.ELLIPSE:
|
1147 |
break;
|
1148 |
case FShape.Z:
|
1149 |
break;
|
1150 |
default : // UNDEFINED |
1151 |
} |
1152 |
|
1153 |
updateUI(); |
1154 |
} catch (ReadDriverException dE) {
|
1155 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Failed_loading_fields"), PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE); |
1156 |
} |
1157 |
} |
1158 |
|
1159 |
private String getNewFieldName(HashSet currentFieldNames, String proposedName) { |
1160 |
String newName = proposedName;
|
1161 |
int i=2; |
1162 |
while (currentFieldNames.contains(newName)) {
|
1163 |
newName = proposedName+i; |
1164 |
i++; |
1165 |
} |
1166 |
return newName;
|
1167 |
} |
1168 |
|
1169 |
/*
|
1170 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
1171 |
*/
|
1172 |
public WindowInfo getWindowInfo() {
|
1173 |
if (viewInfo == null) { |
1174 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
1175 |
viewInfo.setTitle(PluginServices.getText(this, "add_geometric_info")); |
1176 |
viewInfo.setWidth(Window_Width); |
1177 |
viewInfo.setHeight(Window_Height); |
1178 |
} |
1179 |
return viewInfo;
|
1180 |
} |
1181 |
|
1182 |
/**
|
1183 |
* <p>Adapts {@link AcceptCancelPanel AcceptCancelPanel} to be used as a component of the <code>AddGeometricInfoPanel</code> panel.</p>
|
1184 |
*
|
1185 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
1186 |
*/
|
1187 |
private class AdaptedAcceptCancelPanel extends AcceptCancelPanel { |
1188 |
private static final long serialVersionUID = -1630782817926954788L; |
1189 |
|
1190 |
/**
|
1191 |
* <p>Creates a new <code>AdaptedAcceptCancelPanel</code></p>
|
1192 |
*/
|
1193 |
public AdaptedAcceptCancelPanel () {
|
1194 |
super();
|
1195 |
|
1196 |
addOkButtonActionListener(getOKAction()); |
1197 |
addCancelButtonActionListener(getCancelAction()); |
1198 |
setPreferredSize(new Dimension(500, 28)); |
1199 |
} |
1200 |
|
1201 |
/**
|
1202 |
* <p>Create the action that will be executed when user pressed the <i>ok</i> button.</p>
|
1203 |
*
|
1204 |
* @return action that will be executed when user pressed the <i>cancel</i> button
|
1205 |
*/
|
1206 |
private ActionListener getOKAction() { |
1207 |
// OK button action
|
1208 |
return new ActionListener() { |
1209 |
/*
|
1210 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
1211 |
*/
|
1212 |
public void actionPerformed(ActionEvent e) { |
1213 |
closeThis(); |
1214 |
|
1215 |
/* 1- Initial tasks */
|
1216 |
/* 1.1- If layer is in edition, saves it and ends the edition */
|
1217 |
FLyrVect layer = ((FLayerWrapper)getLayersComboBox().getSelectedItem()).getLayer(); |
1218 |
final boolean wasBeingEdited = layer.isEditing(); |
1219 |
|
1220 |
if (wasBeingEdited) {
|
1221 |
try {
|
1222 |
saveLayer(layer); |
1223 |
} |
1224 |
catch (Exception ex) { |
1225 |
NotificationManager.showMessageError(PluginServices.getText(this, "Failed_saving_the_layer"), ex); |
1226 |
PluginServices.getMainFrame().enableControls(); |
1227 |
return;
|
1228 |
} |
1229 |
} |
1230 |
|
1231 |
/* 1.2- Stores the active layers */
|
1232 |
final FLayer[] activeLayers = getActiveLayers(view.getTOC()); |
1233 |
|
1234 |
/* 2- Creates the process */
|
1235 |
AddGeometricInfoProcess iprocess = new AddGeometricInfoProcess(PluginServices.getText(this, "Add_geometric_information_to_layer_process"), PluginServices.getText(this, "Ongoing_process_please_wait"), view, layer, ((DefaultListModel)getAttributesAddedList().getModel()).toArray()); |
1236 |
|
1237 |
IncrementableTask iTask = new IncrementableTask(iprocess, new ProgressPanel(false)); |
1238 |
iTask.addIncrementableListener(iprocess); |
1239 |
iprocess.setIncrementableTask(iTask); |
1240 |
final AddGeometricInfoProcess f_iprocess = iprocess;
|
1241 |
final IncrementableTask f_iTask = iTask;
|
1242 |
|
1243 |
iTask.getProgressPanel().addComponentListener(new ComponentAdapter() { |
1244 |
/*
|
1245 |
* (non-Javadoc)
|
1246 |
* @see java.awt.event.ComponentAdapter#componentHidden(java.awt.event.ComponentEvent)
|
1247 |
*/
|
1248 |
public void componentHidden(ComponentEvent e) { |
1249 |
PluginServices.getMainFrame().enableControls(); |
1250 |
f_iTask.getProgressPanel().dispose(); |
1251 |
|
1252 |
/* 7- Refreshes all the associated project tables */
|
1253 |
ProjectTable pt = f_iprocess.getLayerProjectTable(); |
1254 |
if (pt != null) { |
1255 |
com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
1256 |
|
1257 |
for (int i = 0 ; i<views.length ; i++) { |
1258 |
if (views[i] instanceof Table) { |
1259 |
Table table = (Table)views[i]; |
1260 |
ProjectTable model = table.getModel(); |
1261 |
if (model.equals(pt)) {
|
1262 |
table.setModel(pt); |
1263 |
table.setVisible(false);
|
1264 |
|
1265 |
if ((wasBeingEdited) && (f_iprocess.getVea() != null)) |
1266 |
f_iprocess.getVea().getCommandRecord().addCommandListener(table); |
1267 |
|
1268 |
table.setVisible(true);
|
1269 |
} |
1270 |
} |
1271 |
} |
1272 |
} |
1273 |
|
1274 |
/* 8- Restores the active layers */
|
1275 |
restoreActiveLayers(view.getTOC(), activeLayers); |
1276 |
|
1277 |
/* 9- Writes in the gvSIG log the results of the process */
|
1278 |
String text = "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" + |
1279 |
PluginServices.getText(this, "Summary_of_the_process_of_adding_geometric_information") + ":\n" + |
1280 |
f_iprocess.getLog() + |
1281 |
"\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
|
1282 |
Logger.getLogger(getClass().getName()).debug(text);
|
1283 |
|
1284 |
/* 10- If the process has been canceled -> refreshes the view */
|
1285 |
if (f_iprocess.getPercent() < 100) |
1286 |
mapControl.drawMap(false);
|
1287 |
|
1288 |
/* 11- Refreshes the toolbars and their controls */
|
1289 |
PluginServices.getMainFrame().enableControls(); |
1290 |
} |
1291 |
}); |
1292 |
|
1293 |
/* Starts the process */
|
1294 |
iprocess.start(); |
1295 |
iTask.start(); |
1296 |
} |
1297 |
}; |
1298 |
} |
1299 |
|
1300 |
/**
|
1301 |
* <p>Saves and stops the edition of a vector layer.</p>
|
1302 |
*
|
1303 |
* @param layer the vector layer to save
|
1304 |
*
|
1305 |
* @throws DriverException if fails the driver associated to the layer
|
1306 |
* @throws ReadDriverException
|
1307 |
* @throws InitializeWriterException
|
1308 |
* @throws StopWriterVisitorException
|
1309 |
* @throws EditionException if fails a edition process with the layer
|
1310 |
*/
|
1311 |
private void saveLayer(FLyrVect layer) throws DriverException, ReadDriverException, InitializeWriterException, StopWriterVisitorException { |
1312 |
layer.setProperty("stoppingEditing", new Boolean(true)); |
1313 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer.getSource(); |
1314 |
|
1315 |
ISpatialWriter writer = (ISpatialWriter) vea.getWriter(); |
1316 |
com.iver.andami.ui.mdiManager.IWindow[] views = PluginServices.getMDIManager().getAllWindows();
|
1317 |
for (int j = 0; j < views.length; j++) { |
1318 |
if (views[j] instanceof Table) { |
1319 |
Table table = (Table) views[j]; |
1320 |
if (table.getModel().getAssociatedTable() != null |
1321 |
&& table.getModel().getAssociatedTable().equals(layer)) { |
1322 |
table.stopEditingCell(); |
1323 |
} |
1324 |
} |
1325 |
} |
1326 |
vea.cleanSelectableDatasource(); |
1327 |
layer.setRecordset(vea.getRecordset()); |
1328 |
|
1329 |
// Queremos que el recordset del layer
|
1330 |
// refleje los cambios en los campos.
|
1331 |
ILayerDefinition lyrDef = EditionUtilities.createLayerDefinition(layer); |
1332 |
String aux = "FIELDS:"; |
1333 |
FieldDescription[] flds = lyrDef.getFieldsDesc();
|
1334 |
for (int i=0; i < flds.length; i++) { |
1335 |
aux = aux + ", " + flds[i].getFieldAlias();
|
1336 |
} |
1337 |
|
1338 |
System.err.println("Escribiendo la capa " + lyrDef.getName() + " con los campos " + aux); |
1339 |
lyrDef.setShapeType(layer.getShapeType()); |
1340 |
writer.initialize(lyrDef); |
1341 |
vea.stopEdition(writer, EditionEvent.GRAPHIC); |
1342 |
layer.setProperty("stoppingEditing", new Boolean(false)); |
1343 |
} |
1344 |
|
1345 |
|
1346 |
/**
|
1347 |
* <p>Create the action that will be executed when user pressed the <i>cancel</i> button.</p>
|
1348 |
*
|
1349 |
* @return action that will be executed when user pressed the <i>cancel</i> button
|
1350 |
*/
|
1351 |
private ActionListener getCancelAction() { |
1352 |
// Cancel button action
|
1353 |
return new ActionListener() { |
1354 |
/*
|
1355 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
1356 |
*/
|
1357 |
public void actionPerformed(ActionEvent e) { |
1358 |
closeThis(); |
1359 |
} |
1360 |
}; |
1361 |
} |
1362 |
} |
1363 |
|
1364 |
/**
|
1365 |
* <p>Wrappers a <code>FLayer</code> overwriting the method <code>toString()</code> in order to would
|
1366 |
* return the name of the layer.</code>
|
1367 |
*
|
1368 |
* <p>Also displays icons and label</p>
|
1369 |
*
|
1370 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
1371 |
*/
|
1372 |
private class FLayerWrapper extends JPanel { |
1373 |
private static final long serialVersionUID = -160586150559061104L; |
1374 |
|
1375 |
private FLyrVect layer;
|
1376 |
private int level; |
1377 |
ImageIcon branchIcon;
|
1378 |
|
1379 |
/**
|
1380 |
* <p>Creates a new <code>FLayerWrapper</code>.</p>
|
1381 |
*
|
1382 |
* @param layer the vector layer to be wrappered
|
1383 |
* @param level the level in the tree of the layer wrappered
|
1384 |
* @param branchIcon icon that represents the branch
|
1385 |
* @param leafIcon icon that represents the leaf
|
1386 |
*/
|
1387 |
public FLayerWrapper(FLyrVect layer, int level, ImageIcon branchIcon, Icon leafIcon) { |
1388 |
super();
|
1389 |
|
1390 |
this.layer = layer;
|
1391 |
this.level = level;
|
1392 |
this.branchIcon = branchIcon;
|
1393 |
|
1394 |
setLayout(new SpringLayout()); |
1395 |
|
1396 |
if ((level > 0) && (branchIcon != null)) { |
1397 |
for (int i = 0; i < level; i++) { |
1398 |
add(new JLabel(branchIcon)); |
1399 |
} |
1400 |
} |
1401 |
|
1402 |
JLabel layerLabel;
|
1403 |
|
1404 |
if (layer.getName() != null) |
1405 |
layerLabel = new JLabel(layer.getName()); |
1406 |
else
|
1407 |
layerLabel = new JLabel(""); |
1408 |
|
1409 |
if (leafIcon != null) |
1410 |
layerLabel.setIcon(leafIcon); |
1411 |
|
1412 |
layerLabel.setFont(new Font("Helvetica", Font.BOLD, 12)); |
1413 |
|
1414 |
add(layerLabel); |
1415 |
|
1416 |
if (layer instanceof FLyrVect) { |
1417 |
JLabel layerTypeLabel;
|
1418 |
try {
|
1419 |
layerTypeLabel = new JLabel(PluginServices.getText(null, "Type") + ": " + FShapeTypeNames.getFShapeTypeName(((FLyrVect) layer).getShapeType())); |
1420 |
} catch (ReadDriverException e) {
|
1421 |
layerTypeLabel = new JLabel(PluginServices.getText(null, "Type") + ": " + PluginServices.getText("", "UNKNOWN")); |
1422 |
NotificationManager.showMessageError(PluginServices.getText(null, "Unknown_layer_shape_type") + " : " + layer.getName(), e); |
1423 |
} |
1424 |
|
1425 |
layerTypeLabel.setFont(new Font("Helvetica", Font.ITALIC, 12)); |
1426 |
|
1427 |
add(layerTypeLabel); |
1428 |
} |
1429 |
|
1430 |
doSpringLayout(); |
1431 |
setPreferredSize(new Dimension(340, 16)); |
1432 |
} |
1433 |
|
1434 |
/**
|
1435 |
* <p>Creates the <code>Spring</code> layout of this component.</p>
|
1436 |
*/
|
1437 |
private void doSpringLayout() { |
1438 |
Component[] components = getComponents(); |
1439 |
SpringLayout layout = (SpringLayout)getLayout(); |
1440 |
Spring xPad = Spring.constant(5); |
1441 |
Spring ySpring = Spring.constant(0); |
1442 |
Spring xSpring = xPad;
|
1443 |
|
1444 |
// Make every component 5 pixels away from the component to its left.
|
1445 |
for (int i = 0; i < components.length; i++) { |
1446 |
SpringLayout.Constraints cons = layout.getConstraints(components[i]);
|
1447 |
cons.setX(xSpring); |
1448 |
xSpring = Spring.sum(xPad, cons.getConstraint("East")); |
1449 |
|
1450 |
cons.setY(ySpring); |
1451 |
} |
1452 |
} |
1453 |
|
1454 |
/**
|
1455 |
* <p>Gets the layer wrappered.</p>
|
1456 |
*
|
1457 |
* @return the layer wrappered
|
1458 |
*/
|
1459 |
public FLyrVect getLayer() {
|
1460 |
return layer;
|
1461 |
} |
1462 |
|
1463 |
/**
|
1464 |
* <p>Gets the level in the tree of the layer wrappered.</p>
|
1465 |
*
|
1466 |
* @return the level in the tree of the layer wrappered
|
1467 |
*/
|
1468 |
public int getLevel() { |
1469 |
return level;
|
1470 |
} |
1471 |
|
1472 |
/*
|
1473 |
* (non-Javadoc)
|
1474 |
* @see javax.swing.JComponent#setForeground(java.awt.Color)
|
1475 |
*/
|
1476 |
public void setForeground(Color fg) { |
1477 |
super.setForeground(fg);
|
1478 |
} |
1479 |
|
1480 |
/*
|
1481 |
* (non-Javadoc)
|
1482 |
* @see javax.swing.JComponent#setBackground(java.awt.Color)
|
1483 |
*/
|
1484 |
public void setBackground(Color bg) { |
1485 |
super.setBackground(bg);
|
1486 |
} |
1487 |
|
1488 |
/*
|
1489 |
* (non-Javadoc)
|
1490 |
* @see java.lang.Object#toString()
|
1491 |
*/
|
1492 |
public String toString() { |
1493 |
return layer.getName();
|
1494 |
} |
1495 |
} |
1496 |
|
1497 |
/**
|
1498 |
* <p>Cell renderer of the combo box with information of the visible vector layers in the current active view.</p>
|
1499 |
*
|
1500 |
* @see ListCellRenderer
|
1501 |
*
|
1502 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
1503 |
*/
|
1504 |
private class LayersComboBoxCellRenderer implements ListCellRenderer { |
1505 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
1506 |
FLayerWrapper renderer = (FLayerWrapper)value; |
1507 |
|
1508 |
if (isSelected) {
|
1509 |
renderer.setForeground(UIManager.getColor( "ComboBox.selectionForeground" )); |
1510 |
renderer.setBackground(UIManager.getColor( "ComboBox.selectionBackground" )); |
1511 |
} |
1512 |
else
|
1513 |
renderer.setBackground(Color.WHITE);
|
1514 |
|
1515 |
return renderer;
|
1516 |
} |
1517 |
} |
1518 |
|
1519 |
/**
|
1520 |
* <p>Closes this window.</p>
|
1521 |
*/
|
1522 |
private void closeThis() { |
1523 |
PluginServices.getMDIManager().closeWindow(this);
|
1524 |
} |
1525 |
|
1526 |
/**
|
1527 |
* <p>Gets a list with the indexes of the active layers in the tree.</p>
|
1528 |
*
|
1529 |
* @param tree the {@link TOC TOC} tree with teh active layers
|
1530 |
*
|
1531 |
* @return indexes of the active layers
|
1532 |
*/
|
1533 |
private ArrayList getActiveLayerIndexes(JTree tree) { |
1534 |
TreePath tPath;
|
1535 |
Object node;
|
1536 |
Object userObject;
|
1537 |
ArrayList rows = new ArrayList(); |
1538 |
|
1539 |
try {
|
1540 |
for (int row = 0; row < tree.getRowCount(); row++) { |
1541 |
tPath = tree.getPathForRow(row); |
1542 |
node = tPath.getLastPathComponent(); |
1543 |
|
1544 |
if (node instanceof DefaultMutableTreeNode) { |
1545 |
userObject = ((DefaultMutableTreeNode)node).getUserObject();
|
1546 |
|
1547 |
if (userObject instanceof TocItemBranch) { |
1548 |
FLayer layer = ((TocItemBranch)userObject).getLayer(); |
1549 |
|
1550 |
if (layer.isActive())
|
1551 |
rows.add(new Integer(row)); |
1552 |
} |
1553 |
} |
1554 |
} |
1555 |
} |
1556 |
catch (Exception e) { |
1557 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Failed_saving_active_layer_indexes"), PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE); |
1558 |
} |
1559 |
return rows;
|
1560 |
} |
1561 |
|
1562 |
/**
|
1563 |
* <p>Restores all active layers.</p>
|
1564 |
*
|
1565 |
* @param tree view's TOC's tree
|
1566 |
* @param rows the rows to restore
|
1567 |
*/
|
1568 |
private void restoreActiveLayers(JTree tree, ArrayList rows) { |
1569 |
TreePath tPath;
|
1570 |
Object node;
|
1571 |
Object userObject;
|
1572 |
int row;
|
1573 |
FLayer layer; |
1574 |
|
1575 |
try {
|
1576 |
if ((tree == null) || (rows == null)) |
1577 |
return;
|
1578 |
|
1579 |
// First sets all not active
|
1580 |
for (row = 0; row < tree.getRowCount(); row ++) { |
1581 |
tPath = tree.getPathForRow(row); |
1582 |
node = tPath.getLastPathComponent(); |
1583 |
|
1584 |
if (node instanceof DefaultMutableTreeNode) { |
1585 |
userObject = ((DefaultMutableTreeNode)node).getUserObject();
|
1586 |
|
1587 |
if (userObject instanceof TocItemBranch) { |
1588 |
layer = ((TocItemBranch)userObject).getLayer(); |
1589 |
|
1590 |
layer.setActive(false);
|
1591 |
} |
1592 |
} |
1593 |
} |
1594 |
|
1595 |
// Second set active only the required layers
|
1596 |
for (int i = 0; i < rows.size(); i ++) { |
1597 |
row = ((Integer)rows.get(i)).intValue();
|
1598 |
|
1599 |
tPath = tree.getPathForRow(row); |
1600 |
node = tPath.getLastPathComponent(); |
1601 |
|
1602 |
if (node instanceof DefaultMutableTreeNode) { |
1603 |
userObject = ((DefaultMutableTreeNode)node).getUserObject();
|
1604 |
|
1605 |
if (userObject instanceof TocItemBranch) { |
1606 |
layer = ((TocItemBranch)userObject).getLayer(); |
1607 |
|
1608 |
layer.setActive(true);
|
1609 |
} |
1610 |
} |
1611 |
} |
1612 |
} |
1613 |
catch (Exception e) { |
1614 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "Failed_restoring_active_layers"), PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE); |
1615 |
} |
1616 |
} |
1617 |
|
1618 |
public Object getWindowProfile() { |
1619 |
return WindowInfo.DIALOG_PROFILE;
|
1620 |
} |
1621 |
|
1622 |
|
1623 |
private FLayer[] getActiveLayers(TOC toc) { |
1624 |
return toc.getSelectedLayers();
|
1625 |
} |
1626 |
|
1627 |
|
1628 |
private void restoreActiveLayers(TOC toc, FLayer[] ll) { |
1629 |
|
1630 |
int len = ll.length;
|
1631 |
toc.clearSelection(); |
1632 |
for (int i=0; i<len; i++) { |
1633 |
toc.selectLayer(ll[i]); |
1634 |
} |
1635 |
} |
1636 |
} |