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