gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.dissolve / src / main / java / org / gvsig / geoprocess / algorithm / dissolve / DissolveParametersPanel.java @ 259
History | View | Annotate | Download (11.9 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.dissolve; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
31 |
import java.awt.event.ActionEvent; |
32 |
import java.awt.event.ActionListener; |
33 |
|
34 |
import javax.swing.ComboBoxModel; |
35 |
import javax.swing.DefaultComboBoxModel; |
36 |
import javax.swing.JCheckBox; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JLabel; |
39 |
import javax.swing.JPanel; |
40 |
|
41 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
42 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
43 |
import org.gvsig.gui.beans.table.TableContainer; |
44 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
45 |
|
46 |
import es.unex.sextante.core.GeoAlgorithm; |
47 |
import es.unex.sextante.core.ObjectAndDescription; |
48 |
import es.unex.sextante.core.OutputObjectsSet; |
49 |
import es.unex.sextante.core.ParametersSet; |
50 |
import es.unex.sextante.core.Sextante; |
51 |
import es.unex.sextante.dataObjects.IVectorLayer; |
52 |
import es.unex.sextante.gridCalculus.gridCalculator.GridCalculatorAlgorithm; |
53 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
54 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
55 |
import es.unex.sextante.gui.core.SextanteGUI; |
56 |
import es.unex.sextante.outputs.Output; |
57 |
|
58 |
/**
|
59 |
* Panel for dissolve algorithm
|
60 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
61 |
*/
|
62 |
public class DissolveParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
63 |
private static final long serialVersionUID = 1L; |
64 |
private GeoAlgorithm m_Algorithm = null; |
65 |
private JComboBox layersCombo = null; |
66 |
private JComboBox fieldsCombo = null; |
67 |
private JCheckBox selectionOnly = null; |
68 |
private JCheckBox adjacentOnly = null; |
69 |
//private AlgorithmOutputPanel output = null;
|
70 |
private final String[] columnNames = { "Min", "Max", "Sum", "Avg", "Field ID" }; |
71 |
private final int[] columnWidths = { 35, 35, 35, 35, 334 }; |
72 |
private TableContainer table = null; |
73 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
74 |
private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
75 |
private JPanel outputPanel; |
76 |
|
77 |
public DissolveParametersPanel() {
|
78 |
super();
|
79 |
} |
80 |
|
81 |
public void init(GeoAlgorithm algorithm) { |
82 |
m_Algorithm = algorithm; |
83 |
initGUI(); |
84 |
} |
85 |
|
86 |
private void initGUI() { |
87 |
GridBagLayout gbl = new GridBagLayout(); |
88 |
this.setLayout(gbl);
|
89 |
|
90 |
GridBagConstraints gbc = new GridBagConstraints(); |
91 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
92 |
gbc.weightx = 1.0;
|
93 |
gbc.gridx = 0;
|
94 |
gbc.gridy = 0;
|
95 |
gbc.insets = new Insets(0, 0, 8, 0); |
96 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("Input_layer"), getLayersCombo()), gbc); |
97 |
|
98 |
gbc.gridy = 1;
|
99 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("Field"), getFieldsCombo()), gbc); |
100 |
|
101 |
gbc.gridy = 2;
|
102 |
this.add(getSelectionCheck(), gbc);
|
103 |
|
104 |
gbc.gridy = 3;
|
105 |
this.add(getAdjacentCheck(), gbc);
|
106 |
|
107 |
gbc.gridy = 4;
|
108 |
this.add(new JLabel(GeoProcessLocator.getGeoProcessManager().getTranslation("summary_function")), gbc); |
109 |
|
110 |
gbc.gridy = 5;
|
111 |
gbc.fill = GridBagConstraints.BOTH;
|
112 |
gbc.insets = new Insets(0, 0, 12, 0); |
113 |
gbc.weighty = 1.0;
|
114 |
this.add(getRadioButtonTable(), gbc);
|
115 |
|
116 |
gbc.gridy = 6;
|
117 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
118 |
gbc.weighty = 0.0;
|
119 |
this.add(getOutputChannelSelectionPanel(), gbc);
|
120 |
|
121 |
initTable(); |
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(GridCalculatorAlgorithm.RESULT);
|
135 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
136 |
outputPanel.add(new JLabel(" Dissolve [Vectorial] "), BorderLayout.WEST); |
137 |
outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
|
138 |
} catch (final Exception e) { |
139 |
Sextante.addErrorToLog(e); |
140 |
} |
141 |
} |
142 |
return outputPanel;
|
143 |
} |
144 |
|
145 |
/**
|
146 |
* Gets the output panel
|
147 |
* @return
|
148 |
*/
|
149 |
@SuppressWarnings("unused") |
150 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
151 |
if(algorithmOutputPanel == null) |
152 |
algorithmOutputPanel = new AlgorithmOutputPanel();
|
153 |
return algorithmOutputPanel;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* Gets a new JPanel with the text and JComboBox
|
158 |
* @param text
|
159 |
* @param combo
|
160 |
* @return
|
161 |
*/
|
162 |
public JPanel getComboPanel(String text, JComboBox combo) { |
163 |
JPanel panel = new JPanel(); |
164 |
GridBagLayout gbl = new GridBagLayout(); |
165 |
panel.setLayout(gbl); |
166 |
|
167 |
GridBagConstraints gbc = new GridBagConstraints(); |
168 |
gbc.fill = GridBagConstraints.NONE;
|
169 |
gbc.weightx = 0;
|
170 |
gbc.gridx = 0;
|
171 |
gbc.insets = new Insets(0, 2, 0, 5); |
172 |
JLabel label = new JLabel(text); |
173 |
label.setPreferredSize(new Dimension(180, 18)); |
174 |
panel.add(label, gbc); |
175 |
|
176 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
177 |
gbc.weightx = 1.0;
|
178 |
gbc.gridx = 1;
|
179 |
gbc.anchor = GridBagConstraints.EAST;
|
180 |
gbc.insets = new Insets(0, 2, 0, 0); |
181 |
panel.add(combo, gbc); |
182 |
return panel;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Gets a ComboBox
|
187 |
* @return
|
188 |
*/
|
189 |
public JComboBox getLayersCombo() { |
190 |
if(layersCombo == null) { |
191 |
layersCombo = new JComboBox(); |
192 |
layersCombo.setPreferredSize(new Dimension(0, 18)); |
193 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
194 |
layersCombo.setModel(comboModel); |
195 |
layersCombo.addActionListener(this);
|
196 |
} |
197 |
return layersCombo;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* Gets a ComboBox
|
202 |
* @return
|
203 |
*/
|
204 |
public JComboBox getFieldsCombo() { |
205 |
if(fieldsCombo == null) { |
206 |
fieldsCombo = new JComboBox(); |
207 |
fieldsCombo.setPreferredSize(new Dimension(0, 18)); |
208 |
String[] fieldList = getFieldList(); |
209 |
fieldsCombo.removeAllItems(); |
210 |
for (int i = 0; i < fieldList.length; i++) |
211 |
fieldsCombo.addItem(fieldList[i]); |
212 |
} |
213 |
return fieldsCombo;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Gets a CheckBox
|
218 |
* @return
|
219 |
*/
|
220 |
public JCheckBox getSelectionCheck() { |
221 |
if(selectionOnly == null) { |
222 |
selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries")); |
223 |
} |
224 |
return selectionOnly;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Gets a CheckBox
|
229 |
* @return
|
230 |
*/
|
231 |
public JCheckBox getAdjacentCheck() { |
232 |
if(adjacentOnly == null) { |
233 |
adjacentOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("adjacent_geometries_only")); |
234 |
} |
235 |
return adjacentOnly;
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* Gets the summary table
|
240 |
* @return TableContainer
|
241 |
*/
|
242 |
public TableContainer getRadioButtonTable() {
|
243 |
if (table == null) { |
244 |
table = new TableContainer(columnNames, columnWidths, null); |
245 |
table.setModel("ARGBBandSelectorModel");
|
246 |
table.setControlVisible(false);
|
247 |
table.initialize(); |
248 |
} |
249 |
return table;
|
250 |
} |
251 |
|
252 |
//------------------------------------------------------------
|
253 |
|
254 |
/*
|
255 |
* (non-Javadoc)
|
256 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
257 |
*/
|
258 |
public void actionPerformed(ActionEvent e) { |
259 |
if(e.getSource() == getLayersCombo()) {
|
260 |
//Recarga el combo de campos
|
261 |
String[] fieldList = getFieldList(); |
262 |
getFieldsCombo().removeAllItems(); |
263 |
for (int i = 0; i < fieldList.length; i++) |
264 |
getFieldsCombo().addItem(fieldList[i]); |
265 |
|
266 |
initTable(); |
267 |
} |
268 |
} |
269 |
|
270 |
/**
|
271 |
* Adds to the table one entry for each field
|
272 |
*/
|
273 |
private void initTable() { |
274 |
try {
|
275 |
getRadioButtonTable().removeAllRows(); |
276 |
for (int i = 0; i < getSelectedVectorLayer().getFieldCount(); i++) |
277 |
addTableRow(getSelectedVectorLayer().getFieldName(i)); |
278 |
} catch (NotInitializeException e) {
|
279 |
Sextante.addErrorToLog(e); |
280 |
} |
281 |
} |
282 |
|
283 |
/**
|
284 |
* A?ade una banda a la tabla bandas de la imagen asignandole un nombre y
|
285 |
* valor a los checkbox
|
286 |
* @param bandName Nombre de la banda
|
287 |
* @throws NotInitializeException
|
288 |
*/
|
289 |
private void addTableRow(String fieldName) throws NotInitializeException { |
290 |
Object[] row = { new Boolean(false), |
291 |
new Boolean(false), |
292 |
new Boolean(false), |
293 |
new Boolean(false), |
294 |
fieldName }; |
295 |
getRadioButtonTable().addRow(row); |
296 |
} |
297 |
|
298 |
@Override
|
299 |
public void assignParameters() { |
300 |
try {
|
301 |
ParametersSet params = m_Algorithm.getParameters(); |
302 |
params.getParameter(DissolveAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
303 |
params.getParameter(DissolveAlgorithm.FIELD).setParameterValue(fieldsCombo.getSelectedIndex()); |
304 |
params.getParameter(DissolveAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected()); |
305 |
params.getParameter(DissolveAlgorithm.DISSOLV_ADJ).setParameterValue(getAdjacentCheck().isSelected()); |
306 |
|
307 |
params.getParameter(DissolveAlgorithm.FUNCTION_LIST).setParameterValue(getValues()); |
308 |
|
309 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
310 |
Output out = ooSet.getOutput(DissolveAlgorithm.RESULT); |
311 |
|
312 |
//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
|
313 |
//AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
|
314 |
//out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
|
315 |
out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
316 |
} catch (Exception e) { |
317 |
Sextante.addErrorToLog(e); |
318 |
} |
319 |
} |
320 |
|
321 |
/**
|
322 |
* Formats the content of the table
|
323 |
* @return
|
324 |
*/
|
325 |
private String getValues() { |
326 |
String str = ""; |
327 |
try {
|
328 |
for (int i = 0; i < getRadioButtonTable().getRowCount(); i++) { |
329 |
str = str + (String)getRadioButtonTable().getModel().getValueAt(i, 4) + ","; |
330 |
for (int j = 0; j < getRadioButtonTable().getModel().getColumnCount() - 1; j++) |
331 |
if(((Boolean)getRadioButtonTable().getModel().getValueAt(i, j)).booleanValue()) |
332 |
str = str + DissolveAlgorithm.Summary[j] + ",";
|
333 |
str = str.substring(0, str.length() - 1) + ";"; |
334 |
} |
335 |
} catch (NotInitializeException e) {
|
336 |
Sextante.addErrorToLog(e); |
337 |
} |
338 |
return str.substring(0, str.length() - 1); |
339 |
} |
340 |
|
341 |
@Override
|
342 |
public void setOutputValue(String arg0, String arg1) { |
343 |
|
344 |
} |
345 |
|
346 |
@Override
|
347 |
public void setParameterValue(String arg0, String arg1) { |
348 |
|
349 |
} |
350 |
|
351 |
/**
|
352 |
* Gets the input layer list
|
353 |
* @return
|
354 |
*/
|
355 |
private ObjectAndDescription[] getLayerList() { |
356 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
357 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_POLYGON); |
358 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
359 |
for (int i = 0; i < layers.length; i++) |
360 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
361 |
return oad;
|
362 |
} |
363 |
|
364 |
/**
|
365 |
* Gets the selected vector layer in the JComboBox
|
366 |
* @return
|
367 |
*/
|
368 |
private IVectorLayer getSelectedVectorLayer() {
|
369 |
if(layersCombo.getSelectedItem() != null) |
370 |
return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
|
371 |
return null; |
372 |
} |
373 |
|
374 |
/**
|
375 |
* Gets the field list of the selected layer
|
376 |
* @return
|
377 |
*/
|
378 |
public String[] getFieldList() { |
379 |
IVectorLayer layer = getSelectedVectorLayer(); |
380 |
String[] data = new String[layer.getFieldCount()]; |
381 |
for (int i = 0; i < layer.getFieldCount(); i++) |
382 |
data[i] = layer.getFieldName(i); |
383 |
return data;
|
384 |
} |
385 |
} |