gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.algorithm / org.gvsig.sextante.app.algorithm.reproject / src / main / java / org / gvsig / sextante / app / algorithm / reproject / ReprojectParametersPanel.java @ 172
History | View | Annotate | Download (8.64 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.reproject; |
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.cresques.cts.IProjection; |
46 |
|
47 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
48 |
import org.gvsig.fmap.crs.CRSFactory; |
49 |
import org.gvsig.geoprocess.core.CompositeSourceOutputChannel; |
50 |
import org.gvsig.geoprocess.gui.AlgorithmOutputPanel; |
51 |
|
52 |
/**
|
53 |
* Panel for reproject algorithm
|
54 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
55 |
*/
|
56 |
public class ReprojectParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener { |
57 |
private static final long serialVersionUID = 1L; |
58 |
private GeoAlgorithm m_Algorithm = null; |
59 |
private JComboBox layersCombo = null; |
60 |
private JCheckBox selectionOnly = null; |
61 |
//private AlgorithmOutputPanel output = null;
|
62 |
private JLabel projLabel = null; |
63 |
private CRSSelectPanel projectionSrcSelector = null; |
64 |
private IProjection targetLayerProjection = null; |
65 |
private AlgorithmOutputPanel algorithmOutputPanel = null; |
66 |
public ReprojectParametersPanel() {
|
67 |
super();
|
68 |
} |
69 |
|
70 |
public void init(GeoAlgorithm algorithm) { |
71 |
m_Algorithm = algorithm; |
72 |
initGUI(); |
73 |
init(); |
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(15, 5, 15, 0); |
86 |
this.add(getComboPanel(Sextante.getText("Input_layer"), getLayersCombo()), gbc); |
87 |
|
88 |
gbc.gridy = 1;
|
89 |
gbc.insets = new Insets(0, 5, 15, 0); |
90 |
this.add(getSelectionCheck(), gbc);
|
91 |
|
92 |
gbc.gridy = 2;
|
93 |
this.add(getCurrentProjLabel(), gbc);
|
94 |
|
95 |
gbc.gridy = 3;
|
96 |
this.add(getProjectionSelector(), gbc);
|
97 |
|
98 |
gbc.gridy = 4;
|
99 |
gbc.fill = GridBagConstraints.BOTH;
|
100 |
gbc.weighty = 1.0;
|
101 |
gbc.weightx = 1.0;
|
102 |
this.add(new JPanel(), gbc); |
103 |
|
104 |
gbc.gridy = 5;
|
105 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
106 |
gbc.weighty = 0.0;
|
107 |
this.add(getAlgorithmOutputPanel(), gbc);
|
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 getComboPanel(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 getLayersCombo() { |
154 |
if(layersCombo == null) { |
155 |
layersCombo = new JComboBox(); |
156 |
layersCombo.setPreferredSize(new Dimension(0, 18)); |
157 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
158 |
layersCombo.setModel(comboModel); |
159 |
layersCombo.addActionListener(this);
|
160 |
} |
161 |
return layersCombo;
|
162 |
} |
163 |
|
164 |
|
165 |
/**
|
166 |
* Gets a CheckBox
|
167 |
* @return
|
168 |
*/
|
169 |
public JCheckBox getSelectionCheck() { |
170 |
if(selectionOnly == null) { |
171 |
selectionOnly = new JCheckBox(Sextante.getText("Selected_geometries")); |
172 |
} |
173 |
return selectionOnly;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* Panel with the projection selector
|
178 |
* @return
|
179 |
*/
|
180 |
private CRSSelectPanel getProjectionSelector() {
|
181 |
if (projectionSrcSelector == null) { |
182 |
targetLayerProjection = CRSFactory.getCRS("EPSG:23030");
|
183 |
projectionSrcSelector = CRSSelectPanel.getPanel(targetLayerProjection); |
184 |
projectionSrcSelector.getJLabel().setText(Sextante.getText("Proyeccion_Destino"));
|
185 |
projectionSrcSelector.setPreferredSize(new java.awt.Dimension(330,35)); |
186 |
projectionSrcSelector.addActionListener(new java.awt.event.ActionListener() {
|
187 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
188 |
if (projectionSrcSelector.isOkPressed()) {
|
189 |
targetLayerProjection = projectionSrcSelector.getCurProj(); |
190 |
} |
191 |
} |
192 |
}); |
193 |
} |
194 |
projectionSrcSelector.setTransPanelActive(true);
|
195 |
return projectionSrcSelector;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Gets the label with the current projection
|
200 |
* @return
|
201 |
*/
|
202 |
public JLabel getCurrentProjLabel() { |
203 |
if(projLabel == null) |
204 |
projLabel = new JLabel(); |
205 |
return projLabel;
|
206 |
} |
207 |
|
208 |
//------------------------------------------------------------
|
209 |
|
210 |
/**
|
211 |
* Initialize actions
|
212 |
*/
|
213 |
private void init() { |
214 |
IVectorLayer layer = getSelectedVectorLayer(); |
215 |
IProjection currentProj = (IProjection)layer.getCRS(); |
216 |
getCurrentProjLabel().setText("Proj: " + currentProj.getAbrev());
|
217 |
} |
218 |
|
219 |
/*
|
220 |
* (non-Javadoc)
|
221 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
222 |
*/
|
223 |
public void actionPerformed(ActionEvent e) { |
224 |
if(e.getSource() == getLayersCombo()) {
|
225 |
|
226 |
} |
227 |
} |
228 |
|
229 |
@Override
|
230 |
public void assignParameters() { |
231 |
try {
|
232 |
ParametersSet params = m_Algorithm.getParameters(); |
233 |
params.getParameter(ReprojectAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
234 |
params.getParameter(ReprojectAlgorithm.SELECTED_GEOM).setParameterValue(getSelectionCheck().isSelected()); |
235 |
String proj = getProjectionSelector().getCurProj().getAbrev();
|
236 |
params.getParameter(ReprojectAlgorithm.DST_PROJECTION).setParameterValue(proj); |
237 |
|
238 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
239 |
Output out = ooSet.getOutput(ReprojectAlgorithm.RESULT); |
240 |
out.setOutputChannel(new CompositeSourceOutputChannel(getAlgorithmOutputPanel().getOutputParameters()));
|
241 |
} catch (Exception e) { |
242 |
Sextante.addErrorToLog(e); |
243 |
} |
244 |
} |
245 |
|
246 |
@Override
|
247 |
public void setOutputValue(String arg0, String arg1) { |
248 |
|
249 |
} |
250 |
|
251 |
@Override
|
252 |
public void setParameterValue(String arg0, String arg1) { |
253 |
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* Gets the input layer list
|
258 |
* @return
|
259 |
*/
|
260 |
private ObjectAndDescription[] getLayerList() { |
261 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
262 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
263 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
264 |
for (int i = 0; i < layers.length; i++) |
265 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
266 |
return oad;
|
267 |
} |
268 |
|
269 |
/**
|
270 |
* Gets the selected vector layer in the JComboBox
|
271 |
* @return
|
272 |
*/
|
273 |
private IVectorLayer getSelectedVectorLayer() {
|
274 |
if(layersCombo.getSelectedItem() != null) |
275 |
return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
|
276 |
return null; |
277 |
} |
278 |
|
279 |
/**
|
280 |
* Gets the field list of the selected layer
|
281 |
* @return
|
282 |
*/
|
283 |
public String[] getFieldList() { |
284 |
IVectorLayer layer = getSelectedVectorLayer(); |
285 |
String[] data = new String[layer.getFieldCount()]; |
286 |
for (int i = 0; i < layer.getFieldCount(); i++) |
287 |
data[i] = layer.getFieldName(i); |
288 |
return data;
|
289 |
} |
290 |
} |