gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.reproject / src / main / java / org / gvsig / geoprocess / algorithm / reproject / ReprojectParametersPanel.java @ 310
History | View | Annotate | Download (10.2 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.reproject; |
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.cresques.cts.IProjection; |
42 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
43 |
import org.gvsig.fmap.crs.CRSFactory; |
44 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
45 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
46 |
|
47 |
import es.unex.sextante.core.GeoAlgorithm; |
48 |
import es.unex.sextante.core.ObjectAndDescription; |
49 |
import es.unex.sextante.core.OutputObjectsSet; |
50 |
import es.unex.sextante.core.ParametersSet; |
51 |
import es.unex.sextante.core.Sextante; |
52 |
import es.unex.sextante.dataObjects.IVectorLayer; |
53 |
import es.unex.sextante.gridCalculus.gridCalculator.GridCalculatorAlgorithm; |
54 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
55 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
56 |
import es.unex.sextante.gui.core.SextanteGUI; |
57 |
import es.unex.sextante.outputs.Output; |
58 |
|
59 |
/**
|
60 |
* Panel for reproject algorithm
|
61 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
62 |
*/
|
63 |
public class ReprojectParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
64 |
private static final long serialVersionUID = 1L; |
65 |
private GeoAlgorithm m_Algorithm = null; |
66 |
private JComboBox layersCombo = null; |
67 |
private JCheckBox selectionOnly = null; |
68 |
//private AlgorithmOutputPanel output = null;
|
69 |
private JLabel projLabel = null; |
70 |
private CRSSelectPanel projectionSrcSelector = null; |
71 |
private IProjection targetLayerProjection = null; |
72 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
73 |
private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
74 |
private JPanel outputPanel; |
75 |
|
76 |
public ReprojectParametersPanel() {
|
77 |
super();
|
78 |
} |
79 |
|
80 |
public void init(GeoAlgorithm algorithm) { |
81 |
m_Algorithm = algorithm; |
82 |
initGUI(); |
83 |
init(); |
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(15, 5, 15, 0); |
96 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("Input_layer"), getLayersCombo()), gbc); |
97 |
|
98 |
gbc.gridy = 1;
|
99 |
gbc.insets = new Insets(0, 5, 15, 0); |
100 |
this.add(getSelectionCheck(), gbc);
|
101 |
|
102 |
gbc.gridy = 2;
|
103 |
this.add(getCurrentProjLabel(), gbc);
|
104 |
|
105 |
gbc.gridy = 3;
|
106 |
this.add(getProjectionSelector(), gbc);
|
107 |
|
108 |
gbc.gridy = 4;
|
109 |
gbc.fill = GridBagConstraints.BOTH;
|
110 |
gbc.weighty = 1.0;
|
111 |
gbc.weightx = 1.0;
|
112 |
this.add(new JPanel(), gbc); |
113 |
|
114 |
gbc.gridy = 5;
|
115 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
116 |
gbc.weighty = 0.0;
|
117 |
this.add(getOutputChannelSelectionPanel(), gbc);
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Gets the output panel (SEXTANTE)
|
122 |
* @return
|
123 |
*/
|
124 |
private JPanel getOutputChannelSelectionPanel() { |
125 |
if(outputPanel == null) { |
126 |
try {
|
127 |
outputPanel = new JPanel(); |
128 |
outputPanel.setLayout(new BorderLayout()); |
129 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
130 |
final Output out = ooSet.getOutput(GridCalculatorAlgorithm.RESULT);
|
131 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
132 |
String label = GeoProcessLocator.getGeoProcessManager().getTranslation("Reproject"); |
133 |
outputPanel.add(new JLabel(" " + label + " [Vectorial] "), BorderLayout.WEST); |
134 |
outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
|
135 |
} catch (final Exception e) { |
136 |
Sextante.addErrorToLog(e); |
137 |
} |
138 |
} |
139 |
return outputPanel;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Gets the output panel (DAL)
|
144 |
* @return
|
145 |
*/
|
146 |
@SuppressWarnings("unused") |
147 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
148 |
if(algorithmOutputPanel == null) |
149 |
algorithmOutputPanel = new AlgorithmOutputPanel();
|
150 |
return algorithmOutputPanel;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* Gets a new JPanel with the text and JComboBox
|
155 |
* @param text
|
156 |
* @param combo
|
157 |
* @return
|
158 |
*/
|
159 |
public JPanel getComboPanel(String text, JComboBox combo) { |
160 |
JPanel panel = new JPanel(); |
161 |
GridBagLayout gbl = new GridBagLayout(); |
162 |
panel.setLayout(gbl); |
163 |
|
164 |
GridBagConstraints gbc = new GridBagConstraints(); |
165 |
gbc.fill = GridBagConstraints.NONE;
|
166 |
gbc.weightx = 0;
|
167 |
gbc.gridx = 0;
|
168 |
gbc.insets = new Insets(0, 2, 0, 50); |
169 |
JLabel label = new JLabel(text); |
170 |
label.setPreferredSize(new Dimension(180, 18)); |
171 |
panel.add(label, gbc); |
172 |
|
173 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
174 |
gbc.weightx = 1.0;
|
175 |
gbc.gridx = 1;
|
176 |
gbc.anchor = GridBagConstraints.EAST;
|
177 |
gbc.insets = new Insets(0, 2, 0, 0); |
178 |
panel.add(combo, gbc); |
179 |
return panel;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* Gets a ComboBox
|
184 |
* @return
|
185 |
*/
|
186 |
public JComboBox getLayersCombo() { |
187 |
if(layersCombo == null) { |
188 |
layersCombo = new JComboBox(); |
189 |
layersCombo.setPreferredSize(new Dimension(0, 18)); |
190 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
191 |
layersCombo.setModel(comboModel); |
192 |
layersCombo.addActionListener(this);
|
193 |
} |
194 |
return layersCombo;
|
195 |
} |
196 |
|
197 |
|
198 |
/**
|
199 |
* Gets a CheckBox
|
200 |
* @return
|
201 |
*/
|
202 |
public JCheckBox getSelectionCheck() { |
203 |
if(selectionOnly == null) { |
204 |
selectionOnly = new JCheckBox(GeoProcessLocator.getGeoProcessManager().getTranslation("Selected_geometries")); |
205 |
} |
206 |
return selectionOnly;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* Panel with the projection selector
|
211 |
* @return
|
212 |
*/
|
213 |
private CRSSelectPanel getProjectionSelector() {
|
214 |
if (projectionSrcSelector == null) { |
215 |
targetLayerProjection = CRSFactory.getCRS("EPSG:23030");
|
216 |
projectionSrcSelector = CRSSelectPanel.getPanel(targetLayerProjection); |
217 |
projectionSrcSelector.getJLabel().setText(GeoProcessLocator.getGeoProcessManager().getTranslation("Proyeccion_Destino"));
|
218 |
projectionSrcSelector.setPreferredSize(new java.awt.Dimension(330,35)); |
219 |
projectionSrcSelector.addActionListener(new java.awt.event.ActionListener() {
|
220 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
221 |
if (projectionSrcSelector.isOkPressed()) {
|
222 |
targetLayerProjection = projectionSrcSelector.getCurProj(); |
223 |
} |
224 |
} |
225 |
}); |
226 |
} |
227 |
projectionSrcSelector.setTransPanelActive(true);
|
228 |
return projectionSrcSelector;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Gets the label with the current projection
|
233 |
* @return
|
234 |
*/
|
235 |
public JLabel getCurrentProjLabel() { |
236 |
if(projLabel == null) |
237 |
projLabel = new JLabel(); |
238 |
return projLabel;
|
239 |
} |
240 |
|
241 |
//------------------------------------------------------------
|
242 |
|
243 |
/**
|
244 |
* Initialize actions
|
245 |
*/
|
246 |
private void init() { |
247 |
IVectorLayer layer = getSelectedVectorLayer(); |
248 |
IProjection currentProj = (IProjection)layer.getCRS(); |
249 |
getCurrentProjLabel().setText("Proj: " + currentProj.getAbrev());
|
250 |
} |
251 |
|
252 |
/*
|
253 |
* (non-Javadoc)
|
254 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
255 |
*/
|
256 |
public void actionPerformed(ActionEvent e) { |
257 |
if(e.getSource() == getLayersCombo()) {
|
258 |
|
259 |
} |
260 |
} |
261 |
|
262 |
@Override
|
263 |
public void assignParameters() { |
264 |
try {
|
265 |
ParametersSet params = m_Algorithm.getParameters(); |
266 |
params.getParameter(ReprojectAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
267 |
params.getParameter(ReprojectAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected()); |
268 |
String proj = getProjectionSelector().getCurProj().getFullCode();
|
269 |
params.getParameter(ReprojectAlgorithm.DST_PROJECTION).setParameterValue(proj); |
270 |
|
271 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
272 |
Output out = ooSet.getOutput(ReprojectAlgorithm.RESULT); |
273 |
|
274 |
//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
|
275 |
//out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
|
276 |
out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
277 |
} catch (Exception e) { |
278 |
Sextante.addErrorToLog(e); |
279 |
} |
280 |
} |
281 |
|
282 |
@Override
|
283 |
public void setOutputValue(String arg0, String arg1) { |
284 |
|
285 |
} |
286 |
|
287 |
@Override
|
288 |
public void setParameterValue(String arg0, String arg1) { |
289 |
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* Gets the input layer list
|
294 |
* @return
|
295 |
*/
|
296 |
private ObjectAndDescription[] getLayerList() { |
297 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
298 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
299 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
300 |
for (int i = 0; i < layers.length; i++) |
301 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
302 |
return oad;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* Gets the selected vector layer in the JComboBox
|
307 |
* @return
|
308 |
*/
|
309 |
private IVectorLayer getSelectedVectorLayer() {
|
310 |
if(layersCombo.getSelectedItem() != null) |
311 |
return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
|
312 |
return null; |
313 |
} |
314 |
|
315 |
/**
|
316 |
* Gets the field list of the selected layer
|
317 |
* @return
|
318 |
*/
|
319 |
public String[] getFieldList() { |
320 |
IVectorLayer layer = getSelectedVectorLayer(); |
321 |
String[] data = new String[layer.getFieldCount()]; |
322 |
for (int i = 0; i < layer.getFieldCount(); i++) |
323 |
data[i] = layer.getFieldName(i); |
324 |
return data;
|
325 |
} |
326 |
} |