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