root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / UserTableSettingsVectorialPanel.java @ 38608
History | View | Annotate | Download (11.1 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.geodb.vectorialdb.wizard; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
|
32 |
import javax.swing.JCheckBox; |
33 |
import javax.swing.JComboBox; |
34 |
import javax.swing.JLabel; |
35 |
import javax.swing.JTextField; |
36 |
|
37 |
import org.cresques.cts.IProjection; |
38 |
import org.gvsig.andami.PluginServices; |
39 |
import org.gvsig.app.addlayer.AddLayerDialog; |
40 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
41 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
42 |
import org.gvsig.fmap.geom.GeometryLocator; |
43 |
import org.gvsig.fmap.geom.GeometryManager; |
44 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
45 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
46 |
import org.gvsig.fmap.geom.primitive.Envelope; |
47 |
import org.gvsig.fmap.mapcontrol.MapControl; |
48 |
import org.gvsig.gui.beans.swing.JButton; |
49 |
import org.slf4j.Logger; |
50 |
import org.slf4j.LoggerFactory; |
51 |
|
52 |
|
53 |
public class UserTableSettingsVectorialPanel extends UserTableSettingsPanel { |
54 |
private static Logger logger = LoggerFactory |
55 |
.getLogger(UserTableSettingsPanel.class.getName()); |
56 |
|
57 |
private FieldComboItem[] geos; |
58 |
private JComboBox geomComboBox = null; |
59 |
private JLabel geomLabel = null; |
60 |
private JLabel waLabel = null; |
61 |
private JLabel topLabel = null; |
62 |
private JTextField topTextField = null; |
63 |
private JTextField bottomTextField = null; |
64 |
private JTextField rightTextField = null; |
65 |
private JTextField leftTextField = null; |
66 |
private JLabel bottomLabel = null; |
67 |
private JLabel rightLabel = null; |
68 |
private JLabel leftLabel = null; |
69 |
private JButton getviewButton = null; |
70 |
private JCheckBox activateWACheckBox = null; |
71 |
private MapControl mControl = null; |
72 |
private CRSSelectPanel panelProj;
|
73 |
private IProjection currentProj;
|
74 |
|
75 |
public UserTableSettingsVectorialPanel(FieldComboItem[] idComboItems, |
76 |
FieldComboItem[] geoComboItems, String initialLayerName, |
77 |
MapControl mapc, boolean empty, WizardVectorialDB _p,
|
78 |
DBStoreParameters parameters, |
79 |
IProjection curProjection) { |
80 |
super();
|
81 |
setInitValues(idComboItems, initialLayerName, empty, _p, parameters); |
82 |
|
83 |
mControl = mapc; |
84 |
geos = geoComboItems; |
85 |
currentProj = curProjection; |
86 |
initialize(empty); |
87 |
} |
88 |
|
89 |
protected void initialize(boolean _empty) { |
90 |
super.initialize(_empty);
|
91 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
92 |
PluginServices.getText(this, "specify_table_settings"), |
93 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
94 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
95 |
leftLabel = new JLabel(); |
96 |
// leftLabel.setBounds(new java.awt.Rectangle(375, 175, 111, 16));
|
97 |
leftLabel.setBounds(new java.awt.Rectangle(375, 200, 111, 16)); |
98 |
leftLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
99 |
leftLabel.setText(PluginServices.getText(this, "xmin")); |
100 |
rightLabel = new JLabel(); |
101 |
rightLabel.setBounds(new java.awt.Rectangle(260, 200, 111, 16)); |
102 |
rightLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
103 |
rightLabel.setText(PluginServices.getText(this, "xmax")); |
104 |
bottomLabel = new JLabel(); |
105 |
bottomLabel.setBounds(new java.awt.Rectangle(130, 200, 111, 16)); |
106 |
bottomLabel |
107 |
.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
108 |
bottomLabel.setText(PluginServices.getText(this, "ymin")); |
109 |
topLabel = new JLabel(); |
110 |
topLabel.setBounds(new java.awt.Rectangle(15, 200, 111, 16)); |
111 |
topLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
112 |
topLabel.setText(PluginServices.getText(this, "ymax")); |
113 |
waLabel = new JLabel(); |
114 |
// waLabel.setBounds(new java.awt.Rectangle(40, 145, 131, 21));
|
115 |
waLabel.setBounds(new java.awt.Rectangle(30, 172, 131, 21)); |
116 |
waLabel.setText(PluginServices.getText(this, "working_area")); |
117 |
geomLabel = new JLabel(); |
118 |
// geomLabel.setBounds(new java.awt.Rectangle(240, 55, 111, 21));
|
119 |
geomLabel.setBounds(new java.awt.Rectangle(5, 145, 111, 21)); |
120 |
geomLabel.setText(PluginServices.getText(this, "geo_field")); |
121 |
|
122 |
add(getGeomComboBox(), null);
|
123 |
add(geomLabel, null);
|
124 |
add(waLabel, null);
|
125 |
add(topLabel, null);
|
126 |
add(getTopTextField(), null);
|
127 |
add(getBottomTextField(), null);
|
128 |
add(getRightTextField(), null);
|
129 |
add(getLeftTextField(), null);
|
130 |
add(bottomLabel, null);
|
131 |
add(rightLabel, null);
|
132 |
add(leftLabel, null);
|
133 |
add(getGetviewButton(), null);
|
134 |
add(getActivateWACheckBox(), null);
|
135 |
loadValues(_empty); |
136 |
} |
137 |
|
138 |
private CRSSelectPanel getJPanelProj() {
|
139 |
if (panelProj == null) { |
140 |
panelProj = CRSSelectPanel.getPanel(currentProj); |
141 |
|
142 |
panelProj.setTransPanelActive(true);
|
143 |
panelProj.setLocation(new java.awt.Point(-10, 110)); |
144 |
panelProj.addActionListener(new java.awt.event.ActionListener() {
|
145 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
146 |
if (panelProj.isOkPressed()) {
|
147 |
AddLayerDialog |
148 |
.setLastProjection(panelProj.getCurProj()); |
149 |
} |
150 |
} |
151 |
}); |
152 |
} |
153 |
return panelProj;
|
154 |
} |
155 |
|
156 |
|
157 |
public boolean hasValidValues() { |
158 |
if (!super.hasValidValues()) { |
159 |
return false; |
160 |
} |
161 |
|
162 |
if ((activateWACheckBox.isSelected()) && (getWorkingArea() == null)) { |
163 |
return false; |
164 |
} |
165 |
|
166 |
return true; |
167 |
} |
168 |
|
169 |
private JComboBox getGeomComboBox() { |
170 |
if (geomComboBox == null) { |
171 |
geomComboBox = new JComboBox(); |
172 |
// geomComboBox.setBounds(new java.awt.Rectangle(355, 55, 131, 21));
|
173 |
geomComboBox.setBounds(new java.awt.Rectangle(120, 145, 118, 21)); |
174 |
} |
175 |
|
176 |
return geomComboBox;
|
177 |
} |
178 |
|
179 |
private JTextField getTopTextField() { |
180 |
if (topTextField == null) { |
181 |
topTextField = new JTextField(); |
182 |
topTextField.addKeyListener(this);
|
183 |
// topTextField.setBounds(new java.awt.Rectangle(15, 190, 111, 21));
|
184 |
topTextField.setBounds(new java.awt.Rectangle(15, 215, 111, 21)); |
185 |
} |
186 |
|
187 |
return topTextField;
|
188 |
} |
189 |
|
190 |
private JTextField getBottomTextField() { |
191 |
if (bottomTextField == null) { |
192 |
bottomTextField = new JTextField(); |
193 |
bottomTextField.addKeyListener(this);
|
194 |
bottomTextField |
195 |
.setBounds(new java.awt.Rectangle(130, 215, 111, 21)); |
196 |
} |
197 |
|
198 |
return bottomTextField;
|
199 |
} |
200 |
|
201 |
private JTextField getRightTextField() { |
202 |
if (rightTextField == null) { |
203 |
rightTextField = new JTextField(); |
204 |
rightTextField.addKeyListener(this);
|
205 |
rightTextField.setBounds(new java.awt.Rectangle(260, 215, 111, 21)); |
206 |
} |
207 |
|
208 |
return rightTextField;
|
209 |
} |
210 |
|
211 |
private JTextField getLeftTextField() { |
212 |
if (leftTextField == null) { |
213 |
leftTextField = new JTextField(); |
214 |
leftTextField.addKeyListener(this);
|
215 |
leftTextField.setBounds(new java.awt.Rectangle(375, 215, 111, 21)); |
216 |
} |
217 |
|
218 |
return leftTextField;
|
219 |
} |
220 |
|
221 |
private JButton getGetviewButton() { |
222 |
if (getviewButton == null) { |
223 |
getviewButton = new JButton(); |
224 |
getviewButton.addActionListener(this);
|
225 |
//getviewButton.setBounds(new java.awt.Rectangle(195, 145, 111, 26));
|
226 |
getviewButton.setBounds(new java.awt.Rectangle(160, 174, 111, 26)); |
227 |
getviewButton.setForeground(java.awt.Color.black); |
228 |
getviewButton.setText(PluginServices.getText(this, "get_view")); |
229 |
} |
230 |
|
231 |
return getviewButton;
|
232 |
} |
233 |
|
234 |
private JCheckBox getActivateWACheckBox() { |
235 |
if (activateWACheckBox == null) { |
236 |
activateWACheckBox = new JCheckBox(); |
237 |
activateWACheckBox.addActionListener(this);
|
238 |
// activateWACheckBox
|
239 |
// .setBounds(new java.awt.Rectangle(15, 145, 21, 21));
|
240 |
activateWACheckBox |
241 |
.setBounds(new java.awt.Rectangle(5, 172, 21, 21)); |
242 |
|
243 |
} |
244 |
|
245 |
return activateWACheckBox;
|
246 |
} |
247 |
|
248 |
protected void loadValues(boolean is_empty) { |
249 |
super.loadValues(is_empty);
|
250 |
if (is_empty) {
|
251 |
enableAlphaControls(false);
|
252 |
enableSpatialControls(false);
|
253 |
getActivateWACheckBox().setSelected(false);
|
254 |
} else {
|
255 |
enableAlphaControls(true);
|
256 |
enableSpatialControls(true);
|
257 |
|
258 |
getGeomComboBox().removeAllItems(); |
259 |
|
260 |
for (int i = 0; i < geos.length; i++) { |
261 |
getGeomComboBox().addItem(geos[i]); |
262 |
} |
263 |
|
264 |
add(getJPanelProj(), null);
|
265 |
|
266 |
} |
267 |
} |
268 |
|
269 |
public void enableSpatialControls(boolean enable) { |
270 |
super.enableSpatialControls(enable);
|
271 |
getGeomComboBox().setEnabled(enable); |
272 |
|
273 |
getActivateWACheckBox().setEnabled(enable); |
274 |
|
275 |
boolean there_is_view = ((mControl != null) && (mControl.getViewPort() |
276 |
.getAdjustedExtent() != null));
|
277 |
|
278 |
getGetviewButton().setEnabled(enable && there_is_view); |
279 |
getTopTextField().setEnabled(enable); |
280 |
getBottomTextField().setEnabled(enable); |
281 |
getRightTextField().setEnabled(enable); |
282 |
getLeftTextField().setEnabled(enable); |
283 |
} |
284 |
|
285 |
public void actionPerformed(ActionEvent e) { |
286 |
super.actionPerformed(e);
|
287 |
Object src = e.getSource();
|
288 |
|
289 |
if (src == getviewButton) {
|
290 |
getViewIntoFourBounds(); |
291 |
parent.checkFinishable(); |
292 |
} |
293 |
|
294 |
if (src == activateWACheckBox) {
|
295 |
enableWASettings(activateWACheckBox.isSelected()); |
296 |
parent.checkFinishable(); |
297 |
} |
298 |
} |
299 |
|
300 |
private void enableWASettings(boolean b) { |
301 |
getviewButton.setEnabled(b |
302 |
&& (mControl.getViewPort().getAdjustedExtent() != null));
|
303 |
rightTextField.setEnabled(b); |
304 |
leftTextField.setEnabled(b); |
305 |
topTextField.setEnabled(b); |
306 |
bottomTextField.setEnabled(b); |
307 |
} |
308 |
|
309 |
private void getViewIntoFourBounds() { |
310 |
Envelope rect = mControl.getViewPort().getAdjustedExtent(); |
311 |
topTextField.setText(getFormattedDouble(rect.getMaximum(1)));
|
312 |
bottomTextField.setText(getFormattedDouble(rect.getMinimum(1)));
|
313 |
rightTextField.setText(getFormattedDouble(rect.getMaximum(0)));
|
314 |
leftTextField.setText(getFormattedDouble(rect.getMinimum(0)));
|
315 |
} |
316 |
|
317 |
public Envelope getWorkingArea() {
|
318 |
if (!activateWACheckBox.isSelected()) {
|
319 |
return null; |
320 |
} |
321 |
|
322 |
double maxx;
|
323 |
double maxy;
|
324 |
double minx;
|
325 |
double miny;
|
326 |
|
327 |
try {
|
328 |
maxx = Double.parseDouble(rightTextField.getText());
|
329 |
miny = Double.parseDouble(bottomTextField.getText());
|
330 |
minx = Double.parseDouble(leftTextField.getText());
|
331 |
maxy = Double.parseDouble(topTextField.getText());
|
332 |
} catch (NumberFormatException nfe) { |
333 |
logger.error("Not valid value: " + nfe.getMessage());
|
334 |
|
335 |
return null; |
336 |
} |
337 |
GeometryManager geoMan = GeometryLocator.getGeometryManager(); |
338 |
|
339 |
try {
|
340 |
return geoMan.createEnvelope(minx, miny, maxx, maxy,
|
341 |
SUBTYPES.GEOM2D); |
342 |
} catch (CreateEnvelopeException e) {
|
343 |
// FIXME Exception
|
344 |
throw new RuntimeException(e); |
345 |
} |
346 |
} |
347 |
|
348 |
public boolean combosHaveItems() { |
349 |
if (!super.combosHaveItems()) { |
350 |
return false; |
351 |
} |
352 |
|
353 |
if (getGeomComboBox().getItemCount() == 0) { |
354 |
return false; |
355 |
} |
356 |
|
357 |
return true; |
358 |
} |
359 |
|
360 |
public void repaint() { |
361 |
super.repaint();
|
362 |
getGeomComboBox().updateUI(); |
363 |
} |
364 |
|
365 |
public String getGeoFieldName() { |
366 |
if (getGeomComboBox().getSelectedItem() == null) { |
367 |
return null; |
368 |
} |
369 |
return getGeomComboBox().getSelectedItem().toString();
|
370 |
} |
371 |
public IProjection getProjection() {
|
372 |
return panelProj.getCurProj();
|
373 |
} |
374 |
|
375 |
} |