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