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