gvsig-raster / org.gvsig.raster.postgis / trunk / org.gvsig.raster.postgis / org.gvsig.raster.postgis.swing / org.gvsig.raster.postgis.swing.impl / src / main / java / org / gvsig / raster / postgis / swing / impl / addlayer / ConnectionChooserPanel.java @ 885
History | View | Annotate | Download (2.61 KB)
1 |
package org.gvsig.raster.postgis.swing.impl.addlayer; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
|
7 |
import javax.swing.ImageIcon; |
8 |
import javax.swing.JButton; |
9 |
import javax.swing.JComboBox; |
10 |
import javax.swing.JPanel; |
11 |
|
12 |
import org.gvsig.andami.PluginServices; |
13 |
import org.gvsig.i18n.Messages; |
14 |
|
15 |
public class ConnectionChooserPanel extends JPanel { |
16 |
private static final long serialVersionUID = 1L; |
17 |
|
18 |
private JButton jButton = null; |
19 |
private JComboBox combo = null; |
20 |
private boolean showBorder = true; |
21 |
private boolean isButtonVisible = true; |
22 |
|
23 |
public ConnectionChooserPanel(boolean showBorder) { |
24 |
this.showBorder = showBorder;
|
25 |
initialize(); |
26 |
} |
27 |
|
28 |
/**
|
29 |
* This method initializes this
|
30 |
*
|
31 |
*/
|
32 |
private void initialize() { |
33 |
this.setLayout(new GridBagLayout()); |
34 |
if(showBorder)
|
35 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, Messages.getText("select_db"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
36 |
|
37 |
GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
38 |
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
39 |
gridBagConstraints1.weightx = 1;
|
40 |
gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0); |
41 |
|
42 |
this.add(getComboBox(), gridBagConstraints1);
|
43 |
|
44 |
gridBagConstraints1.gridx = 1;
|
45 |
gridBagConstraints1.weightx = 0;
|
46 |
|
47 |
this.add(getJButton(), gridBagConstraints1);
|
48 |
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* This method initializes jButton
|
53 |
*
|
54 |
* @return javax.swing.JButton
|
55 |
*/
|
56 |
public JButton getJButton() { |
57 |
if (jButton == null) { |
58 |
ImageIcon icon = PluginServices.getIconTheme().get("icon-jdbc"); |
59 |
if(icon == null) |
60 |
icon = new ImageIcon(System.getProperty("user.dir") + "/src/main/resources/images/jdbc.png", ""); |
61 |
|
62 |
jButton = new JButton(icon); |
63 |
jButton.setPreferredSize(new Dimension(22, 22)); |
64 |
jButton.setVisible(isButtonVisible); |
65 |
getComboBox().setEnabled(isButtonVisible); |
66 |
} |
67 |
return jButton;
|
68 |
} |
69 |
|
70 |
/**
|
71 |
* This method initializes jTextField
|
72 |
*
|
73 |
* @return javax.swing.JTextField
|
74 |
*/
|
75 |
public JComboBox getComboBox() { |
76 |
if (combo == null) { |
77 |
combo = new JComboBox(); |
78 |
combo.setPreferredSize(new Dimension(0, 22)); |
79 |
} |
80 |
return combo;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Devuelve el file cuya ruta corresponde con el campo de texto.
|
85 |
* @return
|
86 |
*/
|
87 |
public String getSelectedDB() { |
88 |
return (String)getComboBox().getSelectedItem(); |
89 |
} |
90 |
|
91 |
public void setEnabled(boolean enabled) { |
92 |
getComboBox().setEnabled(enabled); |
93 |
getJButton().setEnabled(enabled); |
94 |
} |
95 |
} |