gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.merge / src / main / java / org / gvsig / sextante / app / algorithm / merge / MergeParametersPanel.java @ 56
History | View | Annotate | Download (8.71 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.sextante.app.algorithm.merge; |
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 |
import java.util.ArrayList; |
28 |
|
29 |
import javax.swing.JCheckBox; |
30 |
import javax.swing.JComboBox; |
31 |
import javax.swing.JLabel; |
32 |
import javax.swing.JPanel; |
33 |
|
34 |
import org.gvsig.gui.beans.table.TableContainer; |
35 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
36 |
import org.gvsig.sextante.app.extension.core.CompositeSourceOutputChannel; |
37 |
import org.gvsig.sextante.app.extension.gui.AlgorithmOutputPanel; |
38 |
|
39 |
import es.unex.sextante.core.GeoAlgorithm; |
40 |
import es.unex.sextante.core.ObjectAndDescription; |
41 |
import es.unex.sextante.core.OutputObjectsSet; |
42 |
import es.unex.sextante.core.ParametersSet; |
43 |
import es.unex.sextante.core.Sextante; |
44 |
import es.unex.sextante.dataObjects.IVectorLayer; |
45 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
46 |
import es.unex.sextante.gui.core.SextanteGUI; |
47 |
import es.unex.sextante.outputs.Output; |
48 |
|
49 |
/**
|
50 |
* Panel for merge algorithm
|
51 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
52 |
*/
|
53 |
public class MergeParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
54 |
private static final long serialVersionUID = 1L; |
55 |
private GeoAlgorithm m_Algorithm = null; |
56 |
private JComboBox fieldsCombo = null; |
57 |
private JCheckBox allLayers = null; |
58 |
//private AlgorithmOutputPanel output = null;
|
59 |
private final String[] columnNames = { "Selected", "Layer" }; |
60 |
private final int[] columnWidths = { 35, 334 }; |
61 |
private TableContainer table = null; |
62 |
private ObjectAndDescription[] layerList = null; |
63 |
|
64 |
public MergeParametersPanel() {
|
65 |
super();
|
66 |
} |
67 |
|
68 |
public void init(GeoAlgorithm algorithm) { |
69 |
m_Algorithm = algorithm; |
70 |
initGUI(); |
71 |
} |
72 |
|
73 |
private void initGUI() { |
74 |
GridBagLayout gbl = new GridBagLayout(); |
75 |
this.setLayout(gbl);
|
76 |
|
77 |
GridBagConstraints gbc = new GridBagConstraints(); |
78 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
79 |
gbc.weightx = 1.0;
|
80 |
gbc.gridx = 0;
|
81 |
gbc.gridy = 0;
|
82 |
gbc.insets = new Insets(5, 5, 8, 5); |
83 |
this.add(getAllLayersCheck(), gbc);
|
84 |
|
85 |
gbc.gridy = 1;
|
86 |
gbc.fill = GridBagConstraints.BOTH;
|
87 |
gbc.insets = new Insets(0, 0, 12, 0); |
88 |
gbc.weighty = 1.0;
|
89 |
this.add(getCheckBoxTable(), gbc);
|
90 |
|
91 |
gbc.gridy = 2;
|
92 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
93 |
gbc.insets = new Insets(5, 5, 8, 5); |
94 |
gbc.weightx = 1.0;
|
95 |
gbc.weighty = 0;
|
96 |
this.add(getFieldsComboPanel(Sextante.getText("Field"), getFieldsCombo()), gbc); |
97 |
|
98 |
gbc.gridy = 3;
|
99 |
this.add(AlgorithmOutputPanel.getReference(), gbc);
|
100 |
|
101 |
initTable(); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* Gets the output panel
|
106 |
* @return
|
107 |
*/
|
108 |
/*private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
109 |
if(output == null)
|
110 |
output = new AlgorithmOutputPanel();
|
111 |
return output;
|
112 |
}*/
|
113 |
|
114 |
/**
|
115 |
* Gets a new JPanel with the text and JComboBox
|
116 |
* @param text
|
117 |
* @param combo
|
118 |
* @return
|
119 |
*/
|
120 |
public JPanel getFieldsComboPanel(String text, JComboBox combo) { |
121 |
JPanel panel = new JPanel(); |
122 |
GridBagLayout gbl = new GridBagLayout(); |
123 |
panel.setLayout(gbl); |
124 |
|
125 |
GridBagConstraints gbc = new GridBagConstraints(); |
126 |
gbc.fill = GridBagConstraints.NONE;
|
127 |
gbc.weightx = 0;
|
128 |
gbc.gridx = 0;
|
129 |
gbc.insets = new Insets(0, 2, 0, 50); |
130 |
JLabel label = new JLabel(text); |
131 |
label.setPreferredSize(new Dimension(80, 18)); |
132 |
panel.add(label, gbc); |
133 |
|
134 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
135 |
gbc.weightx = 1.0;
|
136 |
gbc.gridx = 1;
|
137 |
gbc.anchor = GridBagConstraints.EAST;
|
138 |
gbc.insets = new Insets(0, 2, 0, 0); |
139 |
panel.add(combo, gbc); |
140 |
return panel;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Gets a ComboBox
|
145 |
* @return
|
146 |
*/
|
147 |
public JComboBox getFieldsCombo() { |
148 |
if(fieldsCombo == null) { |
149 |
fieldsCombo = new JComboBox(); |
150 |
fieldsCombo.setPreferredSize(new Dimension(0, 18)); |
151 |
ObjectAndDescription[] fieldList = getLayerList();
|
152 |
fieldsCombo.removeAllItems(); |
153 |
for (int i = 0; i < fieldList.length; i++) |
154 |
fieldsCombo.addItem(fieldList[i]); |
155 |
} |
156 |
return fieldsCombo;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
* Gets a CheckBox
|
161 |
* @return
|
162 |
*/
|
163 |
public JCheckBox getAllLayersCheck() { |
164 |
if(allLayers == null) { |
165 |
allLayers = new JCheckBox("select_all_layers"); |
166 |
allLayers.addActionListener(this);
|
167 |
} |
168 |
return allLayers;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Gets the summary table
|
173 |
* @return TableContainer
|
174 |
*/
|
175 |
public TableContainer getCheckBoxTable() {
|
176 |
if (table == null) { |
177 |
table = new TableContainer(columnNames, columnWidths, null); |
178 |
table.setModel("CheckBoxModel");
|
179 |
table.setControlVisible(false);
|
180 |
table.initialize(); |
181 |
} |
182 |
return table;
|
183 |
} |
184 |
|
185 |
//------------------------------------------------------------
|
186 |
|
187 |
/*
|
188 |
* (non-Javadoc)
|
189 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
190 |
*/
|
191 |
public void actionPerformed(ActionEvent e) { |
192 |
if(e.getSource() == getAllLayersCheck()) {
|
193 |
//Selecci?n de todas las capas de la tabla
|
194 |
try {
|
195 |
for (int i = 0; i < getCheckBoxTable().getRowCount(); i++) { |
196 |
if(getAllLayersCheck().isSelected())
|
197 |
getCheckBoxTable().getModel().setValueAt(new Boolean(true), i, 0); |
198 |
else
|
199 |
getCheckBoxTable().getModel().setValueAt(new Boolean(false), i, 0); |
200 |
} |
201 |
} catch (NotInitializeException e1) {
|
202 |
Sextante.addErrorToLog(e1); |
203 |
} |
204 |
} |
205 |
} |
206 |
|
207 |
/**
|
208 |
* Adds to the table one entry for each field
|
209 |
*/
|
210 |
private void initTable() { |
211 |
try {
|
212 |
getCheckBoxTable().removeAllRows(); |
213 |
ObjectAndDescription[] layerList = getLayerList();
|
214 |
for (int i = 0; i < layerList.length; i++) |
215 |
addTableRow(layerList[i].getDescription()); |
216 |
} catch (NotInitializeException e) {
|
217 |
Sextante.addErrorToLog(e); |
218 |
} |
219 |
} |
220 |
|
221 |
/**
|
222 |
* Adds one entry to the table
|
223 |
* @param layerName
|
224 |
* Layer name
|
225 |
* @throws NotInitializeException
|
226 |
*/
|
227 |
private void addTableRow(String layerName) throws NotInitializeException { |
228 |
Object[] row = { new Boolean(false), |
229 |
layerName }; |
230 |
getCheckBoxTable().addRow(row); |
231 |
} |
232 |
|
233 |
@Override
|
234 |
public boolean assignParameters() { |
235 |
try {
|
236 |
ParametersSet params = m_Algorithm.getParameters(); |
237 |
params.getParameter(MergeAlgorithm.FIELDLAYER).setParameterValue(getSelectedVectorLayer()); |
238 |
params.getParameter(MergeAlgorithm.LAYERS).setParameterValue(getSelectedLayerList()); |
239 |
|
240 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
241 |
Output out = ooSet.getOutput(MergeAlgorithm.RESULT); |
242 |
out.setOutputChannel(new CompositeSourceOutputChannel(AlgorithmOutputPanel.getReference().getOutputParameters()));
|
243 |
return true; |
244 |
} catch (Exception e) { |
245 |
Sextante.addErrorToLog(e); |
246 |
return false; |
247 |
} |
248 |
} |
249 |
|
250 |
@Override
|
251 |
public void setOutputValue(String arg0, String arg1) { |
252 |
|
253 |
} |
254 |
|
255 |
@Override
|
256 |
public void setParameterValue(String arg0, String arg1) { |
257 |
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* Gets the input layer list
|
262 |
* @return
|
263 |
*/
|
264 |
private ObjectAndDescription[] getLayerList() { |
265 |
if(layerList == null) { |
266 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
267 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
268 |
layerList = new ObjectAndDescription[layers.length];
|
269 |
for (int i = 0; i < layers.length; i++) |
270 |
layerList[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
271 |
} |
272 |
return layerList;
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* Gets the list of selected layers
|
277 |
* @return
|
278 |
*/
|
279 |
private ArrayList<IVectorLayer> getSelectedLayerList() { |
280 |
ObjectAndDescription[] layerList = getLayerList();
|
281 |
ArrayList<IVectorLayer> vLayer = new ArrayList<IVectorLayer>(); |
282 |
for (int i = 0; i < layerList.length; i++) { |
283 |
Boolean check = (Boolean)getCheckBoxTable().getModel().getValueAt(i, 0); |
284 |
if(check.booleanValue())
|
285 |
vLayer.add((IVectorLayer)layerList[i].getObject()); |
286 |
} |
287 |
return vLayer;
|
288 |
} |
289 |
|
290 |
/**
|
291 |
* Gets the selected vector layer in the JComboBox
|
292 |
* @return
|
293 |
*/
|
294 |
private IVectorLayer getSelectedVectorLayer() {
|
295 |
if(getFieldsCombo().getSelectedItem() != null) |
296 |
return (IVectorLayer)((ObjectAndDescription)getFieldsCombo().getSelectedItem()).getObject();
|
297 |
return null; |
298 |
} |
299 |
|
300 |
} |