svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.daltransform.app / org.gvsig.daltransform.app.eventtheme / src / main / java / org / gvsig / app / eventtheme / daltransform / EventThemeTransformPanel.java @ 43213
History | View | Annotate | Download (11 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2009 {Iver T.I.} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.app.eventtheme.daltransform; |
30 |
|
31 |
import java.awt.BorderLayout; |
32 |
import java.awt.Insets; |
33 |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
35 |
|
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JLabel; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.JTextField; |
40 |
|
41 |
import org.cresques.cts.IProjection; |
42 |
|
43 |
import org.gvsig.andami.PluginServices; |
44 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
45 |
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel; |
46 |
import org.gvsig.app.project.ProjectPreferences; |
47 |
import org.gvsig.daltransform.swing.DataTransformWizard; |
48 |
import org.gvsig.daltransform.swing.impl.AbstractDataTransformWizardPanel; |
49 |
import org.gvsig.daltransform.swing.impl.DefaultDataTransformWizard; |
50 |
import org.gvsig.daltransform.swing.impl.components.FeatureTypeCombo; |
51 |
import org.gvsig.daltransform.swing.impl.components.NumericFeatureTypeAttributesCombo; |
52 |
import org.gvsig.fmap.crs.CRSFactory; |
53 |
import org.gvsig.fmap.dal.exception.DataException; |
54 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 |
import org.gvsig.fmap.dal.feature.FeatureType; |
56 |
import org.gvsig.fmap.mapcontext.MapContext; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
59 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
60 |
|
61 |
|
62 |
/**
|
63 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
64 |
*/
|
65 |
public class EventThemeTransformPanel extends AbstractDataTransformWizardPanel implements ActionListener { |
66 |
private JLabel nameLabel; |
67 |
private JTextField nameText; |
68 |
private NumericFeatureTypeAttributesCombo xCombo;
|
69 |
private JLabel xLabel; |
70 |
private NumericFeatureTypeAttributesCombo yCombo;
|
71 |
private JLabel yLabel; |
72 |
private FeatureTypeCombo featureTypeCombo;
|
73 |
private JLabel featureTypeLabel; |
74 |
private JPanel northPanel = null; |
75 |
private JTextField projectionText; |
76 |
private JLabel projectionLabel; |
77 |
private JButton projectionButton = null; |
78 |
|
79 |
public EventThemeTransformPanel() {
|
80 |
super();
|
81 |
initComponents(); |
82 |
initLabels(); |
83 |
resetProjection(); |
84 |
featureTypeCombo.addActionListener(this);
|
85 |
projectionButton.addActionListener(this);
|
86 |
} |
87 |
|
88 |
private void resetProjection() { |
89 |
|
90 |
DefaultDataTransformWizard dtw = getDataTransformWizard(); |
91 |
if (dtw != null) { |
92 |
MapContext mco = dtw.getMapContext(); |
93 |
if (mco != null && mco.getProjection() != null) { |
94 |
projectionText.setText(mco.getProjection().getAbrev()); |
95 |
return;
|
96 |
} |
97 |
} |
98 |
|
99 |
ProjectPreferences prefs = new ProjectPreferences();
|
100 |
projectionText.setText(prefs.getDefaultProjection().getAbrev()); |
101 |
} |
102 |
|
103 |
|
104 |
public void setDataTransformWizard(DataTransformWizard dtw) { |
105 |
super.setDataTransformWizard(dtw);
|
106 |
resetProjection(); |
107 |
} |
108 |
|
109 |
private void initLabels() { |
110 |
featureTypeLabel.setText(PluginServices.getText(this, "events_feature_type_field") + ":"); |
111 |
xLabel.setText(PluginServices.getText(this, "events_x_field") + ":"); |
112 |
yLabel.setText(PluginServices.getText(this, "events_y_field") + ":"); |
113 |
nameLabel.setText(PluginServices.getText(this, "events_geom_field") + ":"); |
114 |
projectionLabel.setText(PluginServices.getText(this, "projection") + ":"); |
115 |
projectionButton.setText("...");
|
116 |
} |
117 |
|
118 |
private void initComponents() { |
119 |
java.awt.GridBagConstraints gridBagConstraints; |
120 |
|
121 |
featureTypeCombo = new FeatureTypeCombo();
|
122 |
featureTypeLabel = new javax.swing.JLabel();
|
123 |
xLabel = new javax.swing.JLabel();
|
124 |
xCombo = new NumericFeatureTypeAttributesCombo();
|
125 |
yLabel = new javax.swing.JLabel();
|
126 |
yCombo = new NumericFeatureTypeAttributesCombo();
|
127 |
nameLabel = new javax.swing.JLabel();
|
128 |
nameText = new javax.swing.JTextField();
|
129 |
northPanel= new JPanel(); |
130 |
projectionText = new JTextField(); |
131 |
projectionLabel = new JLabel(); |
132 |
projectionButton = new JButton(); |
133 |
projectionButton.setSize(25, 25); |
134 |
projectionText.setEnabled(false);
|
135 |
|
136 |
setLayout(new BorderLayout()); |
137 |
northPanel.setLayout(new java.awt.GridBagLayout());
|
138 |
|
139 |
// gridBagConstraints = new java.awt.GridBagConstraints();
|
140 |
// gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
|
141 |
// gridBagConstraints.insets = new Insets(5,2,2,2);
|
142 |
// northPanel.add(featureTypeLabel, gridBagConstraints);
|
143 |
//
|
144 |
// featureTypeCombo.setModel(new javax.swing.DefaultComboBoxModel());
|
145 |
// gridBagConstraints = new java.awt.GridBagConstraints();
|
146 |
// gridBagConstraints.gridx = 0;
|
147 |
// gridBagConstraints.gridy = 1;
|
148 |
// gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
|
149 |
// gridBagConstraints.weightx = 1.0;
|
150 |
// gridBagConstraints.insets = new Insets(2,2,5,2);
|
151 |
// northPanel.add(featureTypeCombo, gridBagConstraints);
|
152 |
|
153 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
154 |
gridBagConstraints.gridx = 0;
|
155 |
gridBagConstraints.gridy = 0;
|
156 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
157 |
gridBagConstraints.gridwidth = 2;
|
158 |
gridBagConstraints.insets = new Insets(5,2,2,2); |
159 |
northPanel.add(xLabel, gridBagConstraints); |
160 |
|
161 |
xCombo.setModel(new javax.swing.DefaultComboBoxModel());
|
162 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
163 |
gridBagConstraints.gridx = 0;
|
164 |
gridBagConstraints.gridy = 1;
|
165 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
166 |
gridBagConstraints.gridwidth = 2;
|
167 |
gridBagConstraints.insets = new Insets(2,2,5,2); |
168 |
gridBagConstraints.weightx = 1.0;
|
169 |
northPanel.add(xCombo, gridBagConstraints); |
170 |
|
171 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
172 |
gridBagConstraints.gridx = 0;
|
173 |
gridBagConstraints.gridy = 2;
|
174 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
175 |
gridBagConstraints.insets = new Insets(5,2,2,2); |
176 |
gridBagConstraints.gridwidth = 2;
|
177 |
northPanel.add(yLabel, gridBagConstraints); |
178 |
|
179 |
yCombo.setModel(new javax.swing.DefaultComboBoxModel());
|
180 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
181 |
gridBagConstraints.gridx = 0;
|
182 |
gridBagConstraints.gridy = 3;
|
183 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
184 |
gridBagConstraints.weightx = 1.0;
|
185 |
gridBagConstraints.insets = new Insets(2,2,5,2); |
186 |
gridBagConstraints.gridwidth = 2;
|
187 |
northPanel.add(yCombo, gridBagConstraints); |
188 |
|
189 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
190 |
gridBagConstraints.gridx = 0;
|
191 |
gridBagConstraints.gridy = 4;
|
192 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
193 |
gridBagConstraints.insets = new Insets(5,2,2,2); |
194 |
gridBagConstraints.gridwidth = 2;
|
195 |
northPanel.add(nameLabel, gridBagConstraints); |
196 |
|
197 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
198 |
gridBagConstraints.gridx = 0;
|
199 |
gridBagConstraints.gridy = 5;
|
200 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
201 |
gridBagConstraints.weightx = 1.0;
|
202 |
gridBagConstraints.insets = new Insets(2,2,5,2); |
203 |
gridBagConstraints.gridwidth = 2;
|
204 |
northPanel.add(nameText, gridBagConstraints); |
205 |
|
206 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
207 |
gridBagConstraints.gridx = 0;
|
208 |
gridBagConstraints.gridy = 6;
|
209 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
210 |
gridBagConstraints.gridwidth = 2;
|
211 |
gridBagConstraints.insets = new Insets(5,2,2,2); |
212 |
northPanel.add(projectionLabel, gridBagConstraints); |
213 |
|
214 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
215 |
gridBagConstraints.gridx = 0;
|
216 |
gridBagConstraints.gridy = 7;
|
217 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
218 |
gridBagConstraints.weightx = 1.0;
|
219 |
gridBagConstraints.gridwidth = 1;
|
220 |
gridBagConstraints.insets = new Insets(2,2,5,2); |
221 |
northPanel.add(projectionText, gridBagConstraints); |
222 |
|
223 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
224 |
gridBagConstraints.gridx = 1;
|
225 |
gridBagConstraints.gridy = 7;
|
226 |
gridBagConstraints.gridwidth = 1;
|
227 |
gridBagConstraints.insets = new Insets(2,2,5,2); |
228 |
northPanel.add(projectionButton, gridBagConstraints); |
229 |
|
230 |
add(northPanel, BorderLayout.NORTH);
|
231 |
} |
232 |
|
233 |
/* (non-Javadoc)
|
234 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
235 |
*/
|
236 |
public void actionPerformed(ActionEvent event) { |
237 |
if (event == null){ |
238 |
return;
|
239 |
} |
240 |
if (event.getSource() == featureTypeCombo){
|
241 |
Object obj = featureTypeCombo.getSelectedItem();
|
242 |
if (obj != null){ |
243 |
xCombo.addFeatureAttributes(featureTypeCombo.getSelectedFeatureType()); |
244 |
yCombo.addFeatureAttributes(featureTypeCombo.getSelectedFeatureType()); |
245 |
} |
246 |
}else if (event.getSource() == projectionButton){ |
247 |
ISelectCrsPanel panel = CRSSelectPanel.getUIFactory().getSelectCrsPanel( |
248 |
CRSFactory.getCRS(projectionText.getText()), false);
|
249 |
ToolsSwingLocator.getWindowManager().showWindow( |
250 |
panel.asJComponent(), |
251 |
ToolsLocator.getI18nManager().getTranslation("selecciona_sistema_de_referencia"),
|
252 |
WindowManager.MODE.DIALOG |
253 |
); |
254 |
if (panel.isOkPressed()) {
|
255 |
IProjection proj = panel.getProjection(); |
256 |
projectionText.setText(proj.getAbrev()); |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
public String getGeometryName(){ |
262 |
return nameText.getText();
|
263 |
} |
264 |
|
265 |
public String getXName(){ |
266 |
return xCombo.getSelectedFeatureAttributeDescriptor().getName();
|
267 |
} |
268 |
|
269 |
public String getYName(){ |
270 |
return yCombo.getSelectedFeatureAttributeDescriptor().getName();
|
271 |
} |
272 |
|
273 |
/*
|
274 |
* (non-Javadoc)
|
275 |
* @see org.gvsig.app.daltransform.impl.AbstractDataTransformWizardPanel#updatePanel()
|
276 |
*/
|
277 |
public void updatePanel() { |
278 |
featureTypeCombo.addFeatureStore(getFeatureStore()); |
279 |
if (nameText != null) { |
280 |
nameText.setText(this.suggestedGeomFieldName(getFeatureStore()));
|
281 |
} |
282 |
// actionPerformed(null);
|
283 |
} |
284 |
|
285 |
public IProjection getProjection() {
|
286 |
return CRSFactory.getCRS(projectionText.getText());
|
287 |
} |
288 |
|
289 |
private String suggestedGeomFieldName(FeatureStore fsto) { |
290 |
|
291 |
if (fsto == null) { |
292 |
return ""; |
293 |
} |
294 |
|
295 |
FeatureType ft = null;
|
296 |
try {
|
297 |
ft = fsto.getDefaultFeatureType(); |
298 |
} catch (DataException e) {
|
299 |
logger.info("Error: unable to suggest geom field name.", e);
|
300 |
return ""; |
301 |
} |
302 |
|
303 |
if (ft.getAttributeDescriptor("geometry") == null) { |
304 |
return "geometry"; |
305 |
} |
306 |
if (ft.getAttributeDescriptor("geom") == null) { |
307 |
return "geom"; |
308 |
} |
309 |
String aux = ""; |
310 |
int i = -1; |
311 |
do {
|
312 |
i++; |
313 |
aux = "geom" + i;
|
314 |
} while (ft.getAttributeDescriptor(aux) != null); |
315 |
|
316 |
return aux;
|
317 |
} |
318 |
} |