root / trunk / extensions / extDerivedGeometries / src / es / iver / derivedGeom / gui / LayerAndProcessSelectionPanel.java @ 27865
History | View | Annotate | Download (32.4 KB)
1 |
package es.iver.derivedGeom.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.ItemEvent; |
33 |
import java.awt.event.ItemListener; |
34 |
import java.awt.event.KeyAdapter; |
35 |
import java.awt.event.KeyEvent; |
36 |
import java.io.File; |
37 |
|
38 |
import javax.swing.AbstractAction; |
39 |
import javax.swing.BorderFactory; |
40 |
import javax.swing.Icon; |
41 |
import javax.swing.ImageIcon; |
42 |
import javax.swing.JButton; |
43 |
import javax.swing.JComboBox; |
44 |
import javax.swing.JFileChooser; |
45 |
import javax.swing.JLabel; |
46 |
import javax.swing.JList; |
47 |
import javax.swing.JOptionPane; |
48 |
import javax.swing.JPanel; |
49 |
import javax.swing.ListCellRenderer; |
50 |
import javax.swing.Spring; |
51 |
import javax.swing.SpringLayout; |
52 |
import javax.swing.UIManager; |
53 |
import javax.swing.filechooser.FileFilter; |
54 |
|
55 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
56 |
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP; |
57 |
import org.gvsig.quickInfo.gui.QuickInfoDataSelectionPanel; |
58 |
import org.gvsig.quickInfo.utils.FShapeTypeNames; |
59 |
|
60 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
61 |
import com.iver.andami.PluginServices; |
62 |
import com.iver.andami.messages.NotificationManager; |
63 |
import com.iver.andami.ui.mdiManager.IWindow; |
64 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
65 |
import com.iver.cit.gvsig.fmap.core.FShape; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
67 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
68 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
69 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
70 |
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch; |
71 |
import com.iver.utiles.SimpleFileFilter; |
72 |
|
73 |
import es.iver.derivedGeom.process.DerivedGeometryProcessParameters; |
74 |
|
75 |
/**
|
76 |
*
|
77 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
78 |
*/
|
79 |
public class LayerAndProcessSelectionPanel extends JPanel implements IWindow { |
80 |
private WindowInfo viewInfo = null; |
81 |
private View view = null; |
82 |
private ImageIcon bIcon = null; |
83 |
private JLabel layersLabel = null; |
84 |
private JLabel labelName = null; |
85 |
private JLabel labelPath = null; |
86 |
private JLabel destProcessLabel = null; |
87 |
private JLabel destShapeTypeLabel = null; |
88 |
private JPanel northPanel = null; |
89 |
private JPanel destProcessPanel = null; |
90 |
private JPanel optionsPanel = null; |
91 |
private JPanel layersPanel = null; |
92 |
private JPanel destLayerNamePanel = null; |
93 |
private JPanel destPathPanel = null; |
94 |
private JPanel destLayerTypePanel = null; |
95 |
private JComboBox layersComboBox = null; |
96 |
private JTextFieldWithSCP destLayerName = null; |
97 |
private JComboBox destProcessCombo = null; |
98 |
private JTextFieldWithSCP destLayerPath = null; |
99 |
private JComboBox destShapeTypeCombo = null; |
100 |
private JButton jButtonSelectPath = null; |
101 |
private final int layersComboBox_Width = 390; |
102 |
private final int layersComboBox_Height = 22; |
103 |
private final short Window_Width = 480; |
104 |
private final short Window_Height = 280; |
105 |
private AdaptedAcceptCancelPanel acceptCancelPanel = null; |
106 |
private DerivedGeometryProcessParameters parameters = null; |
107 |
private final String SHAPE_EXTENSION = "shp"; |
108 |
private ProcessType pointsToLine, pointsToPolygon, closeMultiLine, pointsToLineOrPolygon;
|
109 |
private OutputSHPType line, polygon, multi;
|
110 |
private boolean started = false; |
111 |
|
112 |
|
113 |
public LayerAndProcessSelectionPanel(View view) { |
114 |
this.view = view;
|
115 |
|
116 |
initialize(); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* <p>
|
121 |
* Initializes this component.
|
122 |
* </p>
|
123 |
*/
|
124 |
private void initialize() { |
125 |
bIcon = PluginServices.getIconTheme().get("layerGroup");
|
126 |
parameters = new DerivedGeometryProcessParameters(null, null, null, null, DerivedGeometryProcessParameters.UNDEFINED_TYPE, view, DerivedGeometryProcessParameters.UNDEFINED_TYPE); |
127 |
|
128 |
pointsToLine = new ProcessType(DerivedGeometryProcessParameters.POINTS_TO_LINE_PROCESS_NAME, DerivedGeometryProcessParameters.POINTS_TO_LINE_PROCESS_ID);
|
129 |
pointsToPolygon = new ProcessType(DerivedGeometryProcessParameters.POINTS_TO_POLYGON_PROCESS_NAME, DerivedGeometryProcessParameters.POINTS_TO_POLYGON_PROCESS_ID);
|
130 |
closeMultiLine = new ProcessType(DerivedGeometryProcessParameters.CLOSE_MULTILINE_PROCESS_NAME, DerivedGeometryProcessParameters.CLOSE_MULTILINE_PROCESS_ID);
|
131 |
pointsToLineOrPolygon = new ProcessType(DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_NAME, DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_ID);
|
132 |
|
133 |
line = new OutputSHPType(PluginServices.getText(null, "Lines"), FShape.LINE); |
134 |
polygon = new OutputSHPType(PluginServices.getText(null, "Polygons"), FShape.POLYGON); |
135 |
multi = new OutputSHPType(PluginServices.getText(null, "Multi"), FShape.MULTI); |
136 |
|
137 |
setLayout(new FlowLayout()); |
138 |
add(getNorthPanel()); |
139 |
add(getDestProcessPanel()); |
140 |
add(getOptionsPanel()); |
141 |
add(getAdaptedAcceptCancelPanel()); |
142 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
143 |
|
144 |
refreshVisibleVectorLayers(); |
145 |
|
146 |
setVisible(false);
|
147 |
|
148 |
if (! refreshVisibleVectorLayers()) {
|
149 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "No_vector_layer_can_be_save_changes"), PluginServices.getText(this, "Warning"), JOptionPane.WARNING_MESSAGE); |
150 |
} else {
|
151 |
setVisible(true);
|
152 |
started = true;
|
153 |
PluginServices.getMDIManager().addWindow(this);
|
154 |
} |
155 |
} |
156 |
|
157 |
/**
|
158 |
* <p>This method initializes northPanel.</p>
|
159 |
*
|
160 |
* @return javax.swing.JPanel
|
161 |
*/
|
162 |
private JPanel getNorthPanel() { |
163 |
if (northPanel == null) { |
164 |
northPanel = new JPanel(); |
165 |
northPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Source_layer"))); |
166 |
northPanel.setLayout(new FlowLayout()); |
167 |
northPanel.setPreferredSize(new Dimension(470, 70)); |
168 |
northPanel.add(getLayersPanel()); |
169 |
} |
170 |
|
171 |
return northPanel;
|
172 |
} |
173 |
|
174 |
private JPanel getDestProcessPanel() { |
175 |
if (destProcessPanel == null) { |
176 |
destProcessPanel = new JPanel(); |
177 |
destProcessPanel.setLayout(new FlowLayout()); |
178 |
destProcessPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Output_layer"))); |
179 |
destProcessPanel.setPreferredSize(new Dimension(470, 136)); |
180 |
destProcessPanel.add(getDestLayerNamePanel()); |
181 |
destProcessPanel.add(getDestPathPanel()); |
182 |
destProcessPanel.add(getDestLayerTypePanel()); |
183 |
} |
184 |
|
185 |
return destProcessPanel;
|
186 |
} |
187 |
|
188 |
private JPanel getDestLayerNamePanel() { |
189 |
if (destLayerNamePanel == null) { |
190 |
destLayerNamePanel = new JPanel(); |
191 |
destLayerNamePanel.setPreferredSize(new Dimension(450, 30)); |
192 |
destLayerNamePanel.setLayout(new FlowLayout()); |
193 |
destLayerNamePanel.add(getLabelName()); |
194 |
destLayerNamePanel.add(getDestLayerName()); |
195 |
} |
196 |
|
197 |
return destLayerNamePanel;
|
198 |
} |
199 |
|
200 |
private JLabel getLabelName() { |
201 |
if (labelName == null) { |
202 |
labelName = new JLabel(PluginServices.getText(null, "Name")); |
203 |
labelName.setPreferredSize(new Dimension(70, 20)); |
204 |
labelName.setToolTipText(PluginServices.getText(null, "Name")); |
205 |
} |
206 |
|
207 |
return labelName;
|
208 |
} |
209 |
|
210 |
private JPanel getDestPathPanel() { |
211 |
if (destPathPanel == null) { |
212 |
destPathPanel = new JPanel(); |
213 |
destPathPanel.setLayout(new FlowLayout()); |
214 |
destPathPanel.setPreferredSize(new Dimension(450, 30)); |
215 |
destPathPanel.add(getLabelPath()); |
216 |
destPathPanel.add(getDestLayerPath()); |
217 |
destPathPanel.add(getJButtonSelectPath()); |
218 |
} |
219 |
|
220 |
return destPathPanel;
|
221 |
} |
222 |
|
223 |
private JPanel getDestLayerTypePanel() { |
224 |
if (destLayerTypePanel == null) { |
225 |
destLayerTypePanel = new JPanel(); |
226 |
destLayerTypePanel.setPreferredSize(new Dimension(450, 30)); |
227 |
destLayerTypePanel.add(getDestShapeTypeLabel()); |
228 |
destLayerTypePanel.add(getDestShapeTypeCombo()); |
229 |
} |
230 |
|
231 |
return destLayerTypePanel;
|
232 |
} |
233 |
|
234 |
private JLabel getDestShapeTypeLabel() { |
235 |
if (destShapeTypeLabel == null) { |
236 |
destShapeTypeLabel = new JLabel(PluginServices.getText(null, "Type")); |
237 |
destShapeTypeLabel.setPreferredSize(new Dimension(178, 20)); |
238 |
destShapeTypeLabel.setToolTipText(PluginServices.getText(null, "Type")); |
239 |
} |
240 |
|
241 |
return destShapeTypeLabel;
|
242 |
} |
243 |
|
244 |
private JComboBox getDestShapeTypeCombo() { |
245 |
if (destShapeTypeCombo == null) { |
246 |
destShapeTypeCombo = new JComboBox(); |
247 |
destShapeTypeCombo.setToolTipText(PluginServices.getText(null, "Destination_layer_type")); |
248 |
destShapeTypeCombo.setPreferredSize(new Dimension(254, 20)); |
249 |
destShapeTypeCombo.addItemListener(new ItemListener() { |
250 |
/*
|
251 |
* (non-Javadoc)
|
252 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
253 |
*/
|
254 |
public void itemStateChanged(ItemEvent e) { |
255 |
JComboBox source = (JComboBox) e.getSource(); |
256 |
|
257 |
if (source.getItemCount() == 0) { |
258 |
parameters.setDestinationLayerShapeType(DerivedGeometryProcessParameters.UNDEFINED_TYPE); |
259 |
} |
260 |
else {
|
261 |
parameters.setDestinationLayerShapeType(((OutputSHPType)source.getSelectedItem()).getOutputSHPType()); |
262 |
} |
263 |
} |
264 |
}); |
265 |
} |
266 |
|
267 |
return destShapeTypeCombo;
|
268 |
} |
269 |
|
270 |
private JPanel getOptionsPanel() { |
271 |
if (optionsPanel == null) { |
272 |
optionsPanel = new JPanel(); |
273 |
optionsPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "Options"))); |
274 |
optionsPanel.setLayout(new FlowLayout()); |
275 |
optionsPanel.setPreferredSize(new Dimension(470, 60)); |
276 |
optionsPanel.add(getProcessLabel()); |
277 |
optionsPanel.add(getProcessCombo()); |
278 |
} |
279 |
|
280 |
return optionsPanel;
|
281 |
} |
282 |
|
283 |
private JLabel getLabelPath() { |
284 |
if (labelPath == null) { |
285 |
labelPath = new JLabel(PluginServices.getText(null, "Path")); |
286 |
labelPath.setPreferredSize(new Dimension(70, 20)); |
287 |
labelPath.setToolTipText(PluginServices.getText(null, "Path")); |
288 |
} |
289 |
|
290 |
return labelPath;
|
291 |
} |
292 |
|
293 |
private JTextFieldWithSCP getDestLayerPath() {
|
294 |
if (destLayerPath == null) { |
295 |
destLayerPath = new JTextFieldWithSCP();
|
296 |
destLayerPath.setEditable(false);
|
297 |
destLayerPath.setBackground(Color.white);
|
298 |
destLayerPath.setPreferredSize(new Dimension(300, 20)); |
299 |
destLayerPath.setToolTipText(PluginServices.getText(null, "Path_where_create_the_new_layer_files")); |
300 |
} |
301 |
|
302 |
return destLayerPath;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* <p>This method initializes <code>jButtonSelectPath</code>.</p>
|
307 |
*
|
308 |
* @return javax.swing.JButton
|
309 |
*/
|
310 |
private JButton getJButtonSelectPath() { |
311 |
if (jButtonSelectPath == null) { |
312 |
jButtonSelectPath = new JButton(); |
313 |
jButtonSelectPath.setToolTipText(PluginServices.getText(this, "Select_the_path")); |
314 |
jButtonSelectPath.setText("...");
|
315 |
jButtonSelectPath.setPreferredSize(new Dimension(60, 20)); |
316 |
jButtonSelectPath.addActionListener(new java.awt.event.ActionListener() {
|
317 |
/*
|
318 |
* (non-Javadoc)
|
319 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
320 |
*/
|
321 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
322 |
JFileChooser jfc = new JFileChooser(); |
323 |
|
324 |
// Removes the default choosable file filter
|
325 |
FileFilter[] filters = jfc.getChoosableFileFilters(); |
326 |
|
327 |
for (int i = 0; i < filters.length; i++) |
328 |
jfc.removeChoosableFileFilter(filters[i]); |
329 |
|
330 |
// Displays only directories
|
331 |
//jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
332 |
|
333 |
// Only SHP
|
334 |
SimpleFileFilter filterSHP = new SimpleFileFilter(SHAPE_EXTENSION, PluginServices.getText(this, "Shape_file") + " (*.shp)"); |
335 |
jfc.addChoosableFileFilter(filterSHP); |
336 |
jfc.setFileFilter(filterSHP); |
337 |
|
338 |
jfc.addActionListener(new AbstractAction() { |
339 |
/*
|
340 |
* (non-Javadoc)
|
341 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
342 |
*/
|
343 |
public void actionPerformed(ActionEvent evt) { |
344 |
JFileChooser jfc = (JFileChooser)evt.getSource(); |
345 |
|
346 |
if (JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) { |
347 |
File destFile = null; |
348 |
|
349 |
if (jfc.getSelectedFile() == null) { |
350 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
351 |
return;
|
352 |
} |
353 |
|
354 |
if (jfc.getSelectedFile().getAbsoluteFile().getAbsolutePath().endsWith("." + SHAPE_EXTENSION)) { |
355 |
destFile = jfc.getSelectedFile().getAbsoluteFile(); |
356 |
} |
357 |
else {
|
358 |
destFile = new File(jfc.getSelectedFile().getAbsoluteFile().getAbsolutePath() + "." + SHAPE_EXTENSION); |
359 |
} |
360 |
|
361 |
parameters.setDestinationFile(destFile); |
362 |
getDestLayerPath().setText(destFile.toString()); |
363 |
|
364 |
if (getDestLayerName().getText().length() == 0) |
365 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
366 |
else {
|
367 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(true);
|
368 |
} |
369 |
} else if (JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) { |
370 |
parameters.setDestinationFile(null);
|
371 |
getDestLayerPath().setText("");
|
372 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
373 |
} |
374 |
} |
375 |
}); |
376 |
|
377 |
jfc.showOpenDialog((Component) PluginServices.getMainFrame());
|
378 |
} |
379 |
}); |
380 |
} |
381 |
|
382 |
return jButtonSelectPath;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* <p>This method initializes layersPanel.</p>
|
387 |
*
|
388 |
* @return javax.swing.JPanel
|
389 |
*/
|
390 |
private JPanel getLayersPanel() { |
391 |
if (layersPanel == null) { |
392 |
layersPanel = new JPanel(); |
393 |
layersPanel.setLayout(new FlowLayout()); |
394 |
layersPanel.setPreferredSize(new Dimension(460, 28)); |
395 |
layersPanel.add(getLayersLabel()); |
396 |
layersPanel.add(getLayersComboBox()); |
397 |
} |
398 |
|
399 |
return layersPanel;
|
400 |
} |
401 |
|
402 |
/**
|
403 |
* <p>This method initializes layersLabel.</p>
|
404 |
*
|
405 |
* @return javax.swing.JLabel
|
406 |
*/
|
407 |
private JLabel getLayersLabel() { |
408 |
if (layersLabel == null) { |
409 |
layersLabel = new JLabel(PluginServices.getText(this, "Layer")); |
410 |
layersLabel.setPreferredSize(new Dimension(40, 20)); |
411 |
} |
412 |
|
413 |
return layersLabel;
|
414 |
} |
415 |
|
416 |
private JTextFieldWithSCP getDestLayerName() {
|
417 |
if (destLayerName == null) { |
418 |
destLayerName = new JTextFieldWithSCP();
|
419 |
destLayerName.setPreferredSize(new Dimension(364, 20)); |
420 |
destLayerName.setToolTipText(PluginServices.getText(null, "Name_of_the_new_layer")); |
421 |
destLayerName.addKeyListener(new KeyAdapter() { |
422 |
/*
|
423 |
* (non-Javadoc)
|
424 |
* @see java.awt.event.KeyAdapter#keyReleased(java.awt.event.KeyEvent)
|
425 |
*/
|
426 |
public void keyReleased(KeyEvent e) { |
427 |
if ((getDestLayerName().getText().length() == 0) || ((JTextFieldWithSCP)e.getSource()).getText().length() == 0) { |
428 |
parameters.setDestinationLayerName(null);
|
429 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
430 |
} else {
|
431 |
parameters.setDestinationLayerName(((JTextFieldWithSCP)e.getSource()).getText()); |
432 |
|
433 |
if (getDestLayerPath().getText().length() == 0) { |
434 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
435 |
} |
436 |
else {
|
437 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(true);
|
438 |
} |
439 |
} |
440 |
} |
441 |
}); |
442 |
} |
443 |
|
444 |
return destLayerName;
|
445 |
} |
446 |
|
447 |
private JLabel getProcessLabel() { |
448 |
if (destProcessLabel == null) { |
449 |
destProcessLabel = new JLabel(PluginServices.getText(null, "Process_type")); |
450 |
destProcessLabel.setPreferredSize(new Dimension(180, 20)); |
451 |
//destShapeTypeLabel.setEnabled(false);
|
452 |
destProcessLabel.setToolTipText(PluginServices.getText(null, "Process_type")); |
453 |
} |
454 |
|
455 |
return destProcessLabel;
|
456 |
} |
457 |
|
458 |
private JComboBox getProcessCombo() { |
459 |
if (destProcessCombo == null) { |
460 |
destProcessCombo = new JComboBox(); |
461 |
destProcessCombo.setToolTipText(PluginServices.getText(null, "Process_type")); |
462 |
destProcessCombo.setPreferredSize(new Dimension(254, 20)); |
463 |
destProcessCombo.addItemListener(new ItemListener() { |
464 |
/*
|
465 |
* (non-Javadoc)
|
466 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
467 |
*/
|
468 |
public void itemStateChanged(ItemEvent e) { |
469 |
JComboBox source = (JComboBox) e.getSource(); |
470 |
|
471 |
if (source.getItemCount() == 0) { |
472 |
parameters.setProcessID(DerivedGeometryProcessParameters.UNDEFINED_TYPE); |
473 |
} |
474 |
else {
|
475 |
short processID = ((ProcessType)source.getSelectedItem()).getProcessID();
|
476 |
|
477 |
parameters.setProcessID(processID); |
478 |
|
479 |
// Updates the other combo
|
480 |
getDestShapeTypeCombo().removeAllItems(); |
481 |
|
482 |
switch(processID) {
|
483 |
case DerivedGeometryProcessParameters.POINTS_TO_LINE_PROCESS_ID:
|
484 |
getDestShapeTypeCombo().addItem(line); |
485 |
//getDestShapeTypeCombo().addItem(multi);
|
486 |
break;
|
487 |
case DerivedGeometryProcessParameters.POINTS_TO_POLYGON_PROCESS_ID:
|
488 |
getDestShapeTypeCombo().addItem(polygon); |
489 |
//getDestShapeTypeCombo().addItem(multi);
|
490 |
break;
|
491 |
case DerivedGeometryProcessParameters.CLOSE_MULTILINE_PROCESS_ID:
|
492 |
getDestShapeTypeCombo().addItem(polygon); |
493 |
//getDestShapeTypeCombo().addItem(multi);
|
494 |
break;
|
495 |
case DerivedGeometryProcessParameters.POINTS_TO_LINE_OR_POLYGON_ID:
|
496 |
getDestShapeTypeCombo().addItem(multi); |
497 |
} |
498 |
} |
499 |
} |
500 |
}); |
501 |
} |
502 |
|
503 |
return destProcessCombo;
|
504 |
} |
505 |
|
506 |
|
507 |
/**
|
508 |
* <p>This method initializes layersComboBox.</p>
|
509 |
*
|
510 |
* @return javax.swing.JComboBox
|
511 |
*/
|
512 |
private JComboBox getLayersComboBox() { |
513 |
if (layersComboBox == null) { |
514 |
layersComboBox = new JComboBox(); |
515 |
layersComboBox.setPreferredSize(new Dimension(layersComboBox_Width, layersComboBox_Height)); |
516 |
layersComboBox.addItemListener(new ItemListener() { |
517 |
/*
|
518 |
* (non-Javadoc)
|
519 |
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
520 |
*/
|
521 |
public void itemStateChanged(ItemEvent e) { |
522 |
if (e.getStateChange() == ItemEvent.SELECTED) { |
523 |
// infoLayerSelected = null;
|
524 |
// selectedFields = 0;
|
525 |
|
526 |
try {
|
527 |
FLayerWrapper fW = (FLayerWrapper)e.getItem(); |
528 |
|
529 |
if (fW != null) { |
530 |
FLayer layer = fW.getLayer(); |
531 |
|
532 |
if (layer != null) { |
533 |
// infoLayerSelected = null;
|
534 |
// infoLayerSelected = new QuickInfoFLayerSelected(layer);
|
535 |
// getFieldsModeButton().setToolTipText(PluginServices.getText(this, "Ascending"));
|
536 |
layersComboBox.setToolTipText("<html>" + PluginServices.getText(this, "Layer") + ": " + layer.getName() + "<br>" + |
537 |
PluginServices.getText(this, "Type") + ": " + FShapeTypeNames.getFShapeTypeName(((FLyrVect)layer).getShapeType()) + "</html>"); |
538 |
|
539 |
// refreshSelectedLayerFields();
|
540 |
|
541 |
// Sets the layer selected
|
542 |
parameters.setSourceLayer((FLyrVect)layer); |
543 |
|
544 |
// Removes the values of the destination file
|
545 |
getDestLayerName().setText("");
|
546 |
getDestLayerPath().setText("");
|
547 |
|
548 |
parameters.setDestinationFile(null);
|
549 |
parameters.setDestinationLayerName(null);
|
550 |
parameters.setDestinationLayerShapeType(DerivedGeometryProcessParameters.UNDEFINED_TYPE); |
551 |
|
552 |
getDestShapeTypeCombo().removeAllItems(); |
553 |
getProcessCombo().removeAllItems(); |
554 |
|
555 |
switch(((FLyrVect)layer).getShapeType()) {
|
556 |
case FShape.POINT:
|
557 |
setSelectableComponentsEnabled(true);
|
558 |
getProcessCombo().addItem(pointsToLine); |
559 |
getProcessCombo().addItem(pointsToPolygon); |
560 |
//getProcessCombo().addItem(pointsToLineOrPolygon);
|
561 |
break;
|
562 |
case FShape.LINE:
|
563 |
setSelectableComponentsEnabled(true);
|
564 |
getProcessCombo().addItem(closeMultiLine); |
565 |
break;
|
566 |
default:
|
567 |
setSelectableComponentsEnabled(false);
|
568 |
|
569 |
if (started)
|
570 |
JOptionPane.showMessageDialog(layersComboBox, PluginServices.getText(null, "Cant_process_this_layer")); |
571 |
} |
572 |
|
573 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
574 |
} |
575 |
} |
576 |
|
577 |
// getFieldsModeButton().setText(PluginServices.getText(this, "Ascending"));
|
578 |
// getFieldsModeButton().setToolTipText(PluginServices.getText(this, "Ascending"));
|
579 |
getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
580 |
} |
581 |
catch(ReadDriverException dE) {
|
582 |
NotificationManager.showMessageError(PluginServices.getText(null, "problem_loading_layers"), dE); |
583 |
} |
584 |
} |
585 |
} |
586 |
}); |
587 |
} |
588 |
|
589 |
return layersComboBox;
|
590 |
} |
591 |
|
592 |
/**
|
593 |
* <p>This method initializes acceptCancelPanel.</p>
|
594 |
*
|
595 |
* @return an adapted {@link AcceptCancelPanel AcceptCancelPanel}
|
596 |
*/
|
597 |
private AdaptedAcceptCancelPanel getAdaptedAcceptCancelPanel() {
|
598 |
if (acceptCancelPanel == null) { |
599 |
acceptCancelPanel = new AdaptedAcceptCancelPanel();
|
600 |
} |
601 |
|
602 |
return acceptCancelPanel;
|
603 |
} |
604 |
|
605 |
/**
|
606 |
* <p>Updates "layersComboBox" with the name of visible layers of the associated <code>MapControl</code> instance.</p>
|
607 |
*
|
608 |
* @see #refreshVisibleVectorLayers(FLayer, int)
|
609 |
*
|
610 |
* @return <code>true</code> if there is any layer added that can be written, otherwise <code>false</code>
|
611 |
*/
|
612 |
private boolean refreshVisibleVectorLayers() { |
613 |
FLayer rootNode = parameters.getMapControl().getMapContext().getLayers(); |
614 |
|
615 |
getLayersComboBox().removeAllItems(); |
616 |
|
617 |
boolean b = refreshVisibleVectorLayers(rootNode, -1); |
618 |
|
619 |
// The selectedLayer will be, by default, the first being added.
|
620 |
if (getLayersComboBox().getItemCount() > 0) { |
621 |
getLayersComboBox().setRenderer(new LayersComboBoxCellRenderer());
|
622 |
getLayersComboBox().setSelectedIndex(0);
|
623 |
} |
624 |
|
625 |
// If there is only one layer -> disable the possibility of selection by the user
|
626 |
if (getLayersComboBox().getItemCount() <= 1) { |
627 |
getLayersComboBox().setEnabled(false);
|
628 |
} |
629 |
|
630 |
return b;
|
631 |
} |
632 |
|
633 |
/**
|
634 |
* <p>Updates "layersComboBox" with the name of visible layers down <code>node</code>.</p>
|
635 |
*
|
636 |
* @param node parent node
|
637 |
* @param level <code>node</code> level from the root
|
638 |
*
|
639 |
* @return <code>true</code> if some layer added can be edited, otherwise <code>false</code>
|
640 |
*/
|
641 |
private boolean refreshVisibleVectorLayers(FLayer node, int level) { |
642 |
if (node instanceof FLayers) { |
643 |
FLayers root = (FLayers)node; |
644 |
boolean b = false; |
645 |
|
646 |
for (int i = root.getLayersCount() - 1; i >= 0 ; i--) { |
647 |
if (root.getLayer(i).isVisible()) {
|
648 |
b |= refreshVisibleVectorLayers(root.getLayer(i), level + 1);
|
649 |
} |
650 |
} |
651 |
|
652 |
return b;
|
653 |
} |
654 |
else {
|
655 |
String layerName = node.getName();
|
656 |
|
657 |
if ((!node.isEditing()) && (node.isVisible()) && (node instanceof FLyrVect) && (layerName != null)) { |
658 |
getLayersComboBox().addItem(new FLayerWrapper((FLyrVect)node, level, bIcon, getLayerIcon(node)));
|
659 |
|
660 |
return node.isWritable();
|
661 |
} |
662 |
} |
663 |
|
664 |
return false; |
665 |
} |
666 |
|
667 |
private void setSelectableComponentsEnabled(boolean b) { |
668 |
getDestLayerPath().setEnabled(b); |
669 |
getDestLayerName().setEnabled(b); |
670 |
getJButtonSelectPath().setEnabled(b); |
671 |
getProcessCombo().setEnabled(b); |
672 |
} |
673 |
|
674 |
/**
|
675 |
* <p>Returns the icon that represents the layer in the current active view's TOC.</p>
|
676 |
*
|
677 |
* @param layer the layer
|
678 |
* @return the layer's icon in the current active view's TOC
|
679 |
*/
|
680 |
private Icon getLayerIcon(FLayer layer) { |
681 |
if (layer.getTocImageIcon() != null) { |
682 |
return layer.getTocImageIcon();
|
683 |
} |
684 |
else {
|
685 |
TocItemBranch branch = new TocItemBranch(layer);
|
686 |
|
687 |
return branch.getIcon();
|
688 |
} |
689 |
} |
690 |
|
691 |
/*
|
692 |
* (non-Javadoc)
|
693 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
694 |
*/
|
695 |
public WindowInfo getWindowInfo() {
|
696 |
if (viewInfo == null) { |
697 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
698 |
viewInfo.setTitle(PluginServices.getText(this, "Select_layers_and_process")); |
699 |
viewInfo.setWidth(Window_Width); |
700 |
viewInfo.setHeight(Window_Height); |
701 |
} |
702 |
|
703 |
return viewInfo;
|
704 |
} |
705 |
|
706 |
|
707 |
// /**
|
708 |
// * <p>Enables / disables the <i>accept</i> button.</p>
|
709 |
// *
|
710 |
// * <p>If all required parameters are defined and valid, will be enabled, otherwise disabled.</p>
|
711 |
// */
|
712 |
// private void updateAcceptButton() {
|
713 |
// if ((parameters != null) && (parameters.requiredDefined())) {
|
714 |
// getAdaptedAcceptCancelPanel().setOkButtonEnabled(true);
|
715 |
// }
|
716 |
// else {
|
717 |
// getAdaptedAcceptCancelPanel().setOkButtonEnabled(false);
|
718 |
// }
|
719 |
// }
|
720 |
|
721 |
/**
|
722 |
* <p>Closes this window.</p>
|
723 |
*/
|
724 |
private void closeThis() { |
725 |
PluginServices.getMDIManager().closeWindow(this);
|
726 |
} |
727 |
|
728 |
/**
|
729 |
* <p>Adapts {@link AcceptCancelPanel AcceptCancelPanel} to be used as a component of the <code>QInfoDataSelectionPanel</code> panel.</p>
|
730 |
*
|
731 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
732 |
*/
|
733 |
private class AdaptedAcceptCancelPanel extends AcceptCancelPanel { |
734 |
private static final long serialVersionUID = -6112053411624411449L; |
735 |
|
736 |
public AdaptedAcceptCancelPanel () {
|
737 |
super();
|
738 |
|
739 |
addOkButtonActionListener(getOKAction()); |
740 |
addCancelButtonActionListener(getCancelAction()); |
741 |
setPreferredSize(new Dimension(474, 28)); |
742 |
} |
743 |
|
744 |
/**
|
745 |
* <p>Create the action that will be executed when user pressed the <i>ok</i> button.</p>
|
746 |
*
|
747 |
* @return action that will be executed when user pressed the <i>cancel</i> button
|
748 |
*/
|
749 |
private ActionListener getOKAction() { |
750 |
// OK button action
|
751 |
return new ActionListener() { |
752 |
/*
|
753 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
754 |
*/
|
755 |
public void actionPerformed(ActionEvent e) { |
756 |
closeThis(); |
757 |
|
758 |
/* If the layer exits, asks the user if wants to overwrite it */
|
759 |
if(parameters.getDestinationFile().exists()){
|
760 |
int resp = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),PluginServices.getText(this,"fichero_ya_existe_seguro_desea_guardarlo"), PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION); |
761 |
|
762 |
if (resp != JOptionPane.YES_OPTION) { |
763 |
return;
|
764 |
} |
765 |
} |
766 |
|
767 |
PluginServices.getMDIManager().addWindow(new DerivedGeometryControlPanel(parameters));
|
768 |
} |
769 |
}; |
770 |
} |
771 |
|
772 |
/**
|
773 |
* <p>Create the action that will be executed when user pressed the <i>cancel</i> button.</p>
|
774 |
*
|
775 |
* @return action that will be executed when user pressed the <i>cancel</i> button
|
776 |
*/
|
777 |
private ActionListener getCancelAction() { |
778 |
// Cancel button action
|
779 |
return new ActionListener() { |
780 |
/*
|
781 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
782 |
*/
|
783 |
public void actionPerformed(ActionEvent e) { |
784 |
closeThis(); |
785 |
} |
786 |
}; |
787 |
} |
788 |
} |
789 |
|
790 |
|
791 |
/**
|
792 |
* <p>Wrappers a <code>FLayer</code> overwriting the method <code>toString()</code> in order to would
|
793 |
* return the name of the layer.</code>
|
794 |
*
|
795 |
* <p>Also displays icons and label</p>
|
796 |
*
|
797 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
798 |
*/
|
799 |
private class FLayerWrapper extends JPanel { |
800 |
private static final long serialVersionUID = -160586150559061104L; |
801 |
|
802 |
private FLyrVect layer;
|
803 |
private int level; |
804 |
ImageIcon branchIcon;
|
805 |
|
806 |
/**
|
807 |
* <p>Creates a new <code>FLayerWrapper</code>.</p>
|
808 |
*
|
809 |
* @param layer the vector layer to be wrappered
|
810 |
* @param level the level in the tree of the layer wrappered
|
811 |
* @param branchIcon icon that represents the branch
|
812 |
* @param leafIcon icon that represents the leaf
|
813 |
*/
|
814 |
public FLayerWrapper(FLyrVect layer, int level, ImageIcon branchIcon, Icon leafIcon) { |
815 |
super();
|
816 |
|
817 |
this.layer = layer;
|
818 |
this.level = level;
|
819 |
this.branchIcon = branchIcon;
|
820 |
|
821 |
setLayout(new SpringLayout()); |
822 |
|
823 |
if ((level > 0) && (branchIcon != null)) { |
824 |
for (int i = 0; i < level; i++) { |
825 |
add(new JLabel(branchIcon)); |
826 |
} |
827 |
} |
828 |
|
829 |
JLabel layerLabel;
|
830 |
|
831 |
if (layer.getName() != null) |
832 |
layerLabel = new JLabel(layer.getName()); |
833 |
else
|
834 |
layerLabel = new JLabel(""); |
835 |
|
836 |
if (leafIcon != null) |
837 |
layerLabel.setIcon(leafIcon); |
838 |
|
839 |
layerLabel.setFont(new Font("Helvetica", Font.BOLD, 12)); |
840 |
|
841 |
add(layerLabel); |
842 |
|
843 |
if (layer instanceof FLyrVect) { |
844 |
JLabel layerTypeLabel;
|
845 |
try {
|
846 |
layerTypeLabel = new JLabel(PluginServices.getText(null, "Type") + ": " + FShapeTypeNames.getFShapeTypeName(((FLyrVect) layer).getShapeType())); |
847 |
} catch (ReadDriverException e) {
|
848 |
layerTypeLabel = new JLabel(PluginServices.getText(null, "Type") + ": " + PluginServices.getText("", "UNKNOWN")); |
849 |
NotificationManager.showMessageError("Driver exception", e);
|
850 |
} |
851 |
|
852 |
layerTypeLabel.setFont(new Font("Helvetica", Font.ITALIC, 12)); |
853 |
|
854 |
add(layerTypeLabel); |
855 |
} |
856 |
|
857 |
doSpringLayout(); |
858 |
setPreferredSize(new Dimension(340, 16)); |
859 |
} |
860 |
|
861 |
/**
|
862 |
* <p>Creates the <code>Spring</code> layout of this component.</p>
|
863 |
*/
|
864 |
private void doSpringLayout() { |
865 |
Component[] components = getComponents(); |
866 |
SpringLayout layout = (SpringLayout)getLayout(); |
867 |
Spring xPad = Spring.constant(5); |
868 |
Spring ySpring = Spring.constant(0); |
869 |
Spring xSpring = xPad;
|
870 |
|
871 |
// Make every component 5 pixels away from the component to its left.
|
872 |
for (int i = 0; i < components.length; i++) { |
873 |
SpringLayout.Constraints cons = layout.getConstraints(components[i]);
|
874 |
cons.setX(xSpring); |
875 |
xSpring = Spring.sum(xPad, cons.getConstraint("East")); |
876 |
|
877 |
cons.setY(ySpring); |
878 |
} |
879 |
} |
880 |
|
881 |
/**
|
882 |
* <p>Gets the layer wrappered.</p>
|
883 |
*
|
884 |
* @return the layer wrappered
|
885 |
*/
|
886 |
public FLyrVect getLayer() {
|
887 |
return layer;
|
888 |
} |
889 |
|
890 |
/**
|
891 |
* <p>Gets the level in the tree of the layer wrappered.</p>
|
892 |
*
|
893 |
* @return the level in the tree of the layer wrappered
|
894 |
*/
|
895 |
public int getLevel() { |
896 |
return level;
|
897 |
} |
898 |
|
899 |
/*
|
900 |
* (non-Javadoc)
|
901 |
* @see javax.swing.JComponent#setForeground(java.awt.Color)
|
902 |
*/
|
903 |
public void setForeground(Color fg) { |
904 |
super.setForeground(fg);
|
905 |
} |
906 |
|
907 |
/*
|
908 |
* (non-Javadoc)
|
909 |
* @see javax.swing.JComponent#setBackground(java.awt.Color)
|
910 |
*/
|
911 |
public void setBackground(Color bg) { |
912 |
super.setBackground(bg);
|
913 |
} |
914 |
|
915 |
/*
|
916 |
* (non-Javadoc)
|
917 |
* @see java.lang.Object#toString()
|
918 |
*/
|
919 |
public String toString() { |
920 |
return layer.getName();
|
921 |
} |
922 |
} |
923 |
|
924 |
|
925 |
/**
|
926 |
* <p>Cell renderer of the combo box with information of the visible vector layers in the current active view.</p>
|
927 |
*
|
928 |
* @see ListCellRenderer
|
929 |
*
|
930 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
931 |
*/
|
932 |
private class LayersComboBoxCellRenderer implements ListCellRenderer { |
933 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
934 |
FLayerWrapper renderer = (FLayerWrapper)value; |
935 |
|
936 |
if (isSelected) {
|
937 |
renderer.setForeground(UIManager.getColor( "ComboBox.selectionForeground" )); |
938 |
renderer.setBackground(UIManager.getColor( "ComboBox.selectionBackground" )); |
939 |
} |
940 |
else
|
941 |
renderer.setBackground(Color.WHITE);
|
942 |
|
943 |
return renderer;
|
944 |
} |
945 |
} |
946 |
|
947 |
/**
|
948 |
*
|
949 |
*
|
950 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
951 |
*/
|
952 |
private class ProcessType { |
953 |
private String processName; |
954 |
private short processID; |
955 |
|
956 |
public ProcessType(String processName, short processID) { |
957 |
this.processName = processName;
|
958 |
this.processID = processID;
|
959 |
} |
960 |
|
961 |
public short getProcessID() { |
962 |
return processID;
|
963 |
} |
964 |
|
965 |
public String getProcessName() { |
966 |
return processName;
|
967 |
} |
968 |
|
969 |
public String toString() { |
970 |
return processName;
|
971 |
} |
972 |
} |
973 |
|
974 |
/**
|
975 |
*
|
976 |
*
|
977 |
*
|
978 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
979 |
*/
|
980 |
private class OutputSHPType { |
981 |
private String outputSHPTypeName; |
982 |
private int outputSHPType; |
983 |
|
984 |
public OutputSHPType(String name, int type) { |
985 |
outputSHPTypeName = name; |
986 |
outputSHPType = type; |
987 |
} |
988 |
|
989 |
public String getOutputSHPName() { |
990 |
return outputSHPTypeName;
|
991 |
} |
992 |
|
993 |
public int getOutputSHPType() { |
994 |
return outputSHPType;
|
995 |
} |
996 |
|
997 |
public String toString() { |
998 |
return outputSHPTypeName;
|
999 |
} |
1000 |
} |
1001 |
|
1002 |
public Object getWindowProfile() { |
1003 |
return WindowInfo.DIALOG_PROFILE;
|
1004 |
} |
1005 |
} |