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 @ 233
History | View | Annotate | Download (10.4 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2010 Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.geoprocess.algorithm.dissolve; |
20 |
|
21 |
import java.awt.Dimension; |
22 |
import java.awt.GridBagConstraints; |
23 |
import java.awt.GridBagLayout; |
24 |
import java.awt.Insets; |
25 |
import java.awt.event.ActionEvent; |
26 |
import java.awt.event.ActionListener; |
27 |
|
28 |
import javax.swing.ComboBoxModel; |
29 |
import javax.swing.DefaultComboBoxModel; |
30 |
import javax.swing.JCheckBox; |
31 |
import javax.swing.JComboBox; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JPanel; |
34 |
|
35 |
import es.unex.sextante.core.GeoAlgorithm; |
36 |
import es.unex.sextante.core.ObjectAndDescription; |
37 |
import es.unex.sextante.core.OutputObjectsSet; |
38 |
import es.unex.sextante.core.ParametersSet; |
39 |
import es.unex.sextante.core.Sextante; |
40 |
import es.unex.sextante.dataObjects.IVectorLayer; |
41 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
42 |
import es.unex.sextante.gui.core.SextanteGUI; |
43 |
import es.unex.sextante.outputs.Output; |
44 |
|
45 |
import org.gvsig.geoprocess.core.CompositeSourceOutputChannel; |
46 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
47 |
import org.gvsig.gui.beans.table.TableContainer; |
48 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
49 |
|
50 |
/**
|
51 |
* Panel for dissolve algorithm
|
52 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
53 |
*/
|
54 |
public class DissolveParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
55 |
private static final long serialVersionUID = 1L; |
56 |
private GeoAlgorithm m_Algorithm = null; |
57 |
private JComboBox layersCombo = null; |
58 |
private JComboBox fieldsCombo = null; |
59 |
private JCheckBox selectionOnly = null; |
60 |
private JCheckBox adjacentOnly = null; |
61 |
//private AlgorithmOutputPanel output = null;
|
62 |
private final String[] columnNames = { "Min", "Max", "Sum", "Avg", "Field ID" }; |
63 |
private final int[] columnWidths = { 35, 35, 35, 35, 334 }; |
64 |
private TableContainer table = null; |
65 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
66 |
|
67 |
public DissolveParametersPanel() {
|
68 |
super();
|
69 |
} |
70 |
|
71 |
public void init(GeoAlgorithm algorithm) { |
72 |
m_Algorithm = algorithm; |
73 |
initGUI(); |
74 |
} |
75 |
|
76 |
private void initGUI() { |
77 |
GridBagLayout gbl = new GridBagLayout(); |
78 |
this.setLayout(gbl);
|
79 |
|
80 |
GridBagConstraints gbc = new GridBagConstraints(); |
81 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
82 |
gbc.weightx = 1.0;
|
83 |
gbc.gridx = 0;
|
84 |
gbc.gridy = 0;
|
85 |
gbc.insets = new Insets(0, 0, 8, 0); |
86 |
this.add(getComboPanel(Sextante.getText("Input_layer"), getLayersCombo()), gbc); |
87 |
|
88 |
gbc.gridy = 1;
|
89 |
this.add(getComboPanel(Sextante.getText("Field"), getFieldsCombo()), gbc); |
90 |
|
91 |
gbc.gridy = 2;
|
92 |
this.add(getSelectionCheck(), gbc);
|
93 |
|
94 |
gbc.gridy = 3;
|
95 |
this.add(getAdjacentCheck(), gbc);
|
96 |
|
97 |
gbc.gridy = 4;
|
98 |
this.add(new JLabel(Sextante.getText("summary_function")), gbc); |
99 |
|
100 |
gbc.gridy = 5;
|
101 |
gbc.fill = GridBagConstraints.BOTH;
|
102 |
gbc.insets = new Insets(0, 0, 12, 0); |
103 |
gbc.weighty = 1.0;
|
104 |
this.add(getRadioButtonTable(), gbc);
|
105 |
|
106 |
gbc.gridy = 6;
|
107 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
108 |
gbc.weighty = 0.0;
|
109 |
this.add(getAlgorithmOutputPanel(), gbc);
|
110 |
|
111 |
initTable(); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Gets the output panel
|
116 |
* @return
|
117 |
*/
|
118 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
119 |
if(algorithmOutputPanel == null) |
120 |
algorithmOutputPanel = new AlgorithmOutputPanel();
|
121 |
return algorithmOutputPanel;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Gets a new JPanel with the text and JComboBox
|
126 |
* @param text
|
127 |
* @param combo
|
128 |
* @return
|
129 |
*/
|
130 |
public JPanel getComboPanel(String text, JComboBox combo) { |
131 |
JPanel panel = new JPanel(); |
132 |
GridBagLayout gbl = new GridBagLayout(); |
133 |
panel.setLayout(gbl); |
134 |
|
135 |
GridBagConstraints gbc = new GridBagConstraints(); |
136 |
gbc.fill = GridBagConstraints.NONE;
|
137 |
gbc.weightx = 0;
|
138 |
gbc.gridx = 0;
|
139 |
gbc.insets = new Insets(0, 2, 0, 5); |
140 |
JLabel label = new JLabel(text); |
141 |
label.setPreferredSize(new Dimension(180, 18)); |
142 |
panel.add(label, gbc); |
143 |
|
144 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
145 |
gbc.weightx = 1.0;
|
146 |
gbc.gridx = 1;
|
147 |
gbc.anchor = GridBagConstraints.EAST;
|
148 |
gbc.insets = new Insets(0, 2, 0, 0); |
149 |
panel.add(combo, gbc); |
150 |
return panel;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Gets a ComboBox
|
155 |
* @return
|
156 |
*/
|
157 |
public JComboBox getLayersCombo() { |
158 |
if(layersCombo == null) { |
159 |
layersCombo = new JComboBox(); |
160 |
layersCombo.setPreferredSize(new Dimension(0, 18)); |
161 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
162 |
layersCombo.setModel(comboModel); |
163 |
layersCombo.addActionListener(this);
|
164 |
} |
165 |
return layersCombo;
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* Gets a ComboBox
|
170 |
* @return
|
171 |
*/
|
172 |
public JComboBox getFieldsCombo() { |
173 |
if(fieldsCombo == null) { |
174 |
fieldsCombo = new JComboBox(); |
175 |
fieldsCombo.setPreferredSize(new Dimension(0, 18)); |
176 |
String[] fieldList = getFieldList(); |
177 |
fieldsCombo.removeAllItems(); |
178 |
for (int i = 0; i < fieldList.length; i++) |
179 |
fieldsCombo.addItem(fieldList[i]); |
180 |
} |
181 |
return fieldsCombo;
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* Gets a CheckBox
|
186 |
* @return
|
187 |
*/
|
188 |
public JCheckBox getSelectionCheck() { |
189 |
if(selectionOnly == null) { |
190 |
selectionOnly = new JCheckBox(Sextante.getText("Selected_geometries")); |
191 |
} |
192 |
return selectionOnly;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Gets a CheckBox
|
197 |
* @return
|
198 |
*/
|
199 |
public JCheckBox getAdjacentCheck() { |
200 |
if(adjacentOnly == null) { |
201 |
adjacentOnly = new JCheckBox(Sextante.getText("adjacent_geometries_only")); |
202 |
} |
203 |
return adjacentOnly;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Gets the summary table
|
208 |
* @return TableContainer
|
209 |
*/
|
210 |
public TableContainer getRadioButtonTable() {
|
211 |
if (table == null) { |
212 |
table = new TableContainer(columnNames, columnWidths, null); |
213 |
table.setModel("ARGBBandSelectorModel");
|
214 |
table.setControlVisible(false);
|
215 |
table.initialize(); |
216 |
} |
217 |
return table;
|
218 |
} |
219 |
|
220 |
//------------------------------------------------------------
|
221 |
|
222 |
/*
|
223 |
* (non-Javadoc)
|
224 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
225 |
*/
|
226 |
public void actionPerformed(ActionEvent e) { |
227 |
if(e.getSource() == getLayersCombo()) {
|
228 |
//Recarga el combo de campos
|
229 |
String[] fieldList = getFieldList(); |
230 |
getFieldsCombo().removeAllItems(); |
231 |
for (int i = 0; i < fieldList.length; i++) |
232 |
getFieldsCombo().addItem(fieldList[i]); |
233 |
|
234 |
initTable(); |
235 |
} |
236 |
} |
237 |
|
238 |
/**
|
239 |
* Adds to the table one entry for each field
|
240 |
*/
|
241 |
private void initTable() { |
242 |
try {
|
243 |
getRadioButtonTable().removeAllRows(); |
244 |
for (int i = 0; i < getSelectedVectorLayer().getFieldCount(); i++) |
245 |
addTableRow(getSelectedVectorLayer().getFieldName(i)); |
246 |
} catch (NotInitializeException e) {
|
247 |
Sextante.addErrorToLog(e); |
248 |
} |
249 |
} |
250 |
|
251 |
/**
|
252 |
* A�ade una banda a la tabla bandas de la imagen asignandole un nombre y
|
253 |
* valor a los checkbox
|
254 |
* @param bandName Nombre de la banda
|
255 |
* @throws NotInitializeException
|
256 |
*/
|
257 |
private void addTableRow(String fieldName) throws NotInitializeException { |
258 |
Object[] row = { new Boolean(false), |
259 |
new Boolean(false), |
260 |
new Boolean(false), |
261 |
new Boolean(false), |
262 |
fieldName }; |
263 |
getRadioButtonTable().addRow(row); |
264 |
} |
265 |
|
266 |
@Override
|
267 |
public void assignParameters() { |
268 |
try {
|
269 |
ParametersSet params = m_Algorithm.getParameters(); |
270 |
params.getParameter(DissolveAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
271 |
params.getParameter(DissolveAlgorithm.FIELD).setParameterValue(fieldsCombo.getSelectedIndex()); |
272 |
params.getParameter(DissolveAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected()); |
273 |
params.getParameter(DissolveAlgorithm.DISSOLV_ADJ).setParameterValue(getAdjacentCheck().isSelected()); |
274 |
|
275 |
params.getParameter(DissolveAlgorithm.FUNCTION_LIST).setParameterValue(getValues()); |
276 |
|
277 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
278 |
Output out = ooSet.getOutput(DissolveAlgorithm.RESULT); |
279 |
out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
|
280 |
} catch (Exception e) { |
281 |
Sextante.addErrorToLog(e); |
282 |
} |
283 |
} |
284 |
|
285 |
/**
|
286 |
* Formats the content of the table
|
287 |
* @return
|
288 |
*/
|
289 |
private String getValues() { |
290 |
String str = ""; |
291 |
try {
|
292 |
for (int i = 0; i < getRadioButtonTable().getRowCount(); i++) { |
293 |
str = str + (String)getRadioButtonTable().getModel().getValueAt(i, 4) + ","; |
294 |
for (int j = 0; j < getRadioButtonTable().getModel().getColumnCount() - 1; j++) |
295 |
if(((Boolean)getRadioButtonTable().getModel().getValueAt(i, j)).booleanValue()) |
296 |
str = str + DissolveAlgorithm.Summary[j] + ",";
|
297 |
str = str.substring(0, str.length() - 1) + ";"; |
298 |
} |
299 |
} catch (NotInitializeException e) {
|
300 |
Sextante.addErrorToLog(e); |
301 |
} |
302 |
return str.substring(0, str.length() - 1); |
303 |
} |
304 |
|
305 |
@Override
|
306 |
public void setOutputValue(String arg0, String arg1) { |
307 |
|
308 |
} |
309 |
|
310 |
@Override
|
311 |
public void setParameterValue(String arg0, String arg1) { |
312 |
|
313 |
} |
314 |
|
315 |
/**
|
316 |
* Gets the input layer list
|
317 |
* @return
|
318 |
*/
|
319 |
private ObjectAndDescription[] getLayerList() { |
320 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
321 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_POLYGON); |
322 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
323 |
for (int i = 0; i < layers.length; i++) |
324 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
325 |
return oad;
|
326 |
} |
327 |
|
328 |
/**
|
329 |
* Gets the selected vector layer in the JComboBox
|
330 |
* @return
|
331 |
*/
|
332 |
private IVectorLayer getSelectedVectorLayer() {
|
333 |
if(layersCombo.getSelectedItem() != null) |
334 |
return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
|
335 |
return null; |
336 |
} |
337 |
|
338 |
/**
|
339 |
* Gets the field list of the selected layer
|
340 |
* @return
|
341 |
*/
|
342 |
public String[] getFieldList() { |
343 |
IVectorLayer layer = getSelectedVectorLayer(); |
344 |
String[] data = new String[layer.getFieldCount()]; |
345 |
for (int i = 0; i < layer.getFieldCount(); i++) |
346 |
data[i] = layer.getFieldName(i); |
347 |
return data;
|
348 |
} |
349 |
} |