svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / jdbc / DefaultJDBCConnectionPanelView.java @ 43377
History | View | Annotate | Download (7.94 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.jdbc; |
---|---|
2 |
|
3 |
import com.jeta.open.i18n.I18NUtils; |
4 |
import com.jgoodies.forms.layout.CellConstraints; |
5 |
import com.jgoodies.forms.layout.FormLayout; |
6 |
import java.awt.BorderLayout; |
7 |
import java.awt.ComponentOrientation; |
8 |
import java.awt.Container; |
9 |
import java.awt.Dimension; |
10 |
import javax.swing.Box; |
11 |
import javax.swing.ImageIcon; |
12 |
import javax.swing.JButton; |
13 |
import javax.swing.JComboBox; |
14 |
import javax.swing.JFrame; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JPasswordField; |
18 |
import javax.swing.JTextField; |
19 |
|
20 |
|
21 |
public class DefaultJDBCConnectionPanelView extends JPanel |
22 |
{ |
23 |
JLabel lblConnectionName = new JLabel(); |
24 |
JLabel lblConnector = new JLabel(); |
25 |
JLabel lblServer = new JLabel(); |
26 |
JLabel lblPort = new JLabel(); |
27 |
JLabel lblDataBase = new JLabel(); |
28 |
JLabel lblUsername = new JLabel(); |
29 |
JLabel lblPassword = new JLabel(); |
30 |
JComboBox cboConnections = new JComboBox(); |
31 |
JComboBox cboConnectors = new JComboBox(); |
32 |
JTextField txtServer = new JTextField(); |
33 |
JTextField txtPort = new JTextField(); |
34 |
JTextField txtUsername = new JTextField(); |
35 |
JTextField txtDataBase = new JTextField(); |
36 |
JPasswordField txtPassword = new JPasswordField(); |
37 |
JLabel lblFile = new JLabel(); |
38 |
JLabel lblFoother = new JLabel(); |
39 |
JTextField txtFile = new JTextField(); |
40 |
JButton btnDataBaseBrowser = new JButton(); |
41 |
|
42 |
/**
|
43 |
* Default constructor
|
44 |
*/
|
45 |
public DefaultJDBCConnectionPanelView()
|
46 |
{ |
47 |
initializePanel(); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
52 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
53 |
* @param cols an array of column indices in the first row where fill components should be added.
|
54 |
* @param rows an array of row indices in the first column where fill components should be added.
|
55 |
*/
|
56 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
57 |
{ |
58 |
Dimension filler = new Dimension(10,10); |
59 |
|
60 |
boolean filled_cell_11 = false; |
61 |
CellConstraints cc = new CellConstraints();
|
62 |
if ( cols.length > 0 && rows.length > 0 ) |
63 |
{ |
64 |
if ( cols[0] == 1 && rows[0] == 1 ) |
65 |
{ |
66 |
/** add a rigid area */
|
67 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
68 |
filled_cell_11 = true;
|
69 |
} |
70 |
} |
71 |
|
72 |
for( int index = 0; index < cols.length; index++ ) |
73 |
{ |
74 |
if ( cols[index] == 1 && filled_cell_11 ) |
75 |
{ |
76 |
continue;
|
77 |
} |
78 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
79 |
} |
80 |
|
81 |
for( int index = 0; index < rows.length; index++ ) |
82 |
{ |
83 |
if ( rows[index] == 1 && filled_cell_11 ) |
84 |
{ |
85 |
continue;
|
86 |
} |
87 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
88 |
} |
89 |
|
90 |
} |
91 |
|
92 |
/**
|
93 |
* Helper method to load an image file from the CLASSPATH
|
94 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
95 |
* @return an ImageIcon instance with the specified image file
|
96 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
97 |
*/
|
98 |
public ImageIcon loadImage( String imageName ) |
99 |
{ |
100 |
try
|
101 |
{ |
102 |
ClassLoader classloader = getClass().getClassLoader();
|
103 |
java.net.URL url = classloader.getResource( imageName ); |
104 |
if ( url != null ) |
105 |
{ |
106 |
ImageIcon icon = new ImageIcon( url ); |
107 |
return icon;
|
108 |
} |
109 |
} |
110 |
catch( Exception e ) |
111 |
{ |
112 |
e.printStackTrace(); |
113 |
} |
114 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Method for recalculating the component orientation for
|
119 |
* right-to-left Locales.
|
120 |
* @param orientation the component orientation to be applied
|
121 |
*/
|
122 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
123 |
{ |
124 |
// Not yet implemented...
|
125 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
126 |
super.applyComponentOrientation(orientation);
|
127 |
} |
128 |
|
129 |
public JPanel createPanel() |
130 |
{ |
131 |
JPanel jpanel1 = new JPanel(); |
132 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
133 |
CellConstraints cc = new CellConstraints();
|
134 |
jpanel1.setLayout(formlayout1); |
135 |
|
136 |
lblConnectionName.setName("lblConnectionName");
|
137 |
lblConnectionName.setText("Nombre de la conexion");
|
138 |
jpanel1.add(lblConnectionName,cc.xy(2,2)); |
139 |
|
140 |
lblConnector.setName("lblConnector");
|
141 |
lblConnector.setText("Conector");
|
142 |
jpanel1.add(lblConnector,cc.xy(2,4)); |
143 |
|
144 |
lblServer.setName("lblServer");
|
145 |
lblServer.setText("Servidor");
|
146 |
jpanel1.add(lblServer,cc.xy(2,8)); |
147 |
|
148 |
lblPort.setName("lblPort");
|
149 |
lblPort.setText("Puerto");
|
150 |
jpanel1.add(lblPort,cc.xy(2,10)); |
151 |
|
152 |
lblDataBase.setName("lblDataBase");
|
153 |
lblDataBase.setText("Base de datos");
|
154 |
jpanel1.add(lblDataBase,cc.xy(2,12)); |
155 |
|
156 |
lblUsername.setName("lblUsername");
|
157 |
lblUsername.setText("Usuario");
|
158 |
jpanel1.add(lblUsername,cc.xy(2,14)); |
159 |
|
160 |
lblPassword.setName("lblPassword");
|
161 |
lblPassword.setText("Clave");
|
162 |
jpanel1.add(lblPassword,cc.xy(2,16)); |
163 |
|
164 |
cboConnections.setEditable(true);
|
165 |
cboConnections.setName("cboConnections");
|
166 |
cboConnections.setRequestFocusEnabled(false);
|
167 |
jpanel1.add(cboConnections,cc.xy(4,2)); |
168 |
|
169 |
cboConnectors.setName("cboConnectors");
|
170 |
jpanel1.add(cboConnectors,cc.xy(4,4)); |
171 |
|
172 |
txtServer.setName("txtServer");
|
173 |
jpanel1.add(txtServer,cc.xy(4,8)); |
174 |
|
175 |
txtPort.setName("txtPort");
|
176 |
jpanel1.add(txtPort,cc.xy(4,10)); |
177 |
|
178 |
txtUsername.setName("txtUsername");
|
179 |
jpanel1.add(txtUsername,cc.xy(4,14)); |
180 |
|
181 |
txtDataBase.setName("txtDataBase");
|
182 |
jpanel1.add(txtDataBase,cc.xy(4,12)); |
183 |
|
184 |
txtPassword.setName("txtPassword");
|
185 |
jpanel1.add(txtPassword,cc.xy(4,16)); |
186 |
|
187 |
lblFile.setName("lblFile");
|
188 |
lblFile.setText("Fichero");
|
189 |
jpanel1.add(lblFile,cc.xy(2,6)); |
190 |
|
191 |
jpanel1.add(createPanel1(),cc.xywh(2,18,3,1)); |
192 |
jpanel1.add(createPanel2(),cc.xy(4,6)); |
193 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19 }); |
194 |
return jpanel1;
|
195 |
} |
196 |
|
197 |
public JPanel createPanel1() |
198 |
{ |
199 |
JPanel jpanel1 = new JPanel(); |
200 |
FormLayout formlayout1 = new FormLayout("RIGHT:12DLU:GROW(1.0)","CENTER:DEFAULT:NONE"); |
201 |
CellConstraints cc = new CellConstraints();
|
202 |
jpanel1.setLayout(formlayout1); |
203 |
|
204 |
lblFoother.setName("lblFoother");
|
205 |
lblFoother.setText("<html> Tenga en cuenta que el nombre de usuario y la contraseƱa deben coincidir en mayusculas y minusculas con el registrado en la base de dato. <html>");
|
206 |
jpanel1.add(lblFoother,cc.xy(1,1)); |
207 |
|
208 |
addFillComponents(jpanel1,new int[0],new int[0]); |
209 |
return jpanel1;
|
210 |
} |
211 |
|
212 |
public JPanel createPanel2() |
213 |
{ |
214 |
JPanel jpanel1 = new JPanel(); |
215 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE"); |
216 |
CellConstraints cc = new CellConstraints();
|
217 |
jpanel1.setLayout(formlayout1); |
218 |
|
219 |
txtFile.setName("txtFile");
|
220 |
jpanel1.add(txtFile,cc.xy(1,1)); |
221 |
|
222 |
btnDataBaseBrowser.setActionCommand("...");
|
223 |
btnDataBaseBrowser.setName("btnDataBaseBrowser");
|
224 |
btnDataBaseBrowser.setText("...");
|
225 |
jpanel1.add(btnDataBaseBrowser,cc.xy(3,1)); |
226 |
|
227 |
addFillComponents(jpanel1,new int[]{ 2 },new int[0]); |
228 |
return jpanel1;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Initializer
|
233 |
*/
|
234 |
protected void initializePanel() |
235 |
{ |
236 |
setLayout(new BorderLayout()); |
237 |
add(createPanel(), BorderLayout.CENTER);
|
238 |
} |
239 |
|
240 |
|
241 |
} |