Statistics
| Revision:

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 @ 43114

History | View | Annotate | Download (7.58 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.JTextField;
18

    
19

    
20
public class DefaultJDBCConnectionPanelView extends JPanel
21
{
22
   JLabel lblConnectionName = new JLabel();
23
   JLabel lblConnector = new JLabel();
24
   JLabel lblServer = new JLabel();
25
   JLabel lblPort = new JLabel();
26
   JLabel lblDataBase = new JLabel();
27
   JLabel lblUsername = new JLabel();
28
   JLabel lblPassword = new JLabel();
29
   JComboBox cboConnections = new JComboBox();
30
   JComboBox cboConnectors = new JComboBox();
31
   JTextField txtServer = new JTextField();
32
   JTextField txtPort = new JTextField();
33
   JTextField txtUsername = new JTextField();
34
   JTextField txtPassword = new JTextField();
35
   JLabel lblFoother = new JLabel();
36
   JTextField txtDataBase = new JTextField();
37
   JButton btnDataBaseBrowser = new JButton();
38

    
39
   /**
40
    * Default constructor
41
    */
42
   public DefaultJDBCConnectionPanelView()
43
   {
44
      initializePanel();
45
   }
46

    
47
   /**
48
    * Adds fill components to empty cells in the first row and first column of the grid.
49
    * This ensures that the grid spacing will be the same as shown in the designer.
50
    * @param cols an array of column indices in the first row where fill components should be added.
51
    * @param rows an array of row indices in the first column where fill components should be added.
52
    */
53
   void addFillComponents( Container panel, int[] cols, int[] rows )
54
   {
55
      Dimension filler = new Dimension(10,10);
56

    
57
      boolean filled_cell_11 = false;
58
      CellConstraints cc = new CellConstraints();
59
      if ( cols.length > 0 && rows.length > 0 )
60
      {
61
         if ( cols[0] == 1 && rows[0] == 1 )
62
         {
63
            /** add a rigid area  */
64
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
65
            filled_cell_11 = true;
66
         }
67
      }
68

    
69
      for( int index = 0; index < cols.length; index++ )
70
      {
71
         if ( cols[index] == 1 && filled_cell_11 )
72
         {
73
            continue;
74
         }
75
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
76
      }
77

    
78
      for( int index = 0; index < rows.length; index++ )
79
      {
80
         if ( rows[index] == 1 && filled_cell_11 )
81
         {
82
            continue;
83
         }
84
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
85
      }
86

    
87
   }
88

    
89
   /**
90
    * Helper method to load an image file from the CLASSPATH
91
    * @param imageName the package and name of the file to load relative to the CLASSPATH
92
    * @return an ImageIcon instance with the specified image file
93
    * @throws IllegalArgumentException if the image resource cannot be loaded.
94
    */
95
   public ImageIcon loadImage( String imageName )
96
   {
97
      try
98
      {
99
         ClassLoader classloader = getClass().getClassLoader();
100
         java.net.URL url = classloader.getResource( imageName );
101
         if ( url != null )
102
         {
103
            ImageIcon icon = new ImageIcon( url );
104
            return icon;
105
         }
106
      }
107
      catch( Exception e )
108
      {
109
         e.printStackTrace();
110
      }
111
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
112
   }
113

    
114
   /**
115
    * Method for recalculating the component orientation for 
116
    * right-to-left Locales.
117
    * @param orientation the component orientation to be applied
118
    */
119
   public void applyComponentOrientation( ComponentOrientation orientation )
120
   {
121
      // Not yet implemented...
122
      // I18NUtils.applyComponentOrientation(this, orientation);
123
      super.applyComponentOrientation(orientation);
124
   }
125

    
126
   public JPanel createPanel()
127
   {
128
      JPanel jpanel1 = new JPanel();
129
      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");
130
      CellConstraints cc = new CellConstraints();
131
      jpanel1.setLayout(formlayout1);
132

    
133
      lblConnectionName.setName("lblConnectionName");
134
      lblConnectionName.setText("Nombre de la conexion");
135
      jpanel1.add(lblConnectionName,cc.xy(2,2));
136

    
137
      lblConnector.setName("lblConnector");
138
      lblConnector.setText("Conector");
139
      jpanel1.add(lblConnector,cc.xy(2,4));
140

    
141
      lblServer.setName("lblServer");
142
      lblServer.setText("Servidor");
143
      jpanel1.add(lblServer,cc.xy(2,6));
144

    
145
      lblPort.setName("lblPort");
146
      lblPort.setText("Puerto");
147
      jpanel1.add(lblPort,cc.xy(2,8));
148

    
149
      lblDataBase.setName("lblDataBase");
150
      lblDataBase.setText("Base de datos");
151
      jpanel1.add(lblDataBase,cc.xy(2,10));
152

    
153
      lblUsername.setName("lblUsername");
154
      lblUsername.setText("Usuario");
155
      jpanel1.add(lblUsername,cc.xy(2,12));
156

    
157
      lblPassword.setName("lblPassword");
158
      lblPassword.setText("Clave");
159
      jpanel1.add(lblPassword,cc.xy(2,14));
160

    
161
      cboConnections.setEditable(true);
162
      cboConnections.setName("cboConnections");
163
      cboConnections.setRequestFocusEnabled(false);
164
      jpanel1.add(cboConnections,cc.xy(4,2));
165

    
166
      cboConnectors.setName("cboConnectors");
167
      jpanel1.add(cboConnectors,cc.xy(4,4));
168

    
169
      txtServer.setName("txtServer");
170
      jpanel1.add(txtServer,cc.xy(4,6));
171

    
172
      txtPort.setName("txtPort");
173
      jpanel1.add(txtPort,cc.xy(4,8));
174

    
175
      txtUsername.setName("txtUsername");
176
      jpanel1.add(txtUsername,cc.xy(4,12));
177

    
178
      txtPassword.setName("txtPassword");
179
      jpanel1.add(txtPassword,cc.xy(4,14));
180

    
181
      jpanel1.add(createPanel1(),cc.xywh(2,16,3,1));
182
      jpanel1.add(createPanel2(),cc.xy(4,10));
183
      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 });
184
      return jpanel1;
185
   }
186

    
187
   public JPanel createPanel1()
188
   {
189
      JPanel jpanel1 = new JPanel();
190
      FormLayout formlayout1 = new FormLayout("RIGHT:12DLU:GROW(1.0)","CENTER:DEFAULT:NONE");
191
      CellConstraints cc = new CellConstraints();
192
      jpanel1.setLayout(formlayout1);
193

    
194
      lblFoother.setName("lblFoother");
195
      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>");
196
      jpanel1.add(lblFoother,cc.xy(1,1));
197

    
198
      addFillComponents(jpanel1,new int[0],new int[0]);
199
      return jpanel1;
200
   }
201

    
202
   public JPanel createPanel2()
203
   {
204
      JPanel jpanel1 = new JPanel();
205
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
206
      CellConstraints cc = new CellConstraints();
207
      jpanel1.setLayout(formlayout1);
208

    
209
      txtDataBase.setName("txtDataBase");
210
      jpanel1.add(txtDataBase,cc.xy(1,1));
211

    
212
      btnDataBaseBrowser.setActionCommand("...");
213
      btnDataBaseBrowser.setName("btnDataBaseBrowser");
214
      btnDataBaseBrowser.setText("...");
215
      jpanel1.add(btnDataBaseBrowser,cc.xy(2,1));
216

    
217
      addFillComponents(jpanel1,new int[0],new int[0]);
218
      return jpanel1;
219
   }
220

    
221
   /**
222
    * Initializer
223
    */
224
   protected void initializePanel()
225
   {
226
      setLayout(new BorderLayout());
227
      add(createPanel(), BorderLayout.CENTER);
228
   }
229

    
230

    
231
}