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