gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.lateralbuffer / src / main / java / org / gvsig / geoprocess / algorithm / lateralbuffer / LateralBufferParametersPanel.java @ 1082
History | View | Annotate | Download (16.7 KB)
1 | 433 | nbrodin | /**
|
---|---|---|---|
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.lateralbuffer; |
||
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 lateral buffer algorithm
|
||
63 | * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
||
64 | */
|
||
65 | public class LateralBufferParametersPanel 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 radialBuffers = null; |
||
73 | private JPanel concentricalRingsPanel = null; |
||
74 | private JComboBox lateralSelectionCombo = null; |
||
75 | private JPanel lateralSelectionPanel = null; |
||
76 | private JCheckBox selectionOnly = null; |
||
77 | 438 | nbrodin | private JCheckBox dissolveEntities = null; |
78 | private JCheckBox roundBorder = null; |
||
79 | 433 | nbrodin | private JTextField distance = null; |
80 | private JRadioButton selectDistance = null; |
||
81 | private JRadioButton selectField = null; |
||
82 | |||
83 | private List<String> fieldList = new ArrayList<String>(); |
||
84 | private AlgorithmOutputPanel algorithmOutputPanel = null; |
||
85 | private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
||
86 | private JPanel outputPanel; |
||
87 | |||
88 | public LateralBufferParametersPanel() {
|
||
89 | super();
|
||
90 | } |
||
91 | |||
92 | public void init(GeoAlgorithm algorithm) { |
||
93 | m_Algorithm = algorithm; |
||
94 | initGUI(); |
||
95 | } |
||
96 | |||
97 | private void initGUI() { |
||
98 | this.setLayout(new BorderLayout()); |
||
99 | this.add(getMainJScrollPane(), BorderLayout.CENTER); |
||
100 | } |
||
101 | |||
102 | private JScrollPane getMainJScrollPane() { |
||
103 | JPanel panel = new JPanel(); |
||
104 | GridBagLayout gbl = new GridBagLayout(); |
||
105 | panel.setLayout(gbl); |
||
106 | |||
107 | GridBagConstraints gbc = new GridBagConstraints(); |
||
108 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
109 | gbc.weightx = 1.0;
|
||
110 | gbc.gridx = 0;
|
||
111 | gbc.gridy = 0;
|
||
112 | gbc.insets = new Insets(0, marginSides, 0, marginSides); |
||
113 | panel.add(getInputPanel(), gbc); |
||
114 | |||
115 | gbc.gridy = 1;
|
||
116 | panel.add(getOptionsPanel(), gbc); |
||
117 | |||
118 | gbc.gridy = 2;
|
||
119 | panel.add(getOutputsPanel(), gbc); |
||
120 | JScrollPane scrollPane = new JScrollPane(panel); |
||
121 | return scrollPane;
|
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * Gets the output panel (SEXTANTE)
|
||
126 | * @return
|
||
127 | */
|
||
128 | private JPanel getOutputChannelSelectionPanel() { |
||
129 | if(outputPanel == null) { |
||
130 | try {
|
||
131 | outputPanel = new JPanel(); |
||
132 | outputPanel.setLayout(new BorderLayout()); |
||
133 | final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
||
134 | final Output out = ooSet.getOutput(LateralBufferAlgorithm.RESULT);
|
||
135 | outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
||
136 | 639 | jjdelcerro | outputPanel.add(new JLabel(" " + GeoProcessLocator.getGeoProcessManager().getTranslation("lateral_buffer") + |
137 | " [" + GeoProcessLocator.getGeoProcessManager().getTranslation("Vectorial") + |
||
138 | "] "), BorderLayout.WEST); |
||
139 | 433 | nbrodin | outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
|
140 | } catch (final Exception e) { |
||
141 | Sextante.addErrorToLog(e); |
||
142 | } |
||
143 | } |
||
144 | return outputPanel;
|
||
145 | } |
||
146 | |||
147 | /**
|
||
148 | * Gets the output panel
|
||
149 | * @return
|
||
150 | */
|
||
151 | @SuppressWarnings("unused") |
||
152 | private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
||
153 | if(algorithmOutputPanel == null) |
||
154 | algorithmOutputPanel = new AlgorithmOutputPanel();
|
||
155 | return algorithmOutputPanel;
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * Gets a new input panel
|
||
160 | * @param text
|
||
161 | * @param combo
|
||
162 | * @return
|
||
163 | */
|
||
164 | public JPanel getOutputsPanel() { |
||
165 | JPanel panel = new JPanel(); |
||
166 | GridBagLayout gbl = new GridBagLayout(); |
||
167 | panel.setLayout(gbl); |
||
168 | panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("outputs"))); |
||
169 | |||
170 | GridBagConstraints gbc = new GridBagConstraints(); |
||
171 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
172 | gbc.weightx = 1.0;
|
||
173 | gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
||
174 | panel.add(getOutputChannelSelectionPanel(), gbc); |
||
175 | |||
176 | return panel;
|
||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * Gets a new input panel
|
||
181 | * @param text
|
||
182 | * @param combo
|
||
183 | * @return
|
||
184 | */
|
||
185 | public JPanel getInputPanel() { |
||
186 | JPanel panel = new JPanel(); |
||
187 | GridBagLayout gbl = new GridBagLayout(); |
||
188 | panel.setLayout(gbl); |
||
189 | panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("input"))); |
||
190 | |||
191 | GridBagConstraints gbc = new GridBagConstraints(); |
||
192 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
193 | gbc.weightx = 1.0;
|
||
194 | gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
||
195 | panel.add(getComboLayers(), gbc); |
||
196 | |||
197 | return panel;
|
||
198 | } |
||
199 | |||
200 | /**
|
||
201 | * Gets a new options panel
|
||
202 | * @param text
|
||
203 | * @param combo
|
||
204 | * @return
|
||
205 | */
|
||
206 | public JPanel getOptionsPanel() { |
||
207 | JPanel panel = new JPanel(); |
||
208 | GridBagLayout gbl = new GridBagLayout(); |
||
209 | panel.setLayout(gbl); |
||
210 | panel.setBorder(BorderFactory.createTitledBorder(GeoProcessLocator.getGeoProcessManager().getTranslation("options"))); |
||
211 | |||
212 | ButtonGroup group = new ButtonGroup(); |
||
213 | group.add(getRadioSelectDistance()); |
||
214 | group.add(getRadioSelectField()); |
||
215 | |||
216 | GridBagConstraints gbc = new GridBagConstraints(); |
||
217 | gbc.fill = GridBagConstraints.HORIZONTAL;
|
||
218 | gbc.weightx = 1.0;
|
||
219 | gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
||
220 | panel.add(getRadioSelectField(), gbc); |
||
221 | |||
222 | gbc.gridy = 1;
|
||
223 | gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
||
224 | panel.add(getComboFields(), gbc); |
||
225 | |||
226 | gbc.gridy = 2;
|
||
227 | gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
||
228 | panel.add(getRadioSelectDistance(), gbc); |
||
229 | |||
230 | gbc.gridy = 3;
|
||
231 | gbc.insets = new Insets(0, marginSides + 10, marginBottom, marginSides); |
||
232 | panel.add(getTextDistance(), gbc); |
||
233 | |||
234 | gbc.gridy = 4;
|
||
235 | gbc.insets = new Insets(0, marginSides, marginBottom, marginSides); |
||
236 | panel.add(getCheckSelectedGeom(), gbc); |
||
237 | |||
238 | gbc.gridy = 5;
|
||
239 | 438 | nbrodin | panel.add(getCheckDissolveEntities(), gbc); |
240 | |||
241 | gbc.gridy = 6;
|
||
242 | //panel.add(getCheckRoundBorder(), gbc);
|
||
243 | |||
244 | gbc.gridy = 7;
|
||
245 | 433 | nbrodin | panel.add(getLateralSelectionPanel(), gbc); |
246 | |||
247 | 438 | nbrodin | gbc.gridy = 8;
|
248 | 433 | nbrodin | panel.add(getNumberOfConcentricalRingsPanel(), gbc); |
249 | 1082 | omartinez | |
250 | gbc.gridy = 9;
|
||
251 | panel.add(getIgnoreInvalidLines(), gbc); |
||
252 | 433 | nbrodin | |
253 | return panel;
|
||
254 | } |
||
255 | |||
256 | /**
|
||
257 | * Gets a ComboBox
|
||
258 | * @return
|
||
259 | */
|
||
260 | public JComboBox getComboLayers() { |
||
261 | if(layers == null) { |
||
262 | layers = new JComboBox(); |
||
263 | ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
||
264 | layers.setModel(comboModel); |
||
265 | layers.addActionListener(this);
|
||
266 | } |
||
267 | return layers;
|
||
268 | } |
||
269 | |||
270 | private JPanel getLateralSelectionPanel() { |
||
271 | if(lateralSelectionPanel == null) { |
||
272 | lateralSelectionPanel = new JPanel(); |
||
273 | BorderLayout ly = new BorderLayout(); |
||
274 | ly.setHgap(5);
|
||
275 | lateralSelectionPanel.setLayout(ly); |
||
276 | lateralSelectionPanel.add(new JLabel(GeoProcessLocator.getGeoProcessManager().getTranslation("select_lateral")), BorderLayout.WEST); |
||
277 | lateralSelectionPanel.add(getLateralSelectionCombo(), BorderLayout.CENTER);
|
||
278 | } |
||
279 | return lateralSelectionPanel;
|
||
280 | } |
||
281 | |||
282 | /**
|
||
283 | * Gets a influence areas ComboBox
|
||
284 | * @return
|
||
285 | */
|
||
286 | public JComboBox getLateralSelectionCombo() { |
||
287 | if(lateralSelectionCombo == null) { |
||
288 | lateralSelectionCombo = new JComboBox(); |
||
289 | 438 | nbrodin | lateralSelectionCombo.addItem(GeoProcessLocator.getGeoProcessManager().getTranslation("left"));
|
290 | lateralSelectionCombo.addItem(GeoProcessLocator.getGeoProcessManager().getTranslation("right"));
|
||
291 | 433 | nbrodin | lateralSelectionCombo.addActionListener(this);
|
292 | } |
||
293 | return lateralSelectionCombo;
|
||
294 | } |
||
295 | |||
296 | private JPanel getNumberOfConcentricalRingsPanel() { |
||
297 | if(concentricalRingsPanel == null) { |
||
298 | concentricalRingsPanel = new JPanel(); |
||
299 | BorderLayout ly = new BorderLayout(); |
||
300 | ly.setHgap(5);
|
||
301 | concentricalRingsPanel.setLayout(ly); |
||
302 | concentricalRingsPanel.add(new JLabel(GeoProcessLocator.getGeoProcessManager().getTranslation("concentrical_rings")), BorderLayout.WEST); |
||
303 | concentricalRingsPanel.add(getComboRadialBuffers(), BorderLayout.CENTER);
|
||
304 | } |
||
305 | return concentricalRingsPanel;
|
||
306 | } |
||
307 | |||
308 | /**
|
||
309 | * Gets a influence areas ComboBox
|
||
310 | * @return
|
||
311 | */
|
||
312 | public JComboBox getComboRadialBuffers() { |
||
313 | if(radialBuffers == null) { |
||
314 | radialBuffers = new JComboBox(); |
||
315 | radialBuffers.addItem("1");
|
||
316 | radialBuffers.addItem("2");
|
||
317 | radialBuffers.addItem("3");
|
||
318 | radialBuffers.addActionListener(this);
|
||
319 | } |
||
320 | return radialBuffers;
|
||
321 | } |
||
322 | |||
323 | /**
|
||
324 | * Gets a CheckBox
|
||
325 | * @return
|
||
326 | */
|
||
327 | public JCheckBox getCheckSelectedGeom() { |
||
328 | if(selectionOnly == null) { |
||
329 | selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries")); |
||
330 | } |
||
331 | return selectionOnly;
|
||
332 | } |
||
333 | |||
334 | /**
|
||
335 | 438 | nbrodin | * Gets a CheckBox
|
336 | * @return
|
||
337 | */
|
||
338 | public JCheckBox getCheckDissolveEntities() { |
||
339 | if(dissolveEntities == null) { |
||
340 | dissolveEntities = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Dissolve_entities")); |
||
341 | } |
||
342 | return dissolveEntities;
|
||
343 | } |
||
344 | |||
345 | /**
|
||
346 | * Gets a CheckBox
|
||
347 | * @return
|
||
348 | */
|
||
349 | public JCheckBox getCheckRoundBorder() { |
||
350 | if(roundBorder == null) { |
||
351 | roundBorder = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Round_border")); |
||
352 | } |
||
353 | return roundBorder;
|
||
354 | } |
||
355 | 1082 | omartinez | |
356 | public JCheckBox getIgnoreInvalidLines() { |
||
357 | if(roundBorder == null) { |
||
358 | roundBorder = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("ignore_invalid_lines")); |
||
359 | } |
||
360 | return roundBorder;
|
||
361 | } |
||
362 | 438 | nbrodin | /**
|
363 | 433 | nbrodin | * Gets a ComboBox
|
364 | * @return
|
||
365 | */
|
||
366 | public JComboBox getComboFields() { |
||
367 | if(fields == null) { |
||
368 | fields = new JComboBox(); |
||
369 | loadFieldsInAreaCombo(); |
||
370 | fields.setEnabled(true);
|
||
371 | } |
||
372 | return fields;
|
||
373 | } |
||
374 | |||
375 | private void loadFieldsInAreaCombo() { |
||
376 | List<String> fieldList = getFieldList(); |
||
377 | getComboFields().removeAllItems(); |
||
378 | for (int i = 0; i < fieldList.size(); i++) |
||
379 | getComboFields().addItem(fieldList.get(i)); |
||
380 | } |
||
381 | |||
382 | /**
|
||
383 | * Gets a CheckBox
|
||
384 | * @return
|
||
385 | */
|
||
386 | public JTextField getTextDistance() { |
||
387 | if(distance == null) { |
||
388 | distance = new JTextField("0.0"); |
||
389 | distance.setEnabled(false);
|
||
390 | } |
||
391 | return distance;
|
||
392 | } |
||
393 | |||
394 | /**
|
||
395 | * Gets a JRadioButton
|
||
396 | * @return
|
||
397 | */
|
||
398 | public JRadioButton getRadioSelectDistance() { |
||
399 | if(selectDistance == null) { |
||
400 | selectDistance = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_distance")); |
||
401 | selectDistance.addActionListener(this);
|
||
402 | selectDistance.setSelected(false);
|
||
403 | } |
||
404 | return selectDistance;
|
||
405 | } |
||
406 | |||
407 | /**
|
||
408 | * Gets a JRadioButton
|
||
409 | * @return
|
||
410 | */
|
||
411 | public JRadioButton getRadioSelectField() { |
||
412 | if(selectField == null) { |
||
413 | selectField = new JRadioButton(GeoProcessLocator.getGeoProcessManager().getTranslation("area_field")); |
||
414 | selectField.addActionListener(this);
|
||
415 | selectField.setSelected(true);
|
||
416 | } |
||
417 | return selectField;
|
||
418 | } |
||
419 | |||
420 | //------------------------------------------------------------
|
||
421 | |||
422 | /*
|
||
423 | * (non-Javadoc)
|
||
424 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
||
425 | */
|
||
426 | public void actionPerformed(ActionEvent e) { |
||
427 | if(e.getSource() == getRadioSelectDistance()) {
|
||
428 | getTextDistance().setEnabled(true);
|
||
429 | getComboFields().setEnabled(false);
|
||
430 | } |
||
431 | |||
432 | if(e.getSource() == getRadioSelectField()) {
|
||
433 | getTextDistance().setEnabled(false);
|
||
434 | getTextDistance().setText("0.0");
|
||
435 | getComboFields().setEnabled(true);
|
||
436 | } |
||
437 | |||
438 | if(e.getSource() == getComboLayers()) {
|
||
439 | loadFieldsInAreaCombo(); |
||
440 | } |
||
441 | } |
||
442 | |||
443 | |||
444 | |||
445 | @Override
|
||
446 | public void assignParameters() { |
||
447 | try {
|
||
448 | ParametersSet params = m_Algorithm.getParameters(); |
||
449 | params.getParameter(LateralBufferAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
||
450 | params.getParameter(LateralBufferAlgorithm.FIELD).setParameterValue(getFieldPosition()); |
||
451 | params.getParameter(LateralBufferAlgorithm.SELECTED_GEOM).setParameterValue(getCheckSelectedGeom().isSelected()); |
||
452 | double dist = 0; |
||
453 | try {
|
||
454 | dist = new Double(getTextDistance().getText()); |
||
455 | } catch(NumberFormatException e) { |
||
456 | } |
||
457 | params.getParameter(LateralBufferAlgorithm.DISTANCE).setParameterValue(dist); |
||
458 | 438 | nbrodin | params.getParameter(LateralBufferAlgorithm.DISSOLVE).setParameterValue(getCheckDissolveEntities().isSelected()); |
459 | params.getParameter(LateralBufferAlgorithm.ROUND_BORDER).setParameterValue(getCheckRoundBorder().isSelected()); |
||
460 | 433 | nbrodin | params.getParameter(LateralBufferAlgorithm.RING_NUMBER).setParameterValue(getComboRadialBuffers().getSelectedIndex()); |
461 | params.getParameter(LateralBufferAlgorithm.LATERAL).setParameterValue(getLateralSelectionCombo().getSelectedIndex()); |
||
462 | 1082 | omartinez | params.getParameter(LateralBufferAlgorithm.IGNOREINVALIDLINES).setParameterValue(getIgnoreInvalidLines().isSelected()); |
463 | |||
464 | 433 | nbrodin | OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
465 | Output out = ooSet.getOutput(LateralBufferAlgorithm.RESULT); |
||
466 | |||
467 | //Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
|
||
468 | //AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
|
||
469 | //out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
|
||
470 | out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
||
471 | } catch (Exception e) { |
||
472 | Sextante.addErrorToLog(e); |
||
473 | } |
||
474 | } |
||
475 | |||
476 | |||
477 | |||
478 | @Override
|
||
479 | public void setOutputValue(String arg0, String arg1) { |
||
480 | |||
481 | } |
||
482 | |||
483 | @Override
|
||
484 | public void setParameterValue(String arg0, String arg1) { |
||
485 | |||
486 | } |
||
487 | |||
488 | /**
|
||
489 | * Gets the input layer list
|
||
490 | * @return
|
||
491 | */
|
||
492 | private ObjectAndDescription[] getLayerList() { |
||
493 | IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
||
494 | .getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
||
495 | ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
||
496 | for (int i = 0; i < layers.length; i++) |
||
497 | oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
||
498 | return oad;
|
||
499 | } |
||
500 | |||
501 | /**
|
||
502 | * Gets the selected vector layer in the JComboBox
|
||
503 | * @return
|
||
504 | */
|
||
505 | private IVectorLayer getSelectedVectorLayer() {
|
||
506 | if(layers.getSelectedItem() != null) |
||
507 | return (IVectorLayer)((ObjectAndDescription)layers.getSelectedItem()).getObject();
|
||
508 | return null; |
||
509 | } |
||
510 | |||
511 | /**
|
||
512 | * Gets the field list of the selected layer
|
||
513 | * @return
|
||
514 | */
|
||
515 | public List<String> getFieldList() { |
||
516 | IVectorLayer layer = getSelectedVectorLayer(); |
||
517 | List<String> data = new ArrayList<String>(); |
||
518 | fieldList.clear(); |
||
519 | for (int i = 0; i < layer.getFieldCount(); i++) { |
||
520 | Class type = layer.getFieldType(i);
|
||
521 | fieldList.add(layer.getFieldName(i)); |
||
522 | if(Number.class.isAssignableFrom(type)) |
||
523 | data.add(layer.getFieldName(i)); |
||
524 | } |
||
525 | return data;
|
||
526 | } |
||
527 | |||
528 | private int getFieldPosition() { |
||
529 | if(getComboFields().getSelectedItem() != null) { |
||
530 | String label = getComboFields().getSelectedItem().toString();
|
||
531 | for (int i = 0; i < fieldList.size(); i++) { |
||
532 | if(fieldList.get(i).equals(label)) {
|
||
533 | return i;
|
||
534 | } |
||
535 | } |
||
536 | } |
||
537 | return -1; |
||
538 | } |
||
539 | } |