root / trunk / extensions / extSelectionTools / src / org / gvsig / selectionTools / tools / buffer / gui / BufferConfigurationPanel.java @ 37921
History | View | Annotate | Download (21.2 KB)
1 |
package org.gvsig.selectionTools.tools.buffer.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.Dimension; |
26 |
import java.awt.FlowLayout; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
import java.awt.event.ComponentAdapter; |
30 |
import java.awt.event.ComponentEvent; |
31 |
import java.text.DecimalFormat; |
32 |
import java.util.ArrayList; |
33 |
import java.util.Arrays; |
34 |
import java.util.Iterator; |
35 |
|
36 |
import javax.swing.BorderFactory; |
37 |
import javax.swing.JCheckBox; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.text.NumberFormatter; |
41 |
|
42 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
43 |
import org.gvsig.gui.beans.incrementabletask.IncrementableTask; |
44 |
import org.gvsig.gui.beans.progresspanel.ProgressPanel; |
45 |
import org.gvsig.gui.beans.specificcaretposition.JFormattedTextFieldSCP; |
46 |
import org.gvsig.selectionTools.tools.buffer.process.BufferSelectionProcess; |
47 |
|
48 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
49 |
import com.iver.andami.PluginServices; |
50 |
import com.iver.andami.messages.NotificationManager; |
51 |
import com.iver.andami.ui.mdiManager.IWindow; |
52 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
53 |
import com.iver.cit.gvsig.fmap.MapControl; |
54 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
55 |
import com.iver.cit.gvsig.geoprocess.impl.buffer.fmap.BufferVisitor; |
56 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
57 |
import com.iver.utiles.swing.JComboBox; |
58 |
|
59 |
|
60 |
/**
|
61 |
*
|
62 |
*
|
63 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
64 |
*/
|
65 |
public class BufferConfigurationPanel extends JPanel implements IWindow { |
66 |
private WindowInfo viewInfo = null; |
67 |
private final short Window_Width = 354; |
68 |
private final short Window_Height = 315; //35; |
69 |
private JFormattedTextFieldSCP distanceTextField = null; |
70 |
private JComboBox distanceUnitsCombo = null; |
71 |
private JComboBox polygonSidesCombo = null; |
72 |
private JComboBox lineSidesCombo = null; |
73 |
private JComboBox pointSidesCombo = null; |
74 |
private JComboBox multiPointSidesCombo = null; |
75 |
private JLabel distanceUnitsLabel = null; |
76 |
private JLabel polygonSideLabel = null; |
77 |
private JLabel lineSideLabel = null; |
78 |
private JLabel pointSideLabel = null; |
79 |
private JLabel multiPointSideLabel = null; |
80 |
private JPanel polygonSidePanel = null; |
81 |
private JPanel lineSidePanel = null; |
82 |
private JPanel pointSidePanel = null; |
83 |
private JPanel multiPointSidePanel = null; |
84 |
private JLabel widthLabel = null; |
85 |
private JPanel widthPanel = null; |
86 |
// private JPanel distanceUnits = null;
|
87 |
private JPanel sidePanel = null; |
88 |
private JPanel optionsPanel = null; |
89 |
private AdaptedAcceptCancelPanel acceptCancelPanel = null; |
90 |
private FLyrVect[] layers; |
91 |
private MapControl mapControl;
|
92 |
private View view; |
93 |
private JCheckBox multiLayerSelectionCBox; |
94 |
// private JCheckBox addBufferLayersCBox;
|
95 |
private JCheckBox addInfluenceAreasLayersCBox; |
96 |
private SideInfo outside, inside, out_in_side;
|
97 |
|
98 |
/**
|
99 |
* <p>
|
100 |
* Creates a new form where user can define the option of the buffer.
|
101 |
* </p>
|
102 |
*/
|
103 |
public BufferConfigurationPanel(FLyrVect[] array, View view) { |
104 |
super();
|
105 |
|
106 |
layers = array; |
107 |
this.view = view;
|
108 |
mapControl = view.getMapControl(); |
109 |
|
110 |
initialize(); |
111 |
} |
112 |
|
113 |
/**
|
114 |
* <p>
|
115 |
* Initializes this component.
|
116 |
* </p>
|
117 |
*/
|
118 |
private void initialize() { |
119 |
outside = new SideInfo(BufferVisitor.BUFFER_OUTSIDE_POLY, PluginServices.getText(null, "Outside")); |
120 |
inside = new SideInfo(BufferVisitor.BUFFER_INSIDE_POLY, PluginServices.getText(null, "Inside")); |
121 |
out_in_side = new SideInfo(BufferVisitor.BUFFER_INSIDE_OUTSIDE_POLY, PluginServices.getText(null, "Both")); |
122 |
|
123 |
setLayout(new FlowLayout()); |
124 |
add(getWidthPanel()); |
125 |
add(getSidePanel()); |
126 |
add(getOptionsPanel()); |
127 |
add(getAdaptedAcceptCancelPanel()); |
128 |
} |
129 |
|
130 |
private JPanel getOptionsPanel() { |
131 |
if (optionsPanel == null) { |
132 |
optionsPanel = new JPanel(); |
133 |
optionsPanel.setLayout(new FlowLayout()); |
134 |
optionsPanel.setPreferredSize(new Dimension(344, 80)); //106)); |
135 |
optionsPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(optionsPanel, "Options"))); |
136 |
optionsPanel.add(getMultiLayerSelectionCBox()); |
137 |
// optionsPanel.add(getAddBufferLayersCBox());
|
138 |
optionsPanel.add(getAddInfluenceAreaLayersCBox()); |
139 |
} |
140 |
|
141 |
return optionsPanel;
|
142 |
} |
143 |
|
144 |
private JCheckBox getMultiLayerSelectionCBox() { |
145 |
if (multiLayerSelectionCBox == null) { |
146 |
multiLayerSelectionCBox = new JCheckBox(); |
147 |
multiLayerSelectionCBox.setPreferredSize(new Dimension(330, 22)); |
148 |
multiLayerSelectionCBox.setText(PluginServices.getText(multiLayerSelectionCBox, "multiLayer_selection"));
|
149 |
multiLayerSelectionCBox.setSelected(true);
|
150 |
multiLayerSelectionCBox.setToolTipText(PluginServices.getText(null, "multiLayerSelection_checkbox_TOOLTIP_HTML_explanation")); |
151 |
} |
152 |
|
153 |
return multiLayerSelectionCBox;
|
154 |
} |
155 |
|
156 |
// private JCheckBox getAddBufferLayersCBox() {
|
157 |
// if (addBufferLayersCBox == null) {
|
158 |
// addBufferLayersCBox = new JCheckBox();
|
159 |
// addBufferLayersCBox.setPreferredSize(new Dimension(330, 22));
|
160 |
// addBufferLayersCBox.setText(PluginServices.getText(addBufferLayersCBox, "add_buffer_layers"));
|
161 |
// addBufferLayersCBox.setSelected(false);
|
162 |
// addBufferLayersCBox.setToolTipText(PluginServices.getText(null, "addBufferLayers_checkbox_TOOLTIP_HTML_explanation"));
|
163 |
// }
|
164 |
//
|
165 |
// return addBufferLayersCBox;
|
166 |
// }
|
167 |
|
168 |
private JCheckBox getAddInfluenceAreaLayersCBox() { |
169 |
if (addInfluenceAreasLayersCBox == null) { |
170 |
addInfluenceAreasLayersCBox = new JCheckBox(); |
171 |
addInfluenceAreasLayersCBox.setPreferredSize(new Dimension(330, 22)); |
172 |
addInfluenceAreasLayersCBox.setText(PluginServices.getText(addInfluenceAreasLayersCBox, "add_influence_areas_layers"));
|
173 |
addInfluenceAreasLayersCBox.setSelected(false);
|
174 |
addInfluenceAreasLayersCBox.setToolTipText(PluginServices.getText(null, "addInfluenceAreasLayers_checkbox_TOOLTIP_HTML_explanation")); |
175 |
} |
176 |
|
177 |
return addInfluenceAreasLayersCBox;
|
178 |
} |
179 |
private JPanel getWidthPanel() { |
180 |
if (widthPanel == null) { |
181 |
widthPanel = new JPanel(); |
182 |
widthPanel.setPreferredSize(new Dimension(344, 55)); |
183 |
widthPanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(widthPanel, "Width"))); |
184 |
widthPanel.setLayout(new FlowLayout()); |
185 |
widthPanel.add(getWidthLabel()); |
186 |
widthPanel.add(getWidthTextField()); |
187 |
widthPanel.add(getDistanceUnitsLabel()); |
188 |
widthPanel.add(getDistanceUnitsCombo()); |
189 |
} |
190 |
|
191 |
return widthPanel;
|
192 |
} |
193 |
|
194 |
private JLabel getWidthLabel() { |
195 |
if (widthLabel == null) { |
196 |
widthLabel = new JLabel(); |
197 |
widthLabel.setPreferredSize(new Dimension(68, 22)); |
198 |
widthLabel.setText(PluginServices.getText(widthLabel, "Width"));
|
199 |
widthLabel.setToolTipText(PluginServices.getText(null, "bufferWidth_TOOLTIP_HTML_explanation")); |
200 |
} |
201 |
|
202 |
return widthLabel;
|
203 |
} |
204 |
|
205 |
private JFormattedTextFieldSCP getWidthTextField() {
|
206 |
if (distanceTextField == null) { |
207 |
DecimalFormat decimalFormat = new DecimalFormat(); |
208 |
decimalFormat.setDecimalSeparatorAlwaysShown(true);
|
209 |
decimalFormat.setMaximumIntegerDigits(12);
|
210 |
decimalFormat.setMinimumIntegerDigits(1);
|
211 |
decimalFormat.setMinimumFractionDigits(2);
|
212 |
decimalFormat.setMaximumFractionDigits(4);
|
213 |
|
214 |
NumberFormatter numberFormatter = new NumberFormatter(); |
215 |
numberFormatter.setAllowsInvalid(false);
|
216 |
numberFormatter.setOverwriteMode(false);
|
217 |
numberFormatter.setCommitsOnValidEdit(true);
|
218 |
numberFormatter.setMinimum(new Double(1)); |
219 |
numberFormatter.setFormat(decimalFormat); |
220 |
|
221 |
// numberFormatter.setFormat(new DecimalFormat("([+]|[-])?[0-9]+([.][0-9]+)?"));
|
222 |
|
223 |
distanceTextField = new JFormattedTextFieldSCP(numberFormatter);
|
224 |
distanceTextField.setPreferredSize(new Dimension(85, 22)); |
225 |
distanceTextField.setValue(new Double(100.00)); |
226 |
distanceTextField.setToolTipText(PluginServices.getText(null, "bufferWidth_TOOLTIP_HTML_explanation")); |
227 |
} |
228 |
|
229 |
return distanceTextField;
|
230 |
} |
231 |
|
232 |
private JLabel getDistanceUnitsLabel() { |
233 |
if (distanceUnitsLabel == null) { |
234 |
distanceUnitsLabel = new JLabel(PluginServices.getText(distanceUnitsLabel, "Unit")); |
235 |
distanceUnitsLabel.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
|
236 |
distanceUnitsLabel.setPreferredSize(new Dimension(68, 22)); |
237 |
distanceUnitsLabel.setToolTipText(PluginServices.getText(null, "distanceUnitsLabel_TOOLTIP_HTML_explanation")); |
238 |
} |
239 |
|
240 |
return distanceUnitsLabel;
|
241 |
} |
242 |
|
243 |
private JComboBox getDistanceUnitsCombo() { |
244 |
if (distanceUnitsCombo == null) { |
245 |
distanceUnitsCombo = new JComboBox(); |
246 |
distanceUnitsCombo.setPreferredSize(new Dimension(85, 22)); |
247 |
distanceUnitsCombo.addItem("km");
|
248 |
distanceUnitsCombo.addItem("m");
|
249 |
distanceUnitsCombo.addItem("cm");
|
250 |
distanceUnitsCombo.addItem("mm");
|
251 |
distanceUnitsCombo.addItem("mi");
|
252 |
distanceUnitsCombo.addItem("Ya");
|
253 |
distanceUnitsCombo.addItem("ft");
|
254 |
distanceUnitsCombo.addItem("in");
|
255 |
distanceUnitsCombo.addItem("?");
|
256 |
distanceUnitsCombo.setSelectedIndex(1); // By default in meters |
257 |
distanceUnitsCombo.setToolTipText(PluginServices.getText(null, "distanceUnitsLabel_TOOLTIP_HTML_explanation")); |
258 |
} |
259 |
|
260 |
return distanceUnitsCombo;
|
261 |
} |
262 |
|
263 |
private JPanel getSidePanel() { |
264 |
if (sidePanel == null) { |
265 |
sidePanel = new JPanel(); |
266 |
sidePanel.setLayout(new FlowLayout()); |
267 |
sidePanel.setPreferredSize(new Dimension(344, 166)); //160)); |
268 |
sidePanel.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(sidePanel, "Side"))); |
269 |
sidePanel.setToolTipText(PluginServices.getText(null, "sideLabel_TOOLTIP_HTML_explanation")); |
270 |
sidePanel.add(getPolygonSidePanel()); |
271 |
sidePanel.add(getLineSidePanel()); |
272 |
sidePanel.add(getPointSidePanel()); |
273 |
sidePanel.add(getMultiPointSidePanel()); |
274 |
} |
275 |
|
276 |
return sidePanel;
|
277 |
} |
278 |
|
279 |
private JPanel getPolygonSidePanel() { |
280 |
if (polygonSidePanel == null) { |
281 |
polygonSidePanel = new JPanel(); |
282 |
polygonSidePanel.setPreferredSize(new Dimension(336, 28)); |
283 |
polygonSidePanel.add(getPolygonSideLabel()); |
284 |
polygonSidePanel.add(getPolygonSidesCombo()); |
285 |
} |
286 |
|
287 |
return polygonSidePanel;
|
288 |
} |
289 |
|
290 |
private JLabel getPolygonSideLabel() { |
291 |
if (polygonSideLabel == null) { |
292 |
polygonSideLabel = new JLabel(PluginServices.getText(polygonSideLabel, "Polygon")); |
293 |
polygonSideLabel.setPreferredSize(new Dimension(90, 22)); |
294 |
polygonSideLabel.setToolTipText(PluginServices.getText(null, "polygonSideLabel_TOOLTIP_HTML_explanation")); |
295 |
} |
296 |
|
297 |
return polygonSideLabel;
|
298 |
} |
299 |
|
300 |
private JComboBox getPolygonSidesCombo() { |
301 |
if (polygonSidesCombo == null) { |
302 |
polygonSidesCombo = new JComboBox(); |
303 |
polygonSidesCombo.setPreferredSize(new Dimension(230, 22)); |
304 |
polygonSidesCombo.addItem(outside); |
305 |
polygonSidesCombo.addItem(inside); |
306 |
//polygonSidesCombo.addItem(out_in_side); // Disabled because fails quite often
|
307 |
polygonSidesCombo.setToolTipText(PluginServices.getText(null, "polygonSideLabel_TOOLTIP_HTML_explanation")); |
308 |
} |
309 |
|
310 |
return polygonSidesCombo;
|
311 |
} |
312 |
|
313 |
private JPanel getLineSidePanel() { |
314 |
if (lineSidePanel == null) { |
315 |
lineSidePanel = new JPanel(); |
316 |
lineSidePanel.setPreferredSize(new Dimension(336, 28)); |
317 |
lineSidePanel.add(getLineSideLabel()); |
318 |
lineSidePanel.add(getLineSidesCombo()); |
319 |
} |
320 |
|
321 |
return lineSidePanel;
|
322 |
} |
323 |
|
324 |
private JLabel getLineSideLabel() { |
325 |
if (lineSideLabel == null) { |
326 |
lineSideLabel = new JLabel(PluginServices.getText(lineSideLabel, "Line")); |
327 |
lineSideLabel.setPreferredSize(new Dimension(90, 22)); |
328 |
lineSideLabel.setToolTipText(PluginServices.getText(null, "lineSideLabel_TOOLTIP_HTML_explanation")); |
329 |
} |
330 |
|
331 |
return lineSideLabel;
|
332 |
} |
333 |
|
334 |
private JComboBox getLineSidesCombo() { |
335 |
if (lineSidesCombo == null) { |
336 |
lineSidesCombo = new JComboBox(); |
337 |
lineSidesCombo.setPreferredSize(new Dimension(230, 22)); |
338 |
lineSidesCombo.addItem(outside); |
339 |
lineSidesCombo.setToolTipText(PluginServices.getText(null, "lineSideLabel_TOOLTIP_HTML_explanation")); |
340 |
//lineSidesCombo.setEnabled(false);
|
341 |
} |
342 |
|
343 |
return lineSidesCombo;
|
344 |
} |
345 |
|
346 |
private JPanel getPointSidePanel() { |
347 |
if (pointSidePanel == null) { |
348 |
pointSidePanel = new JPanel(); |
349 |
pointSidePanel.setPreferredSize(new Dimension(336, 28)); |
350 |
pointSidePanel.add(getPointSideLabel()); |
351 |
pointSidePanel.add(getPointSidesCombo()); |
352 |
} |
353 |
|
354 |
return pointSidePanel;
|
355 |
} |
356 |
|
357 |
private JLabel getPointSideLabel() { |
358 |
if (pointSideLabel == null) { |
359 |
pointSideLabel = new JLabel(PluginServices.getText(pointSideLabel, "Point")); |
360 |
pointSideLabel.setPreferredSize(new Dimension(90, 22)); |
361 |
pointSideLabel.setToolTipText(PluginServices.getText(null, "pointSideLabel_TOOLTIP_HTML_explanation")); |
362 |
} |
363 |
|
364 |
return pointSideLabel;
|
365 |
} |
366 |
|
367 |
private JComboBox getPointSidesCombo() { |
368 |
if (pointSidesCombo == null) { |
369 |
pointSidesCombo = new JComboBox(); |
370 |
pointSidesCombo.setPreferredSize(new Dimension(230, 22)); |
371 |
pointSidesCombo.addItem(outside); |
372 |
pointSidesCombo.setToolTipText(PluginServices.getText(null, "pointSideLabel_TOOLTIP_HTML_explanation")); |
373 |
//pointSidesCombo.setEnabled(false);
|
374 |
} |
375 |
|
376 |
return pointSidesCombo;
|
377 |
} |
378 |
|
379 |
private JPanel getMultiPointSidePanel() { |
380 |
if (multiPointSidePanel == null) { |
381 |
multiPointSidePanel = new JPanel(); |
382 |
multiPointSidePanel.setPreferredSize(new Dimension(336, 28)); |
383 |
multiPointSidePanel.add(getMultiPointSideLabel()); |
384 |
multiPointSidePanel.add(getMultiPointSidesCombo()); |
385 |
} |
386 |
|
387 |
return multiPointSidePanel;
|
388 |
} |
389 |
|
390 |
private JLabel getMultiPointSideLabel() { |
391 |
if (multiPointSideLabel == null) { |
392 |
multiPointSideLabel = new JLabel(PluginServices.getText(multiPointSideLabel, "MultiPoint")); |
393 |
multiPointSideLabel.setPreferredSize(new Dimension(90, 22)); |
394 |
multiPointSideLabel.setToolTipText(PluginServices.getText(null, "multiPointSideLabel_TOOLTIP_HTML_explanation")); |
395 |
} |
396 |
|
397 |
return multiPointSideLabel;
|
398 |
} |
399 |
|
400 |
|
401 |
private JComboBox getMultiPointSidesCombo() { |
402 |
if (multiPointSidesCombo == null) { |
403 |
multiPointSidesCombo = new JComboBox(); |
404 |
multiPointSidesCombo.setPreferredSize(new Dimension(230, 22)); |
405 |
multiPointSidesCombo.addItem(outside); |
406 |
multiPointSidesCombo.setToolTipText(PluginServices.getText(null, "multiPointSideLabel_TOOLTIP_HTML_explanation")); |
407 |
//multiPointSidesCombo.setEnabled(false);
|
408 |
} |
409 |
|
410 |
return multiPointSidesCombo;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* <p>
|
415 |
* This method initializes acceptCancelPanel.
|
416 |
* </p>
|
417 |
*
|
418 |
* @return an adapted {@link AcceptCancelPanel AcceptCancelPanel}
|
419 |
*/
|
420 |
private AdaptedAcceptCancelPanel getAdaptedAcceptCancelPanel() {
|
421 |
if (acceptCancelPanel == null) { |
422 |
acceptCancelPanel = new AdaptedAcceptCancelPanel();
|
423 |
} |
424 |
|
425 |
return acceptCancelPanel;
|
426 |
} |
427 |
|
428 |
/*
|
429 |
* (non-Javadoc)
|
430 |
*
|
431 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
432 |
*/
|
433 |
public WindowInfo getWindowInfo() {
|
434 |
if (viewInfo == null) { |
435 |
viewInfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
436 |
viewInfo.setTitle(PluginServices.getText(this, "configuration")); |
437 |
viewInfo.setWidth(Window_Width); |
438 |
viewInfo.setHeight(Window_Height); |
439 |
} |
440 |
|
441 |
return viewInfo;
|
442 |
} |
443 |
|
444 |
/**
|
445 |
* <p>
|
446 |
* Adapts {@link AcceptCancelPanel AcceptCancelPanel} to be used as a
|
447 |
* component of the <code>BufferConfigurationPanel</code> panel.
|
448 |
* </p>
|
449 |
*
|
450 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
451 |
*/
|
452 |
private class AdaptedAcceptCancelPanel extends AcceptCancelPanel { |
453 |
|
454 |
public AdaptedAcceptCancelPanel() {
|
455 |
super();
|
456 |
|
457 |
addOkButtonActionListener(getOKAction()); |
458 |
addCancelButtonActionListener(getCancelAction()); |
459 |
setPreferredSize(new Dimension(350, 30)); |
460 |
} |
461 |
|
462 |
/**
|
463 |
* <p>
|
464 |
* Create the action that will be executed when user pressed the <i>ok</i>
|
465 |
* button.
|
466 |
* </p>
|
467 |
*
|
468 |
* @return action that will be executed when user pressed the <i>cancel</i>
|
469 |
* button
|
470 |
*/
|
471 |
private ActionListener getOKAction() { |
472 |
// OK button action
|
473 |
return new ActionListener() { |
474 |
/*
|
475 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
476 |
*/
|
477 |
public void actionPerformed(ActionEvent e) { |
478 |
/* 1- Closes this window */
|
479 |
closeThis(); |
480 |
|
481 |
/* 2- Validates the buffer width */
|
482 |
double width;
|
483 |
|
484 |
try {
|
485 |
width = Double.parseDouble(getWidthTextField().getText().replaceAll("(\\.)?", "").replace(",", ".")); // Formats the decimal number to be parsed |
486 |
} |
487 |
catch (Exception ex) { |
488 |
NotificationManager.showMessageError(PluginServices.getText(null, "Invalid_width"), ex); |
489 |
return;
|
490 |
} |
491 |
|
492 |
/* 3- Creates the process */
|
493 |
// checks layers to proccess if multilayer is not selected
|
494 |
ArrayList tmpLayersToProccess = new ArrayList(layers.length); |
495 |
tmpLayersToProccess.addAll(Arrays.asList(layers));
|
496 |
if (!multiLayerSelectionCBox.isSelected()){
|
497 |
Iterator iter = tmpLayersToProccess.iterator();
|
498 |
FLyrVect curLayer; |
499 |
while (iter.hasNext()){
|
500 |
curLayer = (FLyrVect) iter.next(); |
501 |
try {
|
502 |
if (curLayer.getRecordset().getSelection().cardinality() == 0 ){ |
503 |
iter.remove(); |
504 |
} |
505 |
} catch (ReadDriverException e1) {
|
506 |
NotificationManager.showMessageError(PluginServices.getText(null, "Failed_selecting_layer"), e1); |
507 |
return;
|
508 |
|
509 |
} |
510 |
} |
511 |
} |
512 |
FLyrVect[] layersToProcess = (FLyrVect[]) tmpLayersToProccess.toArray(new FLyrVect[tmpLayersToProccess.size()]); |
513 |
|
514 |
BufferSelectionProcess iprocess = new BufferSelectionProcess(PluginServices.getText(this, "Selection_by_buffer_process"), PluginServices.getText(this, "Ongoing_process_please_wait"), mapControl, ((SideInfo)getPolygonSidesCombo().getSelectedItem()).getSide(), ((SideInfo)getLineSidesCombo().getSelectedItem()).getSide(), ((SideInfo)getPointSidesCombo().getSelectedItem()).getSide(), ((SideInfo)getMultiPointSidesCombo().getSelectedItem()).getSide(), width, (short)getDistanceUnitsCombo().getSelectedIndex(), layersToProcess, getAddInfluenceAreaLayersCBox().isSelected(), getMultiLayerSelectionCBox().isSelected());//getAddBufferLayersCBox().isSelected(), getAddInfluenceAreaLayersCBox().isSelected(), getMultiLayerSelectionCBox().isSelected()); |
515 |
IncrementableTask iTask = new IncrementableTask(iprocess, new ProgressPanel(false)); |
516 |
iTask.addIncrementableListener(iprocess); |
517 |
iprocess.setIncrementableTask(iTask); |
518 |
final BufferSelectionProcess f_iprocess = iprocess;
|
519 |
final IncrementableTask f_iTask = iTask;
|
520 |
|
521 |
iTask.getProgressPanel().addComponentListener(new ComponentAdapter() { |
522 |
/*
|
523 |
* (non-Javadoc)
|
524 |
* @see java.awt.event.ComponentAdapter#componentHidden(java.awt.event.ComponentEvent)
|
525 |
*/
|
526 |
public void componentHidden(ComponentEvent e) { |
527 |
/* 5- If the process has failed, tries to reload the layers */
|
528 |
if (f_iprocess.getPercent() < 100) { |
529 |
/* 5.1- Forces to reload the active layers */
|
530 |
mapControl.drawMap(false);
|
531 |
f_iTask.getProgressPanel().dispose(); |
532 |
|
533 |
for (int i = 0; i < layers.length; i++) { |
534 |
try {
|
535 |
layers[i].reload(); |
536 |
} |
537 |
catch(Exception ex) { |
538 |
try {
|
539 |
NotificationManager.showMessageError(PluginServices.getText(null, "Failed_reloading_the_layer") + " " + layers[i].getName(), ex); |
540 |
} |
541 |
catch(Exception ex2) { |
542 |
NotificationManager.showMessageError(PluginServices.getText(null, "Undefined_layer"), ex); |
543 |
} |
544 |
} |
545 |
} |
546 |
|
547 |
// view.getTOC().setVisible(false);
|
548 |
// view.getTOC().setVisible(true);
|
549 |
} |
550 |
|
551 |
/* 6- Writes in the gvSIG log the results of the process */
|
552 |
String text = "\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n" + |
553 |
PluginServices.getText(this, "Summary_of_the_process_of_selecting_by_buffer") + ":\n" + |
554 |
f_iprocess.getLog() + |
555 |
"\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n";
|
556 |
PluginServices.getLogger().info(text); |
557 |
} |
558 |
}); |
559 |
|
560 |
/* 4- Starts the process */
|
561 |
iprocess.start(); |
562 |
iTask.start(); |
563 |
} |
564 |
}; |
565 |
} |
566 |
|
567 |
// private QuickInfoListener getQuickInfoListener() {
|
568 |
// if (qIListener == null) {
|
569 |
// qIListener = new QuickInfoListener(mapControl, infoLayerSelected,
|
570 |
// QuickInfoListener.DEFAULT_PIXEL_TOLERANCE);
|
571 |
// }
|
572 |
//
|
573 |
// return qIListener;
|
574 |
// }
|
575 |
|
576 |
/**
|
577 |
* <p>
|
578 |
* Create the action that will be executed when user pressed the
|
579 |
* <i>cancel</i> button.
|
580 |
* </p>
|
581 |
*
|
582 |
* @return action that will be executed when user pressed the <i>cancel</i>
|
583 |
* button
|
584 |
*/
|
585 |
private ActionListener getCancelAction() { |
586 |
// Cancel button action
|
587 |
return new ActionListener() { |
588 |
/*
|
589 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
590 |
*/
|
591 |
public void actionPerformed(ActionEvent e) { |
592 |
closeThis(); |
593 |
} |
594 |
}; |
595 |
} |
596 |
} |
597 |
|
598 |
/**
|
599 |
* <p>
|
600 |
* Closes this window.
|
601 |
* </p>
|
602 |
*/
|
603 |
private void closeThis() { |
604 |
PluginServices.getMDIManager().closeWindow(this);
|
605 |
} |
606 |
|
607 |
/**
|
608 |
*
|
609 |
*
|
610 |
*
|
611 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
612 |
*/
|
613 |
private class SideInfo { |
614 |
private byte side; |
615 |
private String name; |
616 |
|
617 |
public SideInfo(byte side, String name) { |
618 |
this.side = side;
|
619 |
this.name = name;
|
620 |
} |
621 |
|
622 |
public String toString() { |
623 |
return name;
|
624 |
} |
625 |
|
626 |
public String getName() { |
627 |
return name;
|
628 |
} |
629 |
|
630 |
public byte getSide() { |
631 |
return side;
|
632 |
} |
633 |
} |
634 |
|
635 |
public Object getWindowProfile() { |
636 |
return WindowInfo.DIALOG_PROFILE;
|
637 |
} |
638 |
} |