svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / wizard / UserTableSettingsVectorialPanel.java @ 40557
History | View | Annotate | Download (13.7 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 |
/* gvSIG. Geographic Information System of the Valencian Government
|
25 |
*
|
26 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
27 |
* of the Valencian Government (CIT)
|
28 |
*
|
29 |
* This program is free software; you can redistribute it and/or
|
30 |
* modify it under the terms of the GNU General Public License
|
31 |
* as published by the Free Software Foundation; either version 2
|
32 |
* of the License, or (at your option) any later version.
|
33 |
*
|
34 |
* This program is distributed in the hope that it will be useful,
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
37 |
* GNU General Public License for more details.
|
38 |
*
|
39 |
* You should have received a copy of the GNU General Public License
|
40 |
* along with this program; if not, write to the Free Software
|
41 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
42 |
* MA 02110-1301, USA.
|
43 |
*
|
44 |
*/
|
45 |
|
46 |
/*
|
47 |
* AUTHORS (In addition to CIT):
|
48 |
* 2009 IVER T.I {{Task}}
|
49 |
*/
|
50 |
|
51 |
package org.gvsig.geodb.vectorialdb.wizard; |
52 |
|
53 |
import java.awt.Insets; |
54 |
import java.awt.event.ActionEvent; |
55 |
import java.awt.event.ActionListener; |
56 |
|
57 |
import javax.swing.ImageIcon; |
58 |
import javax.swing.JButton; |
59 |
import javax.swing.JCheckBox; |
60 |
import javax.swing.JComboBox; |
61 |
import javax.swing.JLabel; |
62 |
import javax.swing.JPanel; |
63 |
import javax.swing.JTextField; |
64 |
|
65 |
import org.cresques.cts.IProjection; |
66 |
import org.slf4j.Logger; |
67 |
import org.slf4j.LoggerFactory; |
68 |
|
69 |
import org.gvsig.andami.IconThemeHelper; |
70 |
import org.gvsig.andami.PluginServices; |
71 |
import org.gvsig.app.addlayer.AddLayerDialog; |
72 |
import org.gvsig.app.gui.panels.CRSSelectPanel; |
73 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
74 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
75 |
import org.gvsig.fmap.geom.GeometryLocator; |
76 |
import org.gvsig.fmap.geom.GeometryManager; |
77 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
78 |
import org.gvsig.fmap.geom.primitive.Envelope; |
79 |
import org.gvsig.fmap.mapcontrol.MapControl; |
80 |
import org.gvsig.i18n.Messages; |
81 |
|
82 |
|
83 |
public class UserTableSettingsVectorialPanel extends UserTableSettingsPanel { |
84 |
private static Logger logger = LoggerFactory |
85 |
.getLogger(UserTableSettingsPanel.class.getName()); |
86 |
|
87 |
private FieldComboItem[] geos; |
88 |
private JComboBox geomComboBox = null; |
89 |
private JLabel geomLabel = null; |
90 |
private JLabel waLabel = null; |
91 |
private JLabel topLabel = null; |
92 |
private JTextField topTextField = null; |
93 |
private JTextField bottomTextField = null; |
94 |
private JTextField rightTextField = null; |
95 |
private JTextField leftTextField = null; |
96 |
private JLabel bottomLabel = null; |
97 |
private JLabel rightLabel = null; |
98 |
private JLabel leftLabel = null; |
99 |
private JButton getviewButton = null; |
100 |
private JCheckBox activateWACheckBox = null; |
101 |
private MapControl mControl = null; |
102 |
private CRSSelectPanel panelProj;
|
103 |
|
104 |
private IProjection proposedProjection = null; |
105 |
// private IProjection currentProj;
|
106 |
|
107 |
private JPanel this_panel = null; |
108 |
|
109 |
public UserTableSettingsVectorialPanel(FieldComboItem[] idComboItems, |
110 |
FieldComboItem[] geoComboItems, String initialLayerName, |
111 |
MapControl mapc, boolean empty, WizardVectorialDB _p,
|
112 |
DBStoreParameters parameters, |
113 |
IProjection proposed_proj) { |
114 |
super();
|
115 |
|
116 |
this_panel = this;
|
117 |
setInitValues(idComboItems, initialLayerName, empty, _p, parameters); |
118 |
|
119 |
mControl = mapc; |
120 |
geos = geoComboItems; |
121 |
proposedProjection = proposed_proj; |
122 |
initialize(empty); |
123 |
} |
124 |
|
125 |
protected void initialize(boolean _empty) { |
126 |
super.initialize(_empty);
|
127 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
128 |
PluginServices.getText(this, "_Table_settings"), |
129 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
130 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
131 |
leftLabel = new JLabel(); |
132 |
// leftLabel.setBounds(new java.awt.Rectangle(375, 175, 111, 16));
|
133 |
leftLabel.setBounds(new java.awt.Rectangle(80+70, 200, 70, 16)); |
134 |
leftLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
135 |
leftLabel.setText(PluginServices.getText(this, "xmin")); |
136 |
rightLabel = new JLabel(); |
137 |
rightLabel.setBounds(new java.awt.Rectangle(75+150, 200, 70, 16)); |
138 |
rightLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
139 |
rightLabel.setText(PluginServices.getText(this, "xmax")); |
140 |
bottomLabel = new JLabel(); |
141 |
bottomLabel.setBounds(new java.awt.Rectangle(70+230, 200, 70, 16)); |
142 |
bottomLabel |
143 |
.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
144 |
bottomLabel.setText(PluginServices.getText(this, "ymin")); |
145 |
topLabel = new JLabel(); |
146 |
topLabel.setBounds(new java.awt.Rectangle(65+310, 200, 70, 16)); |
147 |
topLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
148 |
topLabel.setText(PluginServices.getText(this, "ymax")); |
149 |
waLabel = new JLabel(); |
150 |
// waLabel.setBounds(new java.awt.Rectangle(40, 145, 131, 21));
|
151 |
waLabel.setBounds(new java.awt.Rectangle(30, 215, 125, 21)); |
152 |
waLabel.setText(PluginServices.getText(this, "_Working_area")); |
153 |
geomLabel = new JLabel(); |
154 |
// geomLabel.setBounds(new java.awt.Rectangle(240, 55, 111, 21));
|
155 |
geomLabel.setBounds(new java.awt.Rectangle(70, 140, 160, 21)); |
156 |
geomLabel.setText(PluginServices.getText(this, "_Geo_field")); |
157 |
|
158 |
add(getGeomComboBox(), null);
|
159 |
add(geomLabel, null);
|
160 |
add(waLabel, null);
|
161 |
add(topLabel, null);
|
162 |
add(getTopTextField(), null);
|
163 |
add(getBottomTextField(), null);
|
164 |
add(getRightTextField(), null);
|
165 |
add(getLeftTextField(), null);
|
166 |
add(bottomLabel, null);
|
167 |
add(rightLabel, null);
|
168 |
add(leftLabel, null);
|
169 |
add(getGetviewButton(), null);
|
170 |
add(getActivateWACheckBox(), null);
|
171 |
loadValues(_empty); |
172 |
} |
173 |
|
174 |
private CRSSelectPanel getJPanelProj(IProjection pro) {
|
175 |
if (panelProj == null) { |
176 |
panelProj = CRSSelectPanel.getPanel(pro); |
177 |
|
178 |
panelProj.setTransPanelActive(true);
|
179 |
panelProj.setBounds(70, 165, 350, 21); |
180 |
panelProj.addActionListener(new java.awt.event.ActionListener() {
|
181 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
182 |
if (panelProj.isOkPressed()) {
|
183 |
AddLayerDialog |
184 |
.setLastProjection(panelProj.getCurProj()); |
185 |
} |
186 |
} |
187 |
}); |
188 |
} |
189 |
return panelProj;
|
190 |
} |
191 |
|
192 |
|
193 |
public boolean hasValidValues() { |
194 |
if (!super.hasValidValues()) { |
195 |
return false; |
196 |
} |
197 |
|
198 |
if ((activateWACheckBox.isSelected()) && (getWorkingArea() == null)) { |
199 |
return false; |
200 |
} |
201 |
|
202 |
return true; |
203 |
} |
204 |
|
205 |
private JComboBox getGeomComboBox() { |
206 |
if (geomComboBox == null) { |
207 |
geomComboBox = new JComboBox(); |
208 |
// geomComboBox.setBounds(new java.awt.Rectangle(355, 55, 131, 21));
|
209 |
geomComboBox.setBounds(new java.awt.Rectangle(243, 140, 174, 21)); |
210 |
geomComboBox.addActionListener(new ActionListener() { |
211 |
public void actionPerformed(ActionEvent e) { |
212 |
|
213 |
if (panelProj == null) { |
214 |
return;
|
215 |
} |
216 |
/*
|
217 |
* Set the proj of the field in the
|
218 |
* SRS chooser
|
219 |
*/
|
220 |
FieldComboItem fci = (FieldComboItem) geomComboBox.getSelectedItem(); |
221 |
|
222 |
if (fci == null) { |
223 |
return;
|
224 |
} |
225 |
|
226 |
IProjection iproj = fci.getProjection(); |
227 |
if (iproj != null) { |
228 |
/*
|
229 |
* Remove and recreate crs selection panel
|
230 |
*/
|
231 |
this_panel.remove(panelProj); |
232 |
panelProj = null;
|
233 |
add(getJPanelProj(iproj), null);
|
234 |
} |
235 |
} |
236 |
}); |
237 |
} |
238 |
|
239 |
return geomComboBox;
|
240 |
} |
241 |
|
242 |
private JTextField getTopTextField() { |
243 |
if (topTextField == null) { |
244 |
topTextField = new JTextField(); |
245 |
topTextField.addKeyListener(this);
|
246 |
// topTextField.setBounds(new java.awt.Rectangle(15, 190, 111, 21));
|
247 |
topTextField.setBounds(new java.awt.Rectangle(65+310, 215, 70, 21)); |
248 |
} |
249 |
|
250 |
return topTextField;
|
251 |
} |
252 |
|
253 |
private JTextField getBottomTextField() { |
254 |
if (bottomTextField == null) { |
255 |
bottomTextField = new JTextField(); |
256 |
bottomTextField.addKeyListener(this);
|
257 |
bottomTextField |
258 |
.setBounds(new java.awt.Rectangle(70+230, 215, 70, 21)); |
259 |
} |
260 |
|
261 |
return bottomTextField;
|
262 |
} |
263 |
|
264 |
private JTextField getRightTextField() { |
265 |
if (rightTextField == null) { |
266 |
rightTextField = new JTextField(); |
267 |
rightTextField.addKeyListener(this);
|
268 |
rightTextField.setBounds(new java.awt.Rectangle(75+150, 215, 70, 21)); |
269 |
} |
270 |
|
271 |
return rightTextField;
|
272 |
} |
273 |
|
274 |
private JTextField getLeftTextField() { |
275 |
if (leftTextField == null) { |
276 |
leftTextField = new JTextField(); |
277 |
leftTextField.addKeyListener(this);
|
278 |
leftTextField.setBounds(new java.awt.Rectangle(80+70, 215, 70, 21)); |
279 |
} |
280 |
|
281 |
return leftTextField;
|
282 |
} |
283 |
|
284 |
private JButton getGetviewButton() { |
285 |
if (getviewButton == null) { |
286 |
getviewButton = new org.gvsig.gui.beans.swing.JButton();
|
287 |
getviewButton.addActionListener(this);
|
288 |
//getviewButton.setBounds(new java.awt.Rectangle(195, 145, 111, 26));
|
289 |
getviewButton.setBounds(new java.awt.Rectangle(455, 205, 31, 31)); |
290 |
ImageIcon ii = IconThemeHelper.getImageIcon("geodb-get-view-extent"); |
291 |
// ImageIcon ii = IconThemeHelper.getImageIcon("geodb-connection-add");
|
292 |
|
293 |
getviewButton.setMargin(new Insets(1,1,1,1)); |
294 |
getviewButton.setIcon(ii); |
295 |
getviewButton.setToolTipText( |
296 |
Messages.getText("_Get_view_extent"));
|
297 |
getviewButton.setEnabled(false);
|
298 |
} |
299 |
|
300 |
return getviewButton;
|
301 |
} |
302 |
|
303 |
private JCheckBox getActivateWACheckBox() { |
304 |
if (activateWACheckBox == null) { |
305 |
activateWACheckBox = new JCheckBox(); |
306 |
activateWACheckBox.addActionListener(this);
|
307 |
// activateWACheckBox
|
308 |
// .setBounds(new java.awt.Rectangle(15, 145, 21, 21));
|
309 |
activateWACheckBox |
310 |
.setBounds(new java.awt.Rectangle(5, 215, 21, 21)); |
311 |
|
312 |
} |
313 |
|
314 |
return activateWACheckBox;
|
315 |
} |
316 |
|
317 |
protected void loadValues(boolean is_empty) { |
318 |
super.loadValues(is_empty);
|
319 |
if (is_empty) {
|
320 |
enableAlphaControls(false);
|
321 |
enableSpatialControls(false);
|
322 |
getActivateWACheckBox().setSelected(false);
|
323 |
} else {
|
324 |
enableAlphaControls(true);
|
325 |
enableSpatialControls(true);
|
326 |
|
327 |
getGeomComboBox().removeAllItems(); |
328 |
|
329 |
for (int i = 0; i < geos.length; i++) { |
330 |
getGeomComboBox().addItem(geos[i]); |
331 |
} |
332 |
add(getJPanelProj(proposedProjection), null);
|
333 |
} |
334 |
} |
335 |
|
336 |
public void enableSpatialControls(boolean enable) { |
337 |
super.enableSpatialControls(enable);
|
338 |
getGeomComboBox().setEnabled(enable); |
339 |
|
340 |
getActivateWACheckBox().setEnabled(enable); |
341 |
|
342 |
boolean there_is_view = ((mControl != null) && |
343 |
(mControl.getViewPort().getAdjustedEnvelope() != null));
|
344 |
|
345 |
getGetviewButton().setEnabled(enable && there_is_view); |
346 |
getTopTextField().setEnabled(enable); |
347 |
getBottomTextField().setEnabled(enable); |
348 |
getRightTextField().setEnabled(enable); |
349 |
getLeftTextField().setEnabled(enable); |
350 |
} |
351 |
|
352 |
public void actionPerformed(ActionEvent e) { |
353 |
super.actionPerformed(e);
|
354 |
Object src = e.getSource();
|
355 |
|
356 |
if (src == getviewButton) {
|
357 |
getViewIntoFourBounds(); |
358 |
parent.checkFinishable(); |
359 |
} |
360 |
|
361 |
if (src == activateWACheckBox) {
|
362 |
enableWASettings(activateWACheckBox.isSelected()); |
363 |
parent.checkFinishable(); |
364 |
} |
365 |
} |
366 |
|
367 |
private void enableWASettings(boolean b) { |
368 |
getviewButton.setEnabled(b |
369 |
&& (mControl.getViewPort().getAdjustedEnvelope() != null));
|
370 |
rightTextField.setEnabled(b); |
371 |
leftTextField.setEnabled(b); |
372 |
topTextField.setEnabled(b); |
373 |
bottomTextField.setEnabled(b); |
374 |
} |
375 |
|
376 |
private void getViewIntoFourBounds() { |
377 |
Envelope rect = mControl.getViewPort().getAdjustedEnvelope(); |
378 |
topTextField.setText(getFormattedDouble(rect.getMaximum(1)));
|
379 |
bottomTextField.setText(getFormattedDouble(rect.getMinimum(1)));
|
380 |
rightTextField.setText(getFormattedDouble(rect.getMaximum(0)));
|
381 |
leftTextField.setText(getFormattedDouble(rect.getMinimum(0)));
|
382 |
} |
383 |
|
384 |
public Envelope getWorkingArea() {
|
385 |
if (!activateWACheckBox.isSelected()) {
|
386 |
return null; |
387 |
} |
388 |
|
389 |
double maxx;
|
390 |
double maxy;
|
391 |
double minx;
|
392 |
double miny;
|
393 |
|
394 |
try {
|
395 |
maxx = Double.parseDouble(rightTextField.getText());
|
396 |
miny = Double.parseDouble(bottomTextField.getText());
|
397 |
minx = Double.parseDouble(leftTextField.getText());
|
398 |
maxy = Double.parseDouble(topTextField.getText());
|
399 |
} catch (NumberFormatException nfe) { |
400 |
logger.info("Not valid value in working area: " + nfe.getMessage());
|
401 |
return null; |
402 |
} |
403 |
GeometryManager geoMan = GeometryLocator.getGeometryManager(); |
404 |
|
405 |
try {
|
406 |
return geoMan.createEnvelope(minx, miny, maxx, maxy,
|
407 |
SUBTYPES.GEOM2D); |
408 |
} catch (CreateEnvelopeException e) {
|
409 |
// FIXME Exception
|
410 |
throw new RuntimeException(e); |
411 |
} |
412 |
} |
413 |
|
414 |
public boolean combosHaveItems() { |
415 |
if (!super.combosHaveItems()) { |
416 |
return false; |
417 |
} |
418 |
|
419 |
if (getGeomComboBox().getItemCount() == 0) { |
420 |
return false; |
421 |
} |
422 |
|
423 |
return true; |
424 |
} |
425 |
|
426 |
public void repaint() { |
427 |
super.repaint();
|
428 |
getGeomComboBox().updateUI(); |
429 |
} |
430 |
|
431 |
public String getGeoFieldName() { |
432 |
if (getGeomComboBox().getSelectedItem() == null) { |
433 |
return null; |
434 |
} |
435 |
return getGeomComboBox().getSelectedItem().toString();
|
436 |
} |
437 |
public IProjection getProjection() {
|
438 |
return panelProj.getCurProj();
|
439 |
} |
440 |
|
441 |
} |