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