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

History | View | Annotate | Download (6.92 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.JComboBox;
13
import javax.swing.JFrame;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JTextField;
17

    
18

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

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

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

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

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

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

    
85
   }
86

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

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

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

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

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

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

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

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

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

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

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

    
164
      cboConnectors.setName("cboConnectors");
165
      jpanel1.add(cboConnectors,cc.xy(4,4));
166

    
167
      txtServer.setName("txtServer");
168
      jpanel1.add(txtServer,cc.xy(4,6));
169

    
170
      txtPort.setName("txtPort");
171
      jpanel1.add(txtPort,cc.xy(4,8));
172

    
173
      txtDataBase.setName("txtDataBase");
174
      jpanel1.add(txtDataBase,cc.xy(4,10));
175

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

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

    
182
      jpanel1.add(createPanel1(),cc.xywh(2,16,3,1));
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
   /**
203
    * Initializer
204
    */
205
   protected void initializePanel()
206
   {
207
      setLayout(new BorderLayout());
208
      add(createPanel(), BorderLayout.CENTER);
209
   }
210

    
211

    
212
}