root / branches / v10 / extensions / extSDE / src / com / iver / cit / gvsig / sde / gui / sdewizard2 / UserTableSettingsPanel.java @ 11012
History | View | Annotate | Download (15.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package com.iver.cit.gvsig.sde.gui.sdewizard2; |
44 |
|
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.awt.event.KeyEvent; |
48 |
import java.awt.event.KeyListener; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.text.DecimalFormat; |
51 |
import java.text.DecimalFormatSymbols; |
52 |
|
53 |
import javax.swing.JCheckBox; |
54 |
import javax.swing.JComboBox; |
55 |
import javax.swing.JLabel; |
56 |
import javax.swing.JPanel; |
57 |
import javax.swing.JScrollPane; |
58 |
import javax.swing.JTextArea; |
59 |
import javax.swing.JTextField; |
60 |
|
61 |
import org.apache.log4j.Logger; |
62 |
import org.gvsig.gui.beans.swing.JButton; |
63 |
|
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.cit.gvsig.fmap.MapControl; |
66 |
|
67 |
|
68 |
/**
|
69 |
* Utility class that holds a single table settings controls.
|
70 |
*
|
71 |
* @author jldominguez
|
72 |
*
|
73 |
*/
|
74 |
public class UserTableSettingsPanel extends JPanel implements ActionListener, |
75 |
KeyListener {
|
76 |
private static Logger logger = Logger.getLogger(UserTableSettingsPanel.class.getName()); |
77 |
private FieldComboItem[] ids; |
78 |
private FieldComboItem[] geos; |
79 |
private String initLayerName = ""; |
80 |
private JComboBox idComboBox = null; |
81 |
private JComboBox geomComboBox = null; |
82 |
private JTextArea sqlTextArea = null; |
83 |
private JLabel idLabel = null; |
84 |
private JLabel geomLabel = null; |
85 |
private JLabel sqlLabel = null; |
86 |
private JLabel waLabel = null; |
87 |
private JLabel topLabel = null; |
88 |
private JTextField topTextField = null; |
89 |
private JTextField bottomTextField = null; |
90 |
private JTextField rightTextField = null; |
91 |
private JTextField leftTextField = null; |
92 |
private JLabel bottomLabel = null; |
93 |
private JLabel rightLabel = null; |
94 |
private JLabel leftLabel = null; |
95 |
private JButton getviewButton = null; |
96 |
private JCheckBox activateWACheckBox = null; |
97 |
private JCheckBox activateSQLCheckBox = null; |
98 |
private JLabel tableNamejLabel = null; |
99 |
private JTextField layerNameTextField = null; |
100 |
private JScrollPane sqlTextAreaScroll = null; |
101 |
private MapControl mControl = null; |
102 |
private WizardSDE parent = null; |
103 |
|
104 |
public UserTableSettingsPanel(FieldComboItem[] idComboItems, |
105 |
FieldComboItem[] geoComboItems, String initialLayerName, |
106 |
MapControl mapc, boolean empty, WizardSDE _p) {
|
107 |
parent = _p; |
108 |
|
109 |
mControl = mapc; |
110 |
initLayerName = initialLayerName; |
111 |
ids = idComboItems; |
112 |
geos = geoComboItems; |
113 |
initialize(empty); |
114 |
} |
115 |
|
116 |
public boolean hasValidValues() { |
117 |
if (!combosHaveItems()) {
|
118 |
return false; |
119 |
} |
120 |
|
121 |
if ((activateWACheckBox.isSelected()) && (getWorkingArea() == null)) { |
122 |
return false; |
123 |
} |
124 |
|
125 |
if ((activateSQLCheckBox.isSelected()) &&
|
126 |
(getSqlTextArea().getText().trim().length() == 0)) {
|
127 |
return false; |
128 |
} |
129 |
|
130 |
if (getLayerNameTextField().getText().trim().length() == 0) { |
131 |
return false; |
132 |
} |
133 |
|
134 |
return true; |
135 |
} |
136 |
|
137 |
private void initialize(boolean _empty) { |
138 |
tableNamejLabel = new JLabel(); |
139 |
tableNamejLabel.setBounds(new java.awt.Rectangle(15, 25, 221, 21)); |
140 |
tableNamejLabel.setText(PluginServices.getText(this, "layer_name")); |
141 |
leftLabel = new JLabel(); |
142 |
leftLabel.setBounds(new java.awt.Rectangle(375, 175, 111, 16)); |
143 |
leftLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
144 |
leftLabel.setText(PluginServices.getText(this, "xmin")); |
145 |
rightLabel = new JLabel(); |
146 |
rightLabel.setBounds(new java.awt.Rectangle(260, 175, 111, 16)); |
147 |
rightLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
148 |
rightLabel.setText(PluginServices.getText(this, "xmax")); |
149 |
bottomLabel = new JLabel(); |
150 |
bottomLabel.setBounds(new java.awt.Rectangle(130, 175, 111, 16)); |
151 |
bottomLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
152 |
bottomLabel.setText(PluginServices.getText(this, "ymin")); |
153 |
topLabel = new JLabel(); |
154 |
topLabel.setBounds(new java.awt.Rectangle(15, 175, 111, 16)); |
155 |
topLabel.setFont(new java.awt.Font("Dialog", java.awt.Font.BOLD, 10)); |
156 |
topLabel.setText(PluginServices.getText(this, "ymax")); |
157 |
waLabel = new JLabel(); |
158 |
waLabel.setBounds(new java.awt.Rectangle(40, 145, 131, 21)); |
159 |
waLabel.setText(PluginServices.getText(this, "working_area")); |
160 |
sqlLabel = new JLabel(); |
161 |
sqlLabel.setBounds(new java.awt.Rectangle(40, 90, 116, 21)); |
162 |
sqlLabel.setText(PluginServices.getText(this, "sql_restriction")); |
163 |
geomLabel = new JLabel(); |
164 |
geomLabel.setBounds(new java.awt.Rectangle(240, 55, 111, 21)); |
165 |
geomLabel.setText(PluginServices.getText(this, "geo_field")); |
166 |
idLabel = new JLabel(); |
167 |
idLabel.setBounds(new java.awt.Rectangle(15, 55, 86, 21)); |
168 |
idLabel.setText(PluginServices.getText(this, "id_field")); |
169 |
|
170 |
setLayout(null);
|
171 |
setBounds(new java.awt.Rectangle(5, 250, 501, 221)); |
172 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null,
|
173 |
PluginServices.getText(this, "specify_table_settings"), |
174 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
175 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
176 |
add(getIdComboBox(), null);
|
177 |
add(getGeomComboBox(), null);
|
178 |
add(getSqlTextAreaScroll(), null);
|
179 |
add(idLabel, null);
|
180 |
add(geomLabel, null);
|
181 |
add(sqlLabel, null);
|
182 |
add(waLabel, null);
|
183 |
add(topLabel, null);
|
184 |
add(getTopTextField(), null);
|
185 |
add(getBottomTextField(), null);
|
186 |
add(getRightTextField(), null);
|
187 |
add(getLeftTextField(), null);
|
188 |
add(bottomLabel, null);
|
189 |
add(rightLabel, null);
|
190 |
add(leftLabel, null);
|
191 |
add(getGetviewButton(), null);
|
192 |
add(getActivateWACheckBox(), null);
|
193 |
add(getActivateSQLCheckBox(), null);
|
194 |
add(getLayerNameTextField(), null);
|
195 |
add(tableNamejLabel, null);
|
196 |
|
197 |
loadValues(_empty); |
198 |
} |
199 |
|
200 |
public void enableControls(boolean enable) { |
201 |
getIdComboBox().setEnabled(enable); |
202 |
getGeomComboBox().setEnabled(enable); |
203 |
getLayerNameTextField().setEnabled(enable); |
204 |
getActivateSQLCheckBox().setEnabled(enable); |
205 |
getSqlTextArea().setEnabled(enable); |
206 |
|
207 |
getActivateWACheckBox().setEnabled(enable); |
208 |
|
209 |
boolean there_is_view = ((mControl != null) && |
210 |
(mControl.getViewPort().getAdjustedExtent() != null));
|
211 |
|
212 |
getGetviewButton().setEnabled(enable && there_is_view); |
213 |
getTopTextField().setEnabled(enable); |
214 |
getBottomTextField().setEnabled(enable); |
215 |
getRightTextField().setEnabled(enable); |
216 |
getLeftTextField().setEnabled(enable); |
217 |
} |
218 |
|
219 |
public void loadValues() { |
220 |
loadValues(false);
|
221 |
} |
222 |
|
223 |
private void loadValues(boolean is_empty) { |
224 |
if (is_empty) {
|
225 |
enableControls(false);
|
226 |
getLayerNameTextField().setText("");
|
227 |
getActivateSQLCheckBox().setSelected(false);
|
228 |
getActivateWACheckBox().setSelected(false);
|
229 |
} |
230 |
else {
|
231 |
getIdComboBox().removeAllItems(); |
232 |
|
233 |
for (int i = 0; i < ids.length; i++) { |
234 |
getIdComboBox().addItem(ids[i]); |
235 |
} |
236 |
|
237 |
getGeomComboBox().removeAllItems(); |
238 |
|
239 |
for (int i = 0; i < geos.length; i++) { |
240 |
getGeomComboBox().addItem(geos[i]); |
241 |
} |
242 |
|
243 |
getLayerNameTextField().setText(initLayerName); |
244 |
} |
245 |
} |
246 |
|
247 |
private JComboBox getIdComboBox() { |
248 |
if (idComboBox == null) { |
249 |
idComboBox = new JComboBox(); |
250 |
|
251 |
idComboBox.setBounds(new java.awt.Rectangle(105, 55, 126, 21)); |
252 |
} |
253 |
|
254 |
return idComboBox;
|
255 |
} |
256 |
|
257 |
private JComboBox getGeomComboBox() { |
258 |
if (geomComboBox == null) { |
259 |
geomComboBox = new JComboBox(); |
260 |
geomComboBox.setBounds(new java.awt.Rectangle(355, 55, 131, 21)); |
261 |
} |
262 |
|
263 |
return geomComboBox;
|
264 |
} |
265 |
|
266 |
private JTextField getTopTextField() { |
267 |
if (topTextField == null) { |
268 |
topTextField = new JTextField(); |
269 |
topTextField.addKeyListener(this);
|
270 |
topTextField.setBounds(new java.awt.Rectangle(15, 190, 111, 21)); |
271 |
} |
272 |
|
273 |
return topTextField;
|
274 |
} |
275 |
|
276 |
private JTextField getBottomTextField() { |
277 |
if (bottomTextField == null) { |
278 |
bottomTextField = new JTextField(); |
279 |
bottomTextField.addKeyListener(this);
|
280 |
bottomTextField.setBounds(new java.awt.Rectangle(130, 190, 111, 21)); |
281 |
} |
282 |
|
283 |
return bottomTextField;
|
284 |
} |
285 |
|
286 |
private JTextField getRightTextField() { |
287 |
if (rightTextField == null) { |
288 |
rightTextField = new JTextField(); |
289 |
rightTextField.addKeyListener(this);
|
290 |
rightTextField.setBounds(new java.awt.Rectangle(260, 190, 111, 21)); |
291 |
} |
292 |
|
293 |
return rightTextField;
|
294 |
} |
295 |
|
296 |
private JTextField getLeftTextField() { |
297 |
if (leftTextField == null) { |
298 |
leftTextField = new JTextField(); |
299 |
leftTextField.addKeyListener(this);
|
300 |
leftTextField.setBounds(new java.awt.Rectangle(375, 190, 111, 21)); |
301 |
} |
302 |
|
303 |
return leftTextField;
|
304 |
} |
305 |
|
306 |
private JButton getGetviewButton() { |
307 |
if (getviewButton == null) { |
308 |
getviewButton = new JButton(); |
309 |
getviewButton.addActionListener(this);
|
310 |
getviewButton.setBounds(new java.awt.Rectangle(195, 145, 111, 26)); |
311 |
getviewButton.setForeground(java.awt.Color.black); |
312 |
getviewButton.setText(PluginServices.getText(this, "get_view")); |
313 |
} |
314 |
|
315 |
return getviewButton;
|
316 |
} |
317 |
|
318 |
private JCheckBox getActivateWACheckBox() { |
319 |
if (activateWACheckBox == null) { |
320 |
activateWACheckBox = new JCheckBox(); |
321 |
activateWACheckBox.addActionListener(this);
|
322 |
activateWACheckBox.setBounds(new java.awt.Rectangle(15, 145, 21, 21)); |
323 |
} |
324 |
|
325 |
return activateWACheckBox;
|
326 |
} |
327 |
|
328 |
private JCheckBox getActivateSQLCheckBox() { |
329 |
if (activateSQLCheckBox == null) { |
330 |
activateSQLCheckBox = new JCheckBox(); |
331 |
activateSQLCheckBox.addActionListener(this);
|
332 |
activateSQLCheckBox.setBounds(new java.awt.Rectangle(15, 90, 21, 21)); |
333 |
} |
334 |
|
335 |
return activateSQLCheckBox;
|
336 |
} |
337 |
|
338 |
private JTextField getLayerNameTextField() { |
339 |
if (layerNameTextField == null) { |
340 |
layerNameTextField = new JTextField(); |
341 |
layerNameTextField.setBounds(new java.awt.Rectangle(240, 25, 246, 21)); |
342 |
layerNameTextField.addKeyListener(this);
|
343 |
} |
344 |
|
345 |
return layerNameTextField;
|
346 |
} |
347 |
|
348 |
private JTextArea getSqlTextArea() { |
349 |
if (sqlTextArea == null) { |
350 |
sqlTextArea = new JTextArea(); |
351 |
sqlTextArea.setLineWrap(true);
|
352 |
sqlTextArea.setWrapStyleWord(true);
|
353 |
sqlTextArea.addKeyListener(this);
|
354 |
|
355 |
// sqlTextArea.setBounds(new java.awt.Rectangle(160,90,326,41));
|
356 |
} |
357 |
|
358 |
return sqlTextArea;
|
359 |
} |
360 |
|
361 |
private JScrollPane getSqlTextAreaScroll() { |
362 |
if (sqlTextAreaScroll == null) { |
363 |
sqlTextAreaScroll = new JScrollPane(); |
364 |
sqlTextAreaScroll.setBounds(new java.awt.Rectangle(160, 90, 326, 41)); |
365 |
sqlTextAreaScroll.setViewportView(getSqlTextArea()); |
366 |
sqlTextAreaScroll.updateUI(); |
367 |
} |
368 |
|
369 |
return sqlTextAreaScroll;
|
370 |
} |
371 |
|
372 |
public void actionPerformed(ActionEvent e) { |
373 |
Object src = e.getSource();
|
374 |
|
375 |
if (src == getviewButton) {
|
376 |
getViewIntoFourBounds(); |
377 |
parent.checkFinishable(); |
378 |
} |
379 |
|
380 |
if (src == activateSQLCheckBox) {
|
381 |
enableSQLSettings(activateSQLCheckBox.isSelected()); |
382 |
parent.checkFinishable(); |
383 |
} |
384 |
|
385 |
if (src == activateWACheckBox) {
|
386 |
enableWASettings(activateWACheckBox.isSelected()); |
387 |
parent.checkFinishable(); |
388 |
} |
389 |
} |
390 |
|
391 |
private void enableWASettings(boolean b) { |
392 |
getviewButton.setEnabled(b && |
393 |
(mControl.getViewPort().getAdjustedExtent() != null));
|
394 |
rightTextField.setEnabled(b); |
395 |
leftTextField.setEnabled(b); |
396 |
topTextField.setEnabled(b); |
397 |
bottomTextField.setEnabled(b); |
398 |
} |
399 |
|
400 |
private void enableSQLSettings(boolean b) { |
401 |
sqlTextArea.setEnabled(b); |
402 |
} |
403 |
|
404 |
private void getViewIntoFourBounds() { |
405 |
Rectangle2D rect = mControl.getViewPort().getAdjustedExtent();
|
406 |
topTextField.setText(getFormattedDouble(rect.getMaxY())); |
407 |
bottomTextField.setText(getFormattedDouble(rect.getMinY())); |
408 |
rightTextField.setText(getFormattedDouble(rect.getMaxX())); |
409 |
leftTextField.setText(getFormattedDouble(rect.getMinX())); |
410 |
} |
411 |
|
412 |
private String getFormattedDouble(double d) { |
413 |
DecimalFormat df = new DecimalFormat("#.###"); |
414 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
415 |
dfs.setDecimalSeparator('.');
|
416 |
df.setDecimalFormatSymbols(dfs); |
417 |
return df.format(d);
|
418 |
} |
419 |
|
420 |
public void keyPressed(KeyEvent e) { |
421 |
} |
422 |
|
423 |
public void keyReleased(KeyEvent e) { |
424 |
parent.checkFinishable(); |
425 |
} |
426 |
|
427 |
public void keyTyped(KeyEvent e) { |
428 |
} |
429 |
|
430 |
public Rectangle2D getWorkingArea() { |
431 |
if (!activateWACheckBox.isSelected()) {
|
432 |
return null; |
433 |
} |
434 |
|
435 |
double maxx;
|
436 |
double maxy;
|
437 |
double minx;
|
438 |
double miny;
|
439 |
|
440 |
try {
|
441 |
maxx = Double.parseDouble(rightTextField.getText());
|
442 |
miny = Double.parseDouble(bottomTextField.getText());
|
443 |
minx = Double.parseDouble(leftTextField.getText());
|
444 |
maxy = Double.parseDouble(topTextField.getText());
|
445 |
} |
446 |
catch (NumberFormatException nfe) { |
447 |
logger.error("Not valid value: " + nfe.getMessage());
|
448 |
|
449 |
return null; |
450 |
} |
451 |
|
452 |
return new Rectangle2D.Double(minx, miny, maxx - minx, maxy - miny); |
453 |
} |
454 |
|
455 |
public String getUserLayerName() { |
456 |
return getLayerNameTextField().getText();
|
457 |
} |
458 |
|
459 |
public boolean combosHaveItems() { |
460 |
if (getIdComboBox().getItemCount() == 0) { |
461 |
return false; |
462 |
} |
463 |
|
464 |
if (getGeomComboBox().getItemCount() == 0) { |
465 |
return false; |
466 |
} |
467 |
|
468 |
return true; |
469 |
} |
470 |
|
471 |
public void repaint() { |
472 |
super.repaint();
|
473 |
getIdComboBox().updateUI(); |
474 |
getGeomComboBox().updateUI(); |
475 |
} |
476 |
|
477 |
public String getIdFieldName() { |
478 |
return getIdComboBox().getSelectedItem().toString();
|
479 |
} |
480 |
|
481 |
public String getGeoFieldName() { |
482 |
return getGeomComboBox().getSelectedItem().toString();
|
483 |
} |
484 |
|
485 |
public String getWhereClause() { |
486 |
return getSqlTextArea().getText();
|
487 |
} |
488 |
|
489 |
public boolean isSqlActive() { |
490 |
return getActivateSQLCheckBox().isSelected();
|
491 |
} |
492 |
} |