Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial.app / org.gvsig.h2spatial.app.mainplugin / src / main / java / org / gvsig / h2spatial / ImportTableView.java @ 43983

History | View | Annotate | Download (6.02 KB)

1
package org.gvsig.h2spatial;
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.Color;
8
import java.awt.ComponentOrientation;
9
import java.awt.Container;
10
import java.awt.Dimension;
11
import javax.swing.Box;
12
import javax.swing.ImageIcon;
13
import javax.swing.JButton;
14
import javax.swing.JCheckBox;
15
import javax.swing.JComboBox;
16
import javax.swing.JFrame;
17
import javax.swing.JLabel;
18
import javax.swing.JPanel;
19
import javax.swing.JTextField;
20

    
21

    
22
public class ImportTableView extends JPanel
23
{
24
   JLabel lblConnection = new JLabel();
25
   JLabel lblFileType = new JLabel();
26
   JLabel lblFile = new JLabel();
27
   JLabel lblTableName = new JLabel();
28
   JLabel lblDeleteTables = new JLabel();
29
   JComboBox cboConnection = new JComboBox();
30
   JButton btnConnection = new JButton();
31
   JComboBox cboFileType = new JComboBox();
32
   JTextField txtFile = new JTextField();
33
   JButton btnFile = new JButton();
34
   JTextField txtTableName = new JTextField();
35
   JCheckBox chkDeleteTables = new JCheckBox();
36

    
37
   /**
38
    * Default constructor
39
    */
40
   public ImportTableView()
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:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE","CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
128
      CellConstraints cc = new CellConstraints();
129
      jpanel1.setLayout(formlayout1);
130

    
131
      lblConnection.setName("lblConnection");
132
      lblConnection.setText("Connection");
133
      jpanel1.add(lblConnection,cc.xy(2,2));
134

    
135
      lblFileType.setName("lblFileType");
136
      lblFileType.setText("File type");
137
      jpanel1.add(lblFileType,cc.xy(2,4));
138

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

    
143
      lblTableName.setName("lblTableName");
144
      lblTableName.setText("Table name");
145
      jpanel1.add(lblTableName,cc.xy(2,8));
146

    
147
      lblDeleteTables.setName("lblDeleteTables");
148
      lblDeleteTables.setText("Delete tables");
149
      jpanel1.add(lblDeleteTables,cc.xy(2,10));
150

    
151
      cboConnection.setName("cboConnection");
152
      jpanel1.add(cboConnection,cc.xy(4,2));
153

    
154
      btnConnection.setActionCommand("...");
155
      btnConnection.setName("btnConnection");
156
      btnConnection.setText("...");
157
      jpanel1.add(btnConnection,cc.xy(6,2));
158

    
159
      cboFileType.setName("cboFileType");
160
      jpanel1.add(cboFileType,cc.xywh(4,4,3,1));
161

    
162
      txtFile.setBackground(new Color(236,233,216));
163
      txtFile.setEditable(false);
164
      txtFile.setName("txtFile");
165
      jpanel1.add(txtFile,cc.xy(4,6));
166

    
167
      btnFile.setActionCommand("...");
168
      btnFile.setName("btnFile");
169
      btnFile.setText("...");
170
      jpanel1.add(btnFile,cc.xy(6,6));
171

    
172
      txtTableName.setName("txtTableName");
173
      jpanel1.add(txtTableName,cc.xywh(4,8,3,1));
174

    
175
      chkDeleteTables.setName("chkDeleteTables");
176
      chkDeleteTables.setSelected(true);
177
      jpanel1.add(chkDeleteTables,cc.xywh(4,10,3,1));
178

    
179
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11 });
180
      return jpanel1;
181
   }
182

    
183
   /**
184
    * Initializer
185
    */
186
   protected void initializePanel()
187
   {
188
      setLayout(new BorderLayout());
189
      add(createPanel(), BorderLayout.CENTER);
190
   }
191

    
192

    
193
}