Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.xml2db / org.gvsig.xml2db.swing / org.gvsig.xml2db.swing.impl / src / main / java / org / gvsig / xml2db / swing / impl / copyxml2db / CopyXml2dbPanelView.java @ 47607

History | View | Annotate | Download (12.8 KB)

1
package org.gvsig.xml2db.swing.impl.copyxml2db;
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.JCheckBox;
14
import javax.swing.JComboBox;
15
import javax.swing.JFrame;
16
import javax.swing.JLabel;
17
import javax.swing.JPanel;
18
import javax.swing.JProgressBar;
19
import javax.swing.JTextField;
20
import javax.swing.border.EmptyBorder;
21

    
22

    
23
public class CopyXml2dbPanelView extends JPanel
24
{
25
   JLabel lblFileXML = new JLabel();
26
   JLabel lblDatabaseFile = new JLabel();
27
   JLabel lblRepositoryName = new JLabel();
28
   JTextField txtRepositoryName = new JTextField();
29
   JLabel lblProjection = new JLabel();
30
   JLabel lblCharset = new JLabel();
31
   JLabel lblRegisterConnection = new JLabel();
32
   JCheckBox chkRegisterConnection = new JCheckBox();
33
   JLabel lblConnectToRepository = new JLabel();
34
   JCheckBox chkConnectToRepository = new JCheckBox();
35
   JLabel lblOverwriteDatabase = new JLabel();
36
   JCheckBox chkOverwriteDatabase = new JCheckBox();
37
   JLabel lblLocale = new JLabel();
38
   JComboBox cboLocale = new JComboBox();
39
   JLabel lblPrefixesForTables = new JLabel();
40
   JTextField txtPrefixesForTables = new JTextField();
41
   JLabel lblDatabaseType = new JLabel();
42
   JTextField txtXMLFile = new JTextField();
43
   JButton btnXMLFile = new JButton();
44
   JButton btnDataBaseFile = new JButton();
45
   JTextField txtDatabaseFile = new JTextField();
46
   JTextField txtProjection = new JTextField();
47
   JButton btnProjection = new JButton();
48
   JButton btnDetectProjection = new JButton();
49
   JLabel lblStatusCaption = new JLabel();
50
   JLabel lblStatusMsg = new JLabel();
51
   JProgressBar pbStatus = new JProgressBar();
52
   JButton btnDetectCharset = new JButton();
53
   JComboBox cboCharset = new JComboBox();
54
   JComboBox cboDatabaseType = new JComboBox();
55

    
56
   /**
57
    * Default constructor
58
    */
59
   public CopyXml2dbPanelView()
60
   {
61
      initializePanel();
62
   }
63

    
64
   /**
65
    * Adds fill components to empty cells in the first row and first column of the grid.
66
    * This ensures that the grid spacing will be the same as shown in the designer.
67
    * @param cols an array of column indices in the first row where fill components should be added.
68
    * @param rows an array of row indices in the first column where fill components should be added.
69
    */
70
   void addFillComponents( Container panel, int[] cols, int[] rows )
71
   {
72
      Dimension filler = new Dimension(10,10);
73

    
74
      boolean filled_cell_11 = false;
75
      CellConstraints cc = new CellConstraints();
76
      if ( cols.length > 0 && rows.length > 0 )
77
      {
78
         if ( cols[0] == 1 && rows[0] == 1 )
79
         {
80
            /** add a rigid area  */
81
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
82
            filled_cell_11 = true;
83
         }
84
      }
85

    
86
      for( int index = 0; index < cols.length; index++ )
87
      {
88
         if ( cols[index] == 1 && filled_cell_11 )
89
         {
90
            continue;
91
         }
92
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
93
      }
94

    
95
      for( int index = 0; index < rows.length; index++ )
96
      {
97
         if ( rows[index] == 1 && filled_cell_11 )
98
         {
99
            continue;
100
         }
101
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
102
      }
103

    
104
   }
105

    
106
   /**
107
    * Helper method to load an image file from the CLASSPATH
108
    * @param imageName the package and name of the file to load relative to the CLASSPATH
109
    * @return an ImageIcon instance with the specified image file
110
    * @throws IllegalArgumentException if the image resource cannot be loaded.
111
    */
112
   public ImageIcon loadImage( String imageName )
113
   {
114
      try
115
      {
116
         ClassLoader classloader = getClass().getClassLoader();
117
         java.net.URL url = classloader.getResource( imageName );
118
         if ( url != null )
119
         {
120
            ImageIcon icon = new ImageIcon( url );
121
            return icon;
122
         }
123
      }
124
      catch( Exception e )
125
      {
126
         e.printStackTrace();
127
      }
128
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
129
   }
130

    
131
   /**
132
    * Method for recalculating the component orientation for 
133
    * right-to-left Locales.
134
    * @param orientation the component orientation to be applied
135
    */
136
   public void applyComponentOrientation( ComponentOrientation orientation )
137
   {
138
      // Not yet implemented...
139
      // I18NUtils.applyComponentOrientation(this, orientation);
140
      super.applyComponentOrientation(orientation);
141
   }
142

    
143
   public JPanel createPanel()
144
   {
145
      JPanel jpanel1 = new JPanel();
146
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),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,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,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:2DLU:NONE");
147
      CellConstraints cc = new CellConstraints();
148
      jpanel1.setLayout(formlayout1);
149

    
150
      lblFileXML.setName("lblFileXML");
151
      lblFileXML.setText("_XML_File");
152
      jpanel1.add(lblFileXML,cc.xy(2,2));
153

    
154
      lblDatabaseFile.setName("lblDatabaseFile");
155
      lblDatabaseFile.setText("_File_for_the_database");
156
      jpanel1.add(lblDatabaseFile,cc.xy(2,14));
157

    
158
      lblRepositoryName.setName("lblRepositoryName");
159
      lblRepositoryName.setText("_Name_for_the_repository");
160
      jpanel1.add(lblRepositoryName,cc.xy(2,16));
161

    
162
      txtRepositoryName.setName("txtRepositoryName");
163
      jpanel1.add(txtRepositoryName,cc.xy(4,16));
164

    
165
      lblProjection.setName("lblProjection");
166
      lblProjection.setText("_Projection");
167
      jpanel1.add(lblProjection,cc.xy(2,8));
168

    
169
      lblCharset.setName("lblCharset");
170
      lblCharset.setText("_Charset");
171
      jpanel1.add(lblCharset,cc.xy(2,4));
172

    
173
      lblRegisterConnection.setName("lblRegisterConnection");
174
      lblRegisterConnection.setText("_Register_connection");
175
      jpanel1.add(lblRegisterConnection,cc.xy(2,18));
176

    
177
      chkRegisterConnection.setName("chkRegisterConnection");
178
      jpanel1.add(chkRegisterConnection,cc.xy(4,18));
179

    
180
      lblConnectToRepository.setName("lblConnectToRepository");
181
      lblConnectToRepository.setText("_Connect_to_repository");
182
      jpanel1.add(lblConnectToRepository,cc.xy(2,20));
183

    
184
      chkConnectToRepository.setName("chkConnectToRepository");
185
      jpanel1.add(chkConnectToRepository,cc.xy(4,20));
186

    
187
      lblOverwriteDatabase.setName("lblOverwriteDatabase");
188
      lblOverwriteDatabase.setText("_Overwrite_database");
189
      jpanel1.add(lblOverwriteDatabase,cc.xy(2,22));
190

    
191
      chkOverwriteDatabase.setName("chkOverwriteDatabase");
192
      jpanel1.add(chkOverwriteDatabase,cc.xy(4,22));
193

    
194
      lblLocale.setName("lblLocale");
195
      lblLocale.setText("_Language");
196
      jpanel1.add(lblLocale,cc.xy(2,6));
197

    
198
      cboLocale.setName("cboLocale");
199
      jpanel1.add(cboLocale,cc.xy(4,6));
200

    
201
      lblPrefixesForTables.setName("lblPrefixesForTables");
202
      lblPrefixesForTables.setText("_Prefixes_for_tables");
203
      jpanel1.add(lblPrefixesForTables,cc.xy(2,10));
204

    
205
      txtPrefixesForTables.setName("txtPrefixesForTables");
206
      jpanel1.add(txtPrefixesForTables,cc.xy(4,10));
207

    
208
      lblDatabaseType.setName("lblDatabaseType");
209
      lblDatabaseType.setText("_Database_type");
210
      jpanel1.add(lblDatabaseType,cc.xy(2,12));
211

    
212
      jpanel1.add(createPanel1(),cc.xy(4,2));
213
      jpanel1.add(createPanel2(),cc.xy(4,14));
214
      jpanel1.add(createPanel3(),cc.xy(4,8));
215
      jpanel1.add(createPanel4(),cc.xywh(2,24,3,1));
216
      jpanel1.add(createPanel5(),cc.xy(4,4));
217
      cboDatabaseType.setName("cboDatabaseType");
218
      jpanel1.add(cboDatabaseType,cc.xy(4,12));
219

    
220
      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,20,21,22,23,24,25 });
221
      return jpanel1;
222
   }
223

    
224
   public JPanel createPanel1()
225
   {
226
      JPanel jpanel1 = new JPanel();
227
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
228
      CellConstraints cc = new CellConstraints();
229
      jpanel1.setLayout(formlayout1);
230

    
231
      txtXMLFile.setName("txtXMLFile");
232
      jpanel1.add(txtXMLFile,cc.xy(1,1));
233

    
234
      btnXMLFile.setActionCommand("...");
235
      btnXMLFile.setName("btnXMLFile");
236
      btnXMLFile.setText("...");
237
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
238
      btnXMLFile.setBorder(emptyborder1);
239
      jpanel1.add(btnXMLFile,cc.xy(3,1));
240

    
241
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
242
      return jpanel1;
243
   }
244

    
245
   public JPanel createPanel2()
246
   {
247
      JPanel jpanel1 = new JPanel();
248
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
249
      CellConstraints cc = new CellConstraints();
250
      jpanel1.setLayout(formlayout1);
251

    
252
      btnDataBaseFile.setActionCommand("...");
253
      btnDataBaseFile.setName("btnDataBaseFile");
254
      btnDataBaseFile.setText("...");
255
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
256
      btnDataBaseFile.setBorder(emptyborder1);
257
      jpanel1.add(btnDataBaseFile,cc.xy(3,1));
258

    
259
      txtDatabaseFile.setName("txtDatabaseFile");
260
      jpanel1.add(txtDatabaseFile,cc.xy(1,1));
261

    
262
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
263
      return jpanel1;
264
   }
265

    
266
   public JPanel createPanel3()
267
   {
268
      JPanel jpanel1 = new JPanel();
269
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
270
      CellConstraints cc = new CellConstraints();
271
      jpanel1.setLayout(formlayout1);
272

    
273
      txtProjection.setName("txtProjection");
274
      jpanel1.add(txtProjection,cc.xy(1,1));
275

    
276
      btnProjection.setActionCommand("...");
277
      btnProjection.setName("btnProjection");
278
      btnProjection.setText("...");
279
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
280
      btnProjection.setBorder(emptyborder1);
281
      jpanel1.add(btnProjection,cc.xy(3,1));
282

    
283
      btnDetectProjection.setActionCommand("...");
284
      btnDetectProjection.setIcon(loadImage("projects/gvSIG/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.swing/org.gvsig.xml2db.swing.impl/src/main/resources/org/gvsig/xml2db/swing/impl/images/detect-crs.png"));
285
      btnDetectProjection.setName("btnDetectProjection");
286
      btnDetectProjection.setToolTipText("_Detect_projection");
287
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
288
      btnDetectProjection.setBorder(emptyborder2);
289
      jpanel1.add(btnDetectProjection,cc.xy(5,1));
290

    
291
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
292
      return jpanel1;
293
   }
294

    
295
   public JPanel createPanel4()
296
   {
297
      JPanel jpanel1 = new JPanel();
298
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE","CENTER:MAX(12DLU;DEFAULT):NONE,CENTER:MAX(12DLU;DEFAULT):NONE,CENTER:MAX(12DLU;DEFAULT):NONE");
299
      CellConstraints cc = new CellConstraints();
300
      jpanel1.setLayout(formlayout1);
301

    
302
      lblStatusCaption.setName("lblStatusCaption");
303
      jpanel1.add(lblStatusCaption,cc.xy(1,1));
304

    
305
      lblStatusMsg.setName("lblStatusMsg");
306
      jpanel1.add(lblStatusMsg,cc.xy(1,3));
307

    
308
      pbStatus.setName("pbStatus");
309
      pbStatus.setValue(25);
310
      jpanel1.add(pbStatus,cc.xy(1,2));
311

    
312
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
313
      return jpanel1;
314
   }
315

    
316
   public JPanel createPanel5()
317
   {
318
      JPanel jpanel1 = new JPanel();
319
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
320
      CellConstraints cc = new CellConstraints();
321
      jpanel1.setLayout(formlayout1);
322

    
323
      btnDetectCharset.setActionCommand("...");
324
      btnDetectCharset.setIcon(loadImage("projects/gvSIG/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.xml2db/org.gvsig.xml2db.swing/org.gvsig.xml2db.swing.impl/src/main/resources/org/gvsig/xml2db/swing/impl/images/detect-charset.png"));
325
      btnDetectCharset.setName("btnDetectCharset");
326
      btnDetectCharset.setToolTipText("_Detect_charset");
327
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
328
      btnDetectCharset.setBorder(emptyborder1);
329
      jpanel1.add(btnDetectCharset,cc.xy(3,1));
330

    
331
      cboCharset.setName("cboCharset");
332
      jpanel1.add(cboCharset,cc.xy(1,1));
333

    
334
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
335
      return jpanel1;
336
   }
337

    
338
   /**
339
    * Initializer
340
    */
341
   protected void initializePanel()
342
   {
343
      setLayout(new BorderLayout());
344
      add(createPanel(), BorderLayout.CENTER);
345
   }
346

    
347

    
348
}