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 / DefaultJDBCConnectionDialogView.java @ 44419

History | View | Annotate | Download (4.65 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.JFrame;
14
import javax.swing.JPanel;
15

    
16

    
17
public class DefaultJDBCConnectionDialogView extends JPanel
18
{
19
   JButton btnAcept = new JButton();
20
   JButton btnCancel = new JButton();
21
   JPanel containerJDBCConnectionPanel = new JPanel();
22
   JButton btnMore = new JButton();
23

    
24
   /**
25
    * Default constructor
26
    */
27
   public DefaultJDBCConnectionDialogView()
28
   {
29
      initializePanel();
30
   }
31

    
32
   /**
33
    * Adds fill components to empty cells in the first row and first column of the grid.
34
    * This ensures that the grid spacing will be the same as shown in the designer.
35
    * @param cols an array of column indices in the first row where fill components should be added.
36
    * @param rows an array of row indices in the first column where fill components should be added.
37
    */
38
   void addFillComponents( Container panel, int[] cols, int[] rows )
39
   {
40
      Dimension filler = new Dimension(10,10);
41

    
42
      boolean filled_cell_11 = false;
43
      CellConstraints cc = new CellConstraints();
44
      if ( cols.length > 0 && rows.length > 0 )
45
      {
46
         if ( cols[0] == 1 && rows[0] == 1 )
47
         {
48
            /** add a rigid area  */
49
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
50
            filled_cell_11 = true;
51
         }
52
      }
53

    
54
      for( int index = 0; index < cols.length; index++ )
55
      {
56
         if ( cols[index] == 1 && filled_cell_11 )
57
         {
58
            continue;
59
         }
60
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
61
      }
62

    
63
      for( int index = 0; index < rows.length; index++ )
64
      {
65
         if ( rows[index] == 1 && filled_cell_11 )
66
         {
67
            continue;
68
         }
69
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
70
      }
71

    
72
   }
73

    
74
   /**
75
    * Helper method to load an image file from the CLASSPATH
76
    * @param imageName the package and name of the file to load relative to the CLASSPATH
77
    * @return an ImageIcon instance with the specified image file
78
    * @throws IllegalArgumentException if the image resource cannot be loaded.
79
    */
80
   public ImageIcon loadImage( String imageName )
81
   {
82
      try
83
      {
84
         ClassLoader classloader = getClass().getClassLoader();
85
         java.net.URL url = classloader.getResource( imageName );
86
         if ( url != null )
87
         {
88
            ImageIcon icon = new ImageIcon( url );
89
            return icon;
90
         }
91
      }
92
      catch( Exception e )
93
      {
94
         e.printStackTrace();
95
      }
96
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
97
   }
98

    
99
   /**
100
    * Method for recalculating the component orientation for 
101
    * right-to-left Locales.
102
    * @param orientation the component orientation to be applied
103
    */
104
   public void applyComponentOrientation( ComponentOrientation orientation )
105
   {
106
      // Not yet implemented...
107
      // I18NUtils.applyComponentOrientation(this, orientation);
108
      super.applyComponentOrientation(orientation);
109
   }
110

    
111
   public JPanel createPanel()
112
   {
113
      JPanel jpanel1 = new JPanel();
114
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE");
115
      CellConstraints cc = new CellConstraints();
116
      jpanel1.setLayout(formlayout1);
117

    
118
      btnAcept.setActionCommand("Acept");
119
      btnAcept.setName("btnAcept");
120
      btnAcept.setText("Acept");
121
      jpanel1.add(btnAcept,cc.xy(7,4));
122

    
123
      btnCancel.setActionCommand("Cancel");
124
      btnCancel.setName("btnCancel");
125
      btnCancel.setText("Cancel");
126
      jpanel1.add(btnCancel,cc.xy(9,4));
127

    
128
      containerJDBCConnectionPanel.setName("containerJDBCConnectionPanel");
129
      jpanel1.add(containerJDBCConnectionPanel,cc.xywh(2,2,8,1));
130

    
131
      btnMore.setActionCommand("More...");
132
      btnMore.setName("btnMore");
133
      btnMore.setText("More...");
134
      jpanel1.add(btnMore,cc.xy(5,4));
135

    
136
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10 },new int[]{ 1,2,3,4,5 });
137
      return jpanel1;
138
   }
139

    
140
   /**
141
    * Initializer
142
    */
143
   protected void initializePanel()
144
   {
145
      setLayout(new BorderLayout());
146
      add(createPanel(), BorderLayout.CENTER);
147
   }
148

    
149

    
150
}