svn-gvsig-desktop / trunk / extensions / extJDBC / src / com / iver / cit / gvsig / jdbc_spatial / gui / jdbcwizard / DBLayerDefinitionPanel.java @ 6877
History | View | Annotate | Download (14.9 KB)
1 |
package com.iver.cit.gvsig.jdbc_spatial.gui.jdbcwizard; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.event.ActionEvent; |
5 |
import java.awt.event.ActionListener; |
6 |
import java.awt.geom.Rectangle2D; |
7 |
|
8 |
import javax.swing.BorderFactory; |
9 |
import javax.swing.ButtonGroup; |
10 |
import javax.swing.DefaultListModel; |
11 |
import javax.swing.JCheckBox; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JList; |
14 |
import javax.swing.JOptionPane; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JRadioButton; |
17 |
import javax.swing.JScrollPane; |
18 |
import javax.swing.JTextField; |
19 |
|
20 |
import org.gvsig.gui.beans.swing.JButton; |
21 |
|
22 |
import com.iver.andami.PluginServices; |
23 |
import com.iver.andami.ui.mdiManager.IWindow; |
24 |
import com.iver.utiles.swing.wizard.Step; |
25 |
import com.iver.utiles.swing.wizard.WizardControl; |
26 |
import javax.swing.JTextArea; |
27 |
import javax.swing.border.Border; |
28 |
import javax.swing.JTextPane; |
29 |
import javax.swing.JEditorPane; |
30 |
/**
|
31 |
* DOCUMENT ME!
|
32 |
*
|
33 |
* @author Fernando Gonz?lez Cort?s
|
34 |
*/
|
35 |
public class DBLayerDefinitionPanel extends JPanel implements Step { |
36 |
private JList lstTables = null; |
37 |
private JLabel jLabel = null; |
38 |
private JPanel pnlExtent = null; |
39 |
private JLabel jLabel1 = null; |
40 |
private JTextField txtMinX = null; |
41 |
private JLabel jLabel2 = null; |
42 |
private JTextField txtMaxX = null; |
43 |
private JLabel jLabel3 = null; |
44 |
private JTextField txtMinY = null; |
45 |
private JLabel jLabel4 = null; |
46 |
private JTextField txtMaxY = null; |
47 |
private DefaultListModel lstTablesModel = new DefaultListModel(); |
48 |
private JCheckBox radWorkingArea = null; |
49 |
private boolean advanced = false; |
50 |
private JScrollPane jScrollPane = null; |
51 |
private JPanel jPanel = null; |
52 |
private JTextField txtLayerName = null; |
53 |
private JPanel jPanel1 = null; |
54 |
private JLabel jLabel5 = null; |
55 |
|
56 |
private JButton jButton = null; |
57 |
private JLabel jLabelWhereClause = null; |
58 |
private JTextArea jTextAreaWhereClause = null; |
59 |
/**
|
60 |
* This is the default constructor
|
61 |
*/
|
62 |
public DBLayerDefinitionPanel() {
|
63 |
super();
|
64 |
initialize(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* This method initializes this
|
69 |
*/
|
70 |
private void initialize() { |
71 |
jLabel = new JLabel(); |
72 |
this.setLayout(null); |
73 |
this.setSize(509, 473); |
74 |
this.setPreferredSize(new java.awt.Dimension(1260, 180)); |
75 |
jLabel.setText(PluginServices.getText(this, "seleccione_tabla") + ":"); |
76 |
//jLabel.setPreferredSize(new java.awt.Dimension(330, 15));
|
77 |
jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
78 |
jLabel.setBounds(20, 8, 460, 15); |
79 |
jLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); |
80 |
this.add(getJPanel1(), null); |
81 |
this.add(getJButton(), null); |
82 |
this.add(getPnlExtent(), null); |
83 |
this.add(getJPanel(), null); |
84 |
this.add(getJScrollPane(), null); |
85 |
this.add(jLabel, null); |
86 |
// ButtonGroup bt = new ButtonGroup();
|
87 |
// bt.add(getRadFullTable());
|
88 |
// bt.add(getRadWorkingArea());
|
89 |
enableExtent(false);
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* This method initializes lstTables
|
94 |
*
|
95 |
* @return javax.swing.JList
|
96 |
*/
|
97 |
private JList getLstTables() { |
98 |
if (lstTables == null) { |
99 |
lstTables = new JList(); |
100 |
lstTables.setModel(lstTablesModel); |
101 |
lstTables.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
102 |
lstTables.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
103 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
104 |
String aux = (String) lstTables.getSelectedValue(); |
105 |
getTxtLayerName().setText(aux); |
106 |
} |
107 |
}); |
108 |
} |
109 |
|
110 |
return lstTables;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* This method initializes pnlExtent
|
115 |
*
|
116 |
* @return javax.swing.JPanel
|
117 |
*/
|
118 |
private JPanel getPnlExtent() { |
119 |
if (pnlExtent == null) { |
120 |
jLabel4 = new JLabel(); |
121 |
jLabel3 = new JLabel(); |
122 |
jLabel2 = new JLabel(); |
123 |
jLabel1 = new JLabel(); |
124 |
pnlExtent = new JPanel(); |
125 |
pnlExtent.setLayout(null);
|
126 |
pnlExtent.setPreferredSize(new java.awt.Dimension(400,60)); |
127 |
jLabel1.setText(PluginServices.getText(this, "minx") + ":"); |
128 |
jLabel1.setBounds(9, 25, 50, 15); |
129 |
jLabel2.setText(PluginServices.getText(this, "maxx") + ":"); |
130 |
jLabel2.setBounds(9, 80, 50, 15); |
131 |
jLabel3.setText(PluginServices.getText(this, "miny") + ":"); |
132 |
jLabel3.setBounds(9, 48, 50, 15); |
133 |
jLabel4.setText(PluginServices.getText(this, "maxy") + ":"); |
134 |
jLabel4.setBounds(9, 103, 50, 15); |
135 |
pnlExtent.setBounds(20, 319, 212, 131); |
136 |
String strWorkingArea = PluginServices.getText(this,"area_trabajo"); |
137 |
pnlExtent.setBorder(javax.swing.BorderFactory.createTitledBorder(null, strWorkingArea, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
138 |
pnlExtent.add(getTxtMaxY(), null);
|
139 |
pnlExtent.add(jLabel4, null);
|
140 |
pnlExtent.add(getTxtMinY(), null);
|
141 |
pnlExtent.add(jLabel3, null);
|
142 |
pnlExtent.add(getTxtMaxX(), null);
|
143 |
pnlExtent.add(jLabel2, null);
|
144 |
pnlExtent.add(getTxtMinX(), null);
|
145 |
pnlExtent.add(jLabel1, null);
|
146 |
} |
147 |
|
148 |
return pnlExtent;
|
149 |
} |
150 |
|
151 |
/**
|
152 |
* This method initializes txtMinX
|
153 |
*
|
154 |
* @return javax.swing.JTextField
|
155 |
*/
|
156 |
private JTextField getTxtMinX() { |
157 |
if (txtMinX == null) { |
158 |
txtMinX = new JTextField(); |
159 |
txtMinX.setPreferredSize(new java.awt.Dimension(100, 19)); |
160 |
txtMinX.setBounds(65, 21, 118, 19); |
161 |
} |
162 |
|
163 |
return txtMinX;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* This method initializes txtMaxX
|
168 |
*
|
169 |
* @return javax.swing.JTextField
|
170 |
*/
|
171 |
private JTextField getTxtMaxX() { |
172 |
if (txtMaxX == null) { |
173 |
txtMaxX = new JTextField(); |
174 |
txtMaxX.setPreferredSize(new java.awt.Dimension(100, 19)); |
175 |
txtMaxX.setBounds(65, 76, 118, 19); |
176 |
} |
177 |
|
178 |
return txtMaxX;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* This method initializes txtMinY
|
183 |
*
|
184 |
* @return javax.swing.JTextField
|
185 |
*/
|
186 |
private JTextField getTxtMinY() { |
187 |
if (txtMinY == null) { |
188 |
txtMinY = new JTextField(); |
189 |
txtMinY.setPreferredSize(new java.awt.Dimension(100, 19)); |
190 |
txtMinY.setBounds(65, 44, 118, 19); |
191 |
} |
192 |
|
193 |
return txtMinY;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* This method initializes txtMaxY
|
198 |
*
|
199 |
* @return javax.swing.JTextField
|
200 |
*/
|
201 |
private JTextField getTxtMaxY() { |
202 |
if (txtMaxY == null) { |
203 |
txtMaxY = new JTextField(); |
204 |
txtMaxY.setPreferredSize(new java.awt.Dimension(100, 19)); |
205 |
txtMaxY.setBounds(65, 99, 118, 19); |
206 |
} |
207 |
|
208 |
return txtMaxY;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* DOCUMENT ME!
|
213 |
*
|
214 |
* @param tables DOCUMENT ME!
|
215 |
*/
|
216 |
public void setTables(String[] tables) { |
217 |
lstTablesModel = new DefaultListModel(); |
218 |
|
219 |
for (int i = 0; i < tables.length; i++) { |
220 |
lstTablesModel.addElement(tables[i]); |
221 |
} |
222 |
|
223 |
getLstTables().setModel(lstTablesModel); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* DOCUMENT ME!
|
228 |
*
|
229 |
* @param rect DOCUMENT ME!
|
230 |
*/
|
231 |
public void setExtent(Rectangle2D rect) { |
232 |
getTxtMinX().setText(String.valueOf(rect.getMinX()));
|
233 |
getTxtMinY().setText(String.valueOf(rect.getMinY()));
|
234 |
getTxtMaxX().setText(String.valueOf(rect.getMaxX()));
|
235 |
getTxtMaxY().setText(String.valueOf(rect.getMaxY()));
|
236 |
} |
237 |
|
238 |
/**
|
239 |
* DOCUMENT ME!
|
240 |
*
|
241 |
* @return DOCUMENT ME!
|
242 |
*/
|
243 |
public Rectangle2D getExtent() { |
244 |
if (!getRadWorkingArea().isSelected()) {
|
245 |
return null; |
246 |
} else {
|
247 |
return new Rectangle2D.Double(Double.parseDouble( |
248 |
getTxtMinX().getText()), |
249 |
Double.parseDouble(getTxtMinY().getText()),
|
250 |
Double.parseDouble(getTxtMaxX().getText()) -
|
251 |
Double.parseDouble(getTxtMinX().getText()),
|
252 |
Double.parseDouble(getTxtMaxY().getText()) -
|
253 |
Double.parseDouble(getTxtMinY().getText()));
|
254 |
} |
255 |
} |
256 |
|
257 |
/**
|
258 |
* DOCUMENT ME!
|
259 |
*
|
260 |
* @return DOCUMENT ME!
|
261 |
*/
|
262 |
public boolean done() { |
263 |
boolean done = (getTable() != null) && (!getLayerName().trim().equals("")); |
264 |
|
265 |
if (getRadWorkingArea().isSelected()) {
|
266 |
done = done && (getTxtMaxX().getText().length() > 0) &&
|
267 |
(getTxtMaxY().getText().length() > 0) &&
|
268 |
(getTxtMinX().getText().length() > 0) &&
|
269 |
(getTxtMinY().getText().length() > 0);
|
270 |
} |
271 |
|
272 |
return done;
|
273 |
} |
274 |
|
275 |
/**
|
276 |
* DOCUMENT ME!
|
277 |
*
|
278 |
* @return DOCUMENT ME!
|
279 |
*/
|
280 |
public String getTable() { |
281 |
return (String) getLstTables().getSelectedValue(); |
282 |
} |
283 |
|
284 |
/**
|
285 |
* DOCUMENT ME!
|
286 |
*
|
287 |
* @return DOCUMENT ME!
|
288 |
*/
|
289 |
public String getLayerName() { |
290 |
return (String) getTxtLayerName().getText(); |
291 |
} |
292 |
|
293 |
public String getWhereClause(){ |
294 |
String aux = getJTextAreaWhereClause().getText();
|
295 |
// Si est? vac?a, devolvemos vac?o.
|
296 |
if (aux.compareTo("") == 0) return ""; |
297 |
|
298 |
if (aux.toUpperCase().indexOf("WHERE") == -1) |
299 |
{ |
300 |
aux = "WHERE " + aux;
|
301 |
} |
302 |
return aux;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
* DOCUMENT ME!
|
307 |
*
|
308 |
* @param enable DOCUMENT ME!
|
309 |
*/
|
310 |
private void enableExtent(boolean enable) { |
311 |
for (int i = 0; i < pnlExtent.getComponentCount(); i++) { |
312 |
pnlExtent.getComponent(i).setEnabled(enable); |
313 |
} |
314 |
getJButton().setEnabled(enable); |
315 |
} |
316 |
|
317 |
/**
|
318 |
* This method initializes radWorkingArea
|
319 |
*
|
320 |
* @return javax.swing.JRadioButton
|
321 |
*/
|
322 |
private JCheckBox getRadWorkingArea() { |
323 |
if (radWorkingArea == null) { |
324 |
radWorkingArea = new JCheckBox(); |
325 |
radWorkingArea.setText(PluginServices.getText(this, "area_trabajo")+":"); |
326 |
radWorkingArea.setBounds(new java.awt.Rectangle(5,0,202,23)); |
327 |
radWorkingArea.setPreferredSize(new java.awt.Dimension(189,23)); |
328 |
radWorkingArea.addActionListener(new ActionListener() { |
329 |
public void actionPerformed(ActionEvent e) { |
330 |
enableExtent(radWorkingArea.isSelected()); |
331 |
} |
332 |
}); |
333 |
} |
334 |
|
335 |
return radWorkingArea;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* This method initializes jScrollPane
|
340 |
*
|
341 |
* @return javax.swing.JScrollPane
|
342 |
*/
|
343 |
private JScrollPane getJScrollPane() { |
344 |
if (jScrollPane == null) { |
345 |
jScrollPane = new JScrollPane(); |
346 |
jScrollPane.setBounds(20, 25, 460, 147); |
347 |
jScrollPane.setViewportView(getLstTables()); |
348 |
//jScrollPane.setPreferredSize(new java.awt.Dimension(270, 110));
|
349 |
} |
350 |
|
351 |
return jScrollPane;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* @see com.iver.utiles.swing.wizard.Step#init(com.iver.utiles.swing.wizard.WizardControl)
|
356 |
*/
|
357 |
public void init(WizardControl w) { |
358 |
} |
359 |
|
360 |
/**
|
361 |
* This method initializes jPanel
|
362 |
*
|
363 |
* @return javax.swing.JPanel
|
364 |
*/
|
365 |
private JPanel getJPanel() { |
366 |
if (jPanel == null) { |
367 |
jPanel = new JPanel(); |
368 |
jPanel.setLayout(null);
|
369 |
jPanel.setBounds(20, 268, 212, 25); |
370 |
jPanel.add(getRadWorkingArea(), null);
|
371 |
|
372 |
} |
373 |
|
374 |
return jPanel;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* This method initializes jTextField
|
379 |
*
|
380 |
* @return javax.swing.JTextField
|
381 |
*/
|
382 |
private JTextField getTxtLayerName() { |
383 |
if (txtLayerName == null) { |
384 |
txtLayerName = new JTextField(); |
385 |
//txtLayerName.setPreferredSize(new java.awt.Dimension(100, 19));
|
386 |
txtLayerName.setBounds(230, 5, 230, 19); |
387 |
} |
388 |
|
389 |
return txtLayerName;
|
390 |
} |
391 |
|
392 |
/**
|
393 |
* This method initializes jPanel1
|
394 |
*
|
395 |
* @return javax.swing.JPanel
|
396 |
*/
|
397 |
private JPanel getJPanel1() { |
398 |
if (jPanel1 == null) { |
399 |
jLabelWhereClause = new JLabel(); |
400 |
jLabelWhereClause.setBounds(new java.awt.Rectangle(0,32,220,17)); |
401 |
jLabelWhereClause.setText("Where Clause:");
|
402 |
jLabel5 = new JLabel(); |
403 |
jPanel1 = new JPanel(); |
404 |
jLabel5.setText(PluginServices.getText(this, "nombre_capa")+":"); |
405 |
jLabel5.setBounds(0, 5, 220, 15); |
406 |
jPanel1.setLayout(null);
|
407 |
//jPanel1.setPreferredSize(new java.awt.Dimension(383,29));
|
408 |
jPanel1.setBounds(20, 175, 460, 92); |
409 |
jPanel1.add(getTxtLayerName(), null);
|
410 |
jPanel1.add(jLabel5, null);
|
411 |
jPanel1.add(jLabelWhereClause, null);
|
412 |
jPanel1.add(getJTextAreaWhereClause(), null);
|
413 |
} |
414 |
|
415 |
return jPanel1;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* @return
|
420 |
*/
|
421 |
public Rectangle2D getWorkingArea() { |
422 |
if (getRadWorkingArea().isSelected()) {
|
423 |
return new Rectangle2D.Double( |
424 |
Double.parseDouble(getTxtMinX().getText()),
|
425 |
Double.parseDouble(getTxtMinY().getText()),
|
426 |
Double.parseDouble(getTxtMaxX().getText()) - Double.parseDouble(getTxtMinX().getText()), |
427 |
Double.parseDouble(getTxtMaxY().getText()) - Double.parseDouble(getTxtMinY().getText()) |
428 |
); |
429 |
}else{
|
430 |
return null; |
431 |
} |
432 |
} |
433 |
/**
|
434 |
* This method initializes jButton
|
435 |
*
|
436 |
* @return javax.swing.JButton
|
437 |
*/
|
438 |
private JButton getJButton() { |
439 |
if (jButton == null) { |
440 |
jButton = new JButton(); |
441 |
jButton.setText(PluginServices.getText(this, "importar_extent")+":"); |
442 |
jButton.setBounds(20, 295, 212, 23); |
443 |
jButton.addActionListener(new ActionListener() { |
444 |
public void actionPerformed(ActionEvent e) { |
445 |
IWindow v = PluginServices.getMDIManager().getActiveView(); |
446 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) v; |
447 |
Rectangle2D r = vista.getModel().getMapContext().getViewPort().getAdjustedExtent();
|
448 |
if (r == null) |
449 |
{ |
450 |
JOptionPane.showMessageDialog(null,PluginServices.getText(this, "aviso_sin_extent_de_referencia")); |
451 |
return;
|
452 |
} |
453 |
|
454 |
getTxtMinX().setText(Double.toString(r.getMinX()));
|
455 |
getTxtMinY().setText(Double.toString(r.getMinY()));
|
456 |
getTxtMaxX().setText(Double.toString(r.getMaxX()));
|
457 |
getTxtMaxY().setText(Double.toString(r.getMaxY()));
|
458 |
} |
459 |
}); |
460 |
} |
461 |
return jButton;
|
462 |
} |
463 |
|
464 |
/**
|
465 |
* This method initializes jTextAreaWhereClause
|
466 |
*
|
467 |
* @return javax.swing.JTextArea
|
468 |
*/
|
469 |
private JTextArea getJTextAreaWhereClause() { |
470 |
if (jTextAreaWhereClause == null) { |
471 |
jTextAreaWhereClause = new JTextArea(); |
472 |
// jTextAreaWhereClause.setBorder(BorderFactory.createLineBorder(Color.BLACK));
|
473 |
jTextAreaWhereClause.setSize(new java.awt.Dimension(460,34)); |
474 |
jTextAreaWhereClause.setWrapStyleWord(true);
|
475 |
jTextAreaWhereClause.setRows(2);
|
476 |
jTextAreaWhereClause.setLocation(new java.awt.Point(0,54)); |
477 |
} |
478 |
return jTextAreaWhereClause;
|
479 |
} |
480 |
} // @jve:decl-index=0:visual-constraint="10,10"
|