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

History | View | Annotate | Download (12.4 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
   JTextField txtXMLFile = new JTextField();
42
   JButton btnXMLFile = new JButton();
43
   JButton btnDataBaseFile = new JButton();
44
   JTextField txtDatabaseFile = new JTextField();
45
   JTextField txtProjection = new JTextField();
46
   JButton btnProjection = new JButton();
47
   JButton btnDetectProjection = new JButton();
48
   JLabel lblStatusCaption = new JLabel();
49
   JLabel lblStatusMsg = new JLabel();
50
   JProgressBar pbStatus = new JProgressBar();
51
   JButton btnDetectCharset = new JButton();
52
   JComboBox cboCharset = new JComboBox();
53

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

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

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

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

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

    
102
   }
103

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

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

    
141
   public JPanel createPanel()
142
   {
143
      JPanel jpanel1 = new JPanel();
144
      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");
145
      CellConstraints cc = new CellConstraints();
146
      jpanel1.setLayout(formlayout1);
147

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

    
152
      lblDatabaseFile.setName("lblDatabaseFile");
153
      lblDatabaseFile.setText("_File_for_the_database");
154
      jpanel1.add(lblDatabaseFile,cc.xy(2,10));
155

    
156
      lblRepositoryName.setName("lblRepositoryName");
157
      lblRepositoryName.setText("_Name_for_the_repository");
158
      jpanel1.add(lblRepositoryName,cc.xy(2,12));
159

    
160
      txtRepositoryName.setName("txtRepositoryName");
161
      jpanel1.add(txtRepositoryName,cc.xy(4,12));
162

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

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

    
171
      lblRegisterConnection.setName("lblRegisterConnection");
172
      lblRegisterConnection.setText("_Register_connection");
173
      jpanel1.add(lblRegisterConnection,cc.xy(2,16));
174

    
175
      chkRegisterConnection.setName("chkRegisterConnection");
176
      jpanel1.add(chkRegisterConnection,cc.xy(4,16));
177

    
178
      lblConnectToRepository.setName("lblConnectToRepository");
179
      lblConnectToRepository.setText("_Connect_to_repository");
180
      jpanel1.add(lblConnectToRepository,cc.xy(2,18));
181

    
182
      chkConnectToRepository.setName("chkConnectToRepository");
183
      jpanel1.add(chkConnectToRepository,cc.xy(4,18));
184

    
185
      lblOverwriteDatabase.setName("lblOverwriteDatabase");
186
      lblOverwriteDatabase.setText("_Overwrite_database");
187
      jpanel1.add(lblOverwriteDatabase,cc.xy(2,20));
188

    
189
      chkOverwriteDatabase.setName("chkOverwriteDatabase");
190
      jpanel1.add(chkOverwriteDatabase,cc.xy(4,20));
191

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

    
196
      cboLocale.setName("cboLocale");
197
      jpanel1.add(cboLocale,cc.xy(4,6));
198

    
199
      lblPrefixesForTables.setName("lblPrefixesForTables");
200
      lblPrefixesForTables.setText("_Prefixes_for_tables");
201
      jpanel1.add(lblPrefixesForTables,cc.xy(2,14));
202

    
203
      txtPrefixesForTables.setName("txtPrefixesForTables");
204
      jpanel1.add(txtPrefixesForTables,cc.xy(4,14));
205

    
206
      jpanel1.add(createPanel1(),cc.xy(4,2));
207
      jpanel1.add(createPanel2(),cc.xy(4,10));
208
      jpanel1.add(createPanel3(),cc.xy(4,8));
209
      jpanel1.add(createPanel4(),cc.xywh(2,22,3,1));
210
      jpanel1.add(createPanel5(),cc.xy(4,4));
211
      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 });
212
      return jpanel1;
213
   }
214

    
215
   public JPanel createPanel1()
216
   {
217
      JPanel jpanel1 = new JPanel();
218
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
219
      CellConstraints cc = new CellConstraints();
220
      jpanel1.setLayout(formlayout1);
221

    
222
      txtXMLFile.setName("txtXMLFile");
223
      jpanel1.add(txtXMLFile,cc.xy(1,1));
224

    
225
      btnXMLFile.setActionCommand("...");
226
      btnXMLFile.setName("btnXMLFile");
227
      btnXMLFile.setText("...");
228
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
229
      btnXMLFile.setBorder(emptyborder1);
230
      jpanel1.add(btnXMLFile,cc.xy(3,1));
231

    
232
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
233
      return jpanel1;
234
   }
235

    
236
   public JPanel createPanel2()
237
   {
238
      JPanel jpanel1 = new JPanel();
239
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
240
      CellConstraints cc = new CellConstraints();
241
      jpanel1.setLayout(formlayout1);
242

    
243
      btnDataBaseFile.setActionCommand("...");
244
      btnDataBaseFile.setName("btnDataBaseFile");
245
      btnDataBaseFile.setText("...");
246
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
247
      btnDataBaseFile.setBorder(emptyborder1);
248
      jpanel1.add(btnDataBaseFile,cc.xy(3,1));
249

    
250
      txtDatabaseFile.setName("txtDatabaseFile");
251
      jpanel1.add(txtDatabaseFile,cc.xy(1,1));
252

    
253
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
254
      return jpanel1;
255
   }
256

    
257
   public JPanel createPanel3()
258
   {
259
      JPanel jpanel1 = new JPanel();
260
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
261
      CellConstraints cc = new CellConstraints();
262
      jpanel1.setLayout(formlayout1);
263

    
264
      txtProjection.setName("txtProjection");
265
      jpanel1.add(txtProjection,cc.xy(1,1));
266

    
267
      btnProjection.setActionCommand("...");
268
      btnProjection.setName("btnProjection");
269
      btnProjection.setText("...");
270
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
271
      btnProjection.setBorder(emptyborder1);
272
      jpanel1.add(btnProjection,cc.xy(3,1));
273

    
274
      btnDetectProjection.setActionCommand("...");
275
      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"));
276
      btnDetectProjection.setName("btnDetectProjection");
277
      btnDetectProjection.setToolTipText("_Detect_projection");
278
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
279
      btnDetectProjection.setBorder(emptyborder2);
280
      jpanel1.add(btnDetectProjection,cc.xy(5,1));
281

    
282
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
283
      return jpanel1;
284
   }
285

    
286
   public JPanel createPanel4()
287
   {
288
      JPanel jpanel1 = new JPanel();
289
      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");
290
      CellConstraints cc = new CellConstraints();
291
      jpanel1.setLayout(formlayout1);
292

    
293
      lblStatusCaption.setName("lblStatusCaption");
294
      jpanel1.add(lblStatusCaption,cc.xy(1,1));
295

    
296
      lblStatusMsg.setName("lblStatusMsg");
297
      jpanel1.add(lblStatusMsg,cc.xy(1,3));
298

    
299
      pbStatus.setName("pbStatus");
300
      pbStatus.setValue(25);
301
      jpanel1.add(pbStatus,cc.xy(1,2));
302

    
303
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
304
      return jpanel1;
305
   }
306

    
307
   public JPanel createPanel5()
308
   {
309
      JPanel jpanel1 = new JPanel();
310
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
311
      CellConstraints cc = new CellConstraints();
312
      jpanel1.setLayout(formlayout1);
313

    
314
      btnDetectCharset.setActionCommand("...");
315
      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"));
316
      btnDetectCharset.setName("btnDetectCharset");
317
      btnDetectCharset.setToolTipText("_Detect_charset");
318
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
319
      btnDetectCharset.setBorder(emptyborder1);
320
      jpanel1.add(btnDetectCharset,cc.xy(3,1));
321

    
322
      cboCharset.setName("cboCharset");
323
      jpanel1.add(cboCharset,cc.xy(1,1));
324

    
325
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
326
      return jpanel1;
327
   }
328

    
329
   /**
330
    * Initializer
331
    */
332
   protected void initializePanel()
333
   {
334
      setLayout(new BorderLayout());
335
      add(createPanel(), BorderLayout.CENTER);
336
   }
337

    
338

    
339
}