gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.buffer / src / main / java / org / gvsig / geoprocess / algorithm / buffer / BufferParametersPanel.java @ 351
History | View | Annotate | Download (14.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geoprocess.algorithm.buffer; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.GridBagConstraints; |
28 |
import java.awt.GridBagLayout; |
29 |
import java.awt.Insets; |
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.util.ArrayList; |
33 |
import java.util.List; |
34 |
|
35 |
import javax.swing.BorderFactory; |
36 |
import javax.swing.ButtonGroup; |
37 |
import javax.swing.ComboBoxModel; |
38 |
import javax.swing.DefaultComboBoxModel; |
39 |
import javax.swing.JCheckBox; |
40 |
import javax.swing.JComboBox; |
41 |
import javax.swing.JLabel; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JRadioButton; |
44 |
import javax.swing.JScrollPane; |
45 |
import javax.swing.JTextField; |
46 |
|
47 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
48 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
49 |
|
50 |
import es.unex.sextante.core.GeoAlgorithm; |
51 |
import es.unex.sextante.core.ObjectAndDescription; |
52 |
import es.unex.sextante.core.OutputObjectsSet; |
53 |
import es.unex.sextante.core.ParametersSet; |
54 |
import es.unex.sextante.core.Sextante; |
55 |
import es.unex.sextante.dataObjects.IVectorLayer; |
56 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
57 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
58 |
import es.unex.sextante.gui.core.SextanteGUI; |
59 |
import es.unex.sextante.outputs.Output; |
60 |
|
61 |
/**
|
62 |
* Panel for buffer algorithm
|
63 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
64 |
*/
|
65 |
public class BufferParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
66 |
private static final long serialVersionUID = 1L; |
67 |
private final int marginSides = 15; |
68 |
private final int marginBottom = 8; |
69 |
private GeoAlgorithm m_Algorithm = null; |
70 |
private JComboBox layers = null; |
71 |
private JComboBox fields = null; |
72 |
private JComboBox influenceAreas = null; |
73 |
private JComboBox radialBuffers = null; |
74 |
private JCheckBox selectionOnly = null; |
75 |
private JCheckBox dissolveEntities = null; |
76 |
private JCheckBox roundBorder = null; |
77 |
private JTextField distance = null; |
78 |
private JRadioButton selectDistance = null; |
79 |
private JRadioButton selectField = null; |
80 |
|
81 |
private List<String> fieldList = new ArrayList<String>(); |
82 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
83 |
private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
84 |
private JPanel outputPanel; |
85 |
|
86 |
public BufferParametersPanel() {
|
87 |
super();
|
88 |
} |
89 |
|
90 |
public void init(GeoAlgorithm algorithm) { |
91 |
m_Algorithm = algorithm; |
92 |
initGUI(); |
93 |
} |
94 |
|
95 |
private void initGUI() { |
96 |
this.setLayout(new BorderLayout()); |
97 |
this.add(getMainJScrollPane(), BorderLayout.CENTER); |
98 |
} |
99 |
|
100 |
private JScrollPane getMainJScrollPane() { |
101 |
JPanel panel = new JPanel(); |
102 |
GridBagLayout gbl = new GridBagLayout(); |
103 |
panel.setLayout(gbl); |
104 |
|
105 |
GridBagConstraints gbc = new GridBagConstraints(); |
106 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
107 |
gbc.weightx = 1.0;
|
108 |
gbc.gridx = 0;
|
109 |
gbc.gridy = 0;
|
110 |
gbc.insets = new Insets(0, marginSides, 0, marginSides); |
111 |
panel.add(getInputPanel(), gbc); |
112 |
|
113 |
gbc.gridy = 1;
|
114 |
panel.add(getOptionsPanel(), gbc); |
115 |
|
116 |
gbc.gridy = 2;
|
117 |
panel.add(getOutputsPanel(), gbc); |
118 |
JScrollPane scrollPane = new JScrollPane(panel); |
119 |
return scrollPane;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Gets the output panel (SEXTANTE)
|
124 |
* @return
|
125 |
*/
|
126 |
private JPanel getOutputChannelSelectionPanel() { |
127 |
if(outputPanel == null) { |
128 |
try {
|
129 |
outputPanel = new JPanel(); |
130 |
outputPanel.setLayout(new BorderLayout()); |
131 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
132 |
final Output out = ooSet.getOutput(BufferAlgorithm.RESULT);
|
133 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
134 |
outputPanel.add(new JLabel(" Buffer [Vectorial] "), BorderLayout.WEST); |
135 |
outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
|
136 |
} catch (final Exception e) { |
137 |
Sextante.addErrorToLog(e); |
138 |
} |
139 |
} |
140 |
return outputPanel;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Gets the output panel
|
145 |
* @return
|
146 |
*/
|
147 |
@SuppressWarnings("unused") |
148 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
149 |
if(algorithmOutputPanel == null) |
150 |
algorithmOutputPanel = new AlgorithmOutputPanel();
|
151 |
return algorithmOutputPanel;
|
152 |
} |
153 |
|
154 |
/**
|
155 |
* Gets a new input panel
|
156 |
* @param text
|
157 |
* @param combo
|
158 |
* @return
|
159 |
*/
|
160 |
public JPanel getOutputsPanel() { |
161 |
JPanel panel = new JPanel(); |
162 |
GridBagLayout gbl = new GridBagLayout(); |
163 |
panel.setLayout(gbl); |
164 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("outputs"))); |
165 |
|
166 |
GridBagConstraints gbc = new GridBagConstraints(); |
167 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
168 |
gbc.weightx = 1.0;
|
169 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
170 |
panel.add(getOutputChannelSelectionPanel(), gbc); |
171 |
|
172 |
return panel;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Gets a new input panel
|
177 |
* @param text
|
178 |
* @param combo
|
179 |
* @return
|
180 |
*/
|
181 |
public JPanel getInputPanel() { |
182 |
JPanel panel = new JPanel(); |
183 |
GridBagLayout gbl = new GridBagLayout(); |
184 |
panel.setLayout(gbl); |
185 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("input"))); |
186 |
|
187 |
GridBagConstraints gbc = new GridBagConstraints(); |
188 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
189 |
gbc.weightx = 1.0;
|
190 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
191 |
panel.add(getComboLayers(), gbc); |
192 |
|
193 |
return panel;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* Gets a new options panel
|
198 |
* @param text
|
199 |
* @param combo
|
200 |
* @return
|
201 |
*/
|
202 |
public JPanel getOptionsPanel() { |
203 |
JPanel panel = new JPanel(); |
204 |
GridBagLayout gbl = new GridBagLayout(); |
205 |
panel.setLayout(gbl); |
206 |
panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("options"))); |
207 |
|
208 |
ButtonGroup group = new ButtonGroup(); |
209 |
group.add(getRadioSelectDistance()); |
210 |
group.add(getRadioSelectField()); |
211 |
|
212 |
GridBagConstraints gbc = new GridBagConstraints(); |
213 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
214 |
gbc.weightx = 1.0;
|
215 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
216 |
panel.add(getRadioSelectField(), gbc); |
217 |
|
218 |
gbc.gridy = 1;
|
219 |
gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
220 |
panel.add(getComboFields(), gbc); |
221 |
|
222 |
gbc.gridy = 2;
|
223 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
224 |
panel.add(getRadioSelectDistance(), gbc); |
225 |
|
226 |
gbc.gridy = 3;
|
227 |
gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
228 |
panel.add(getTextDistance(), gbc); |
229 |
|
230 |
gbc.gridy = 4;
|
231 |
gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
232 |
panel.add(getCheckSelectedGeom(), gbc); |
233 |
|
234 |
gbc.gridy = 5;
|
235 |
panel.add(getCheckDissolveEntities(), gbc); |
236 |
|
237 |
gbc.gridy = 6;
|
238 |
panel.add(getCheckRoundBorder(), gbc); |
239 |
|
240 |
gbc.gridy = 7;
|
241 |
panel.add(getComboInfluenceAreas(), gbc); |
242 |
|
243 |
gbc.gridy = 8;
|
244 |
panel.add(getComboRadialBuffers(), gbc); |
245 |
|
246 |
return panel;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* Gets a ComboBox
|
251 |
* @return
|
252 |
*/
|
253 |
public JComboBox getComboLayers() { |
254 |
if(layers == null) { |
255 |
layers = new JComboBox(); |
256 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
257 |
layers.setModel(comboModel); |
258 |
layers.addActionListener(this);
|
259 |
} |
260 |
return layers;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* Gets a influence areas ComboBox
|
265 |
* @return
|
266 |
*/
|
267 |
public JComboBox getComboInfluenceAreas() { |
268 |
if(influenceAreas == null) { |
269 |
influenceAreas = new JComboBox(); |
270 |
for (int i = 0; i < BufferAlgorithm.sOptions.length; i++) { |
271 |
influenceAreas.addItem(BufferAlgorithm.sOptions[i]); |
272 |
} |
273 |
influenceAreas.addActionListener(this);
|
274 |
} |
275 |
return influenceAreas;
|
276 |
} |
277 |
|
278 |
/**
|
279 |
* Gets a influence areas ComboBox
|
280 |
* @return
|
281 |
*/
|
282 |
public JComboBox getComboRadialBuffers() { |
283 |
if(radialBuffers == null) { |
284 |
radialBuffers = new JComboBox(); |
285 |
radialBuffers.addItem("1");
|
286 |
radialBuffers.addItem("2");
|
287 |
radialBuffers.addItem("3");
|
288 |
radialBuffers.addActionListener(this);
|
289 |
} |
290 |
return radialBuffers;
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* Gets a CheckBox
|
295 |
* @return
|
296 |
*/
|
297 |
public JCheckBox getCheckSelectedGeom() { |
298 |
if(selectionOnly == null) { |
299 |
selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries")); |
300 |
} |
301 |
return selectionOnly;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* Gets a CheckBox
|
306 |
* @return
|
307 |
*/
|
308 |
public JCheckBox getCheckDissolveEntities() { |
309 |
if(dissolveEntities == null) { |
310 |
dissolveEntities = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Dissolve_entities")); |
311 |
} |
312 |
return dissolveEntities;
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Gets a CheckBox
|
317 |
* @return
|
318 |
*/
|
319 |
public JCheckBox getCheckRoundBorder() { |
320 |
if(roundBorder == null) { |
321 |
roundBorder = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Round_border")); |
322 |
} |
323 |
return roundBorder;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* Gets a ComboBox
|
328 |
* @return
|
329 |
*/
|
330 |
public JComboBox getComboFields() { |
331 |
if(fields == null) { |
332 |
fields = new JComboBox(); |
333 |
loadFieldsInAreaCombo(); |
334 |
fields.setEnabled(true);
|
335 |
} |
336 |
return fields;
|
337 |
} |
338 |
|
339 |
private void loadFieldsInAreaCombo() { |
340 |
List<String> fieldList = getFieldList(); |
341 |
getComboFields().removeAllItems(); |
342 |
for (int i = 0; i < fieldList.size(); i++) |
343 |
getComboFields().addItem(fieldList.get(i)); |
344 |
} |
345 |
|
346 |
/**
|
347 |
* Gets a CheckBox
|
348 |
* @return
|
349 |
*/
|
350 |
public JTextField getTextDistance() { |
351 |
if(distance == null) { |
352 |
distance = new JTextField("0.0"); |
353 |
distance.setEnabled(false);
|
354 |
} |
355 |
return distance;
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Gets a JRadioButton
|
360 |
* @return
|
361 |
*/
|
362 |
public JRadioButton getRadioSelectDistance() { |
363 |
if(selectDistance == null) { |
364 |
selectDistance = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_distance")); |
365 |
selectDistance.addActionListener(this);
|
366 |
selectDistance.setSelected(false);
|
367 |
} |
368 |
return selectDistance;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Gets a JRadioButton
|
373 |
* @return
|
374 |
*/
|
375 |
public JRadioButton getRadioSelectField() { |
376 |
if(selectField == null) { |
377 |
selectField = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_field")); |
378 |
selectField.addActionListener(this);
|
379 |
selectField.setSelected(true);
|
380 |
} |
381 |
return selectField;
|
382 |
} |
383 |
|
384 |
//------------------------------------------------------------
|
385 |
|
386 |
/*
|
387 |
* (non-Javadoc)
|
388 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
389 |
*/
|
390 |
public void actionPerformed(ActionEvent e) { |
391 |
if(e.getSource() == getRadioSelectDistance()) {
|
392 |
getTextDistance().setEnabled(true);
|
393 |
getComboFields().setEnabled(false);
|
394 |
} |
395 |
|
396 |
if(e.getSource() == getRadioSelectField()) {
|
397 |
getTextDistance().setEnabled(false);
|
398 |
getTextDistance().setText("0.0");
|
399 |
getComboFields().setEnabled(true);
|
400 |
} |
401 |
|
402 |
if(e.getSource() == getComboLayers()) {
|
403 |
loadFieldsInAreaCombo(); |
404 |
} |
405 |
} |
406 |
|
407 |
|
408 |
|
409 |
@Override
|
410 |
public void assignParameters() { |
411 |
try {
|
412 |
ParametersSet params = m_Algorithm.getParameters(); |
413 |
params.getParameter(BufferAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
414 |
params.getParameter(BufferAlgorithm.FIELD).setParameterValue(getFieldPosition()); |
415 |
params.getParameter(BufferAlgorithm.SELECTED_GEOM).setParameterValue(getCheckSelectedGeom().isSelected()); |
416 |
double dist = 0; |
417 |
try {
|
418 |
dist = new Double(getTextDistance().getText()); |
419 |
} catch(NumberFormatException e) { |
420 |
} |
421 |
params.getParameter(BufferAlgorithm.DISTANCE).setParameterValue(dist); |
422 |
params.getParameter(BufferAlgorithm.DISSOLVE).setParameterValue(getCheckDissolveEntities().isSelected()); |
423 |
params.getParameter(BufferAlgorithm.ROUND_BORDER).setParameterValue(getCheckRoundBorder().isSelected()); |
424 |
params.getParameter(BufferAlgorithm.AREA).setParameterValue(getComboInfluenceAreas().getSelectedIndex()); |
425 |
params.getParameter(BufferAlgorithm.RING_NUMBER).setParameterValue(getComboRadialBuffers().getSelectedIndex()); |
426 |
|
427 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
428 |
Output out = ooSet.getOutput(BufferAlgorithm.RESULT); |
429 |
|
430 |
//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
|
431 |
//AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
|
432 |
//out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
|
433 |
out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
434 |
} catch (Exception e) { |
435 |
Sextante.addErrorToLog(e); |
436 |
} |
437 |
} |
438 |
|
439 |
|
440 |
|
441 |
@Override
|
442 |
public void setOutputValue(String arg0, String arg1) { |
443 |
|
444 |
} |
445 |
|
446 |
@Override
|
447 |
public void setParameterValue(String arg0, String arg1) { |
448 |
|
449 |
} |
450 |
|
451 |
/**
|
452 |
* Gets the input layer list
|
453 |
* @return
|
454 |
*/
|
455 |
private ObjectAndDescription[] getLayerList() { |
456 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
457 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
458 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
459 |
for (int i = 0; i < layers.length; i++) |
460 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
461 |
return oad;
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* Gets the selected vector layer in the JComboBox
|
466 |
* @return
|
467 |
*/
|
468 |
private IVectorLayer getSelectedVectorLayer() {
|
469 |
if(layers.getSelectedItem() != null) |
470 |
return (IVectorLayer)((ObjectAndDescription)layers.getSelectedItem()).getObject();
|
471 |
return null; |
472 |
} |
473 |
|
474 |
/**
|
475 |
* Gets the field list of the selected layer
|
476 |
* @return
|
477 |
*/
|
478 |
@SuppressWarnings("unchecked") |
479 |
public List<String> getFieldList() { |
480 |
IVectorLayer layer = getSelectedVectorLayer(); |
481 |
List<String> data = new ArrayList<String>(); |
482 |
fieldList.clear(); |
483 |
for (int i = 0; i < layer.getFieldCount(); i++) { |
484 |
Class type = layer.getFieldType(i);
|
485 |
fieldList.add(layer.getFieldName(i)); |
486 |
if(Number.class.isAssignableFrom(type)) |
487 |
data.add(layer.getFieldName(i)); |
488 |
} |
489 |
return data;
|
490 |
} |
491 |
|
492 |
private int getFieldPosition() { |
493 |
if(getComboFields().getSelectedItem() != null) { |
494 |
String label = getComboFields().getSelectedItem().toString();
|
495 |
for (int i = 0; i < fieldList.size(); i++) { |
496 |
if(fieldList.get(i).equals(label)) {
|
497 |
return i;
|
498 |
} |
499 |
} |
500 |
} |
501 |
return -1; |
502 |
} |
503 |
} |