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

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

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

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

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

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

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

    
100
   }
101

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

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

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

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

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

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

    
158
      txtRepositoryName.setName("txtRepositoryName");
159
      jpanel1.add(txtRepositoryName,cc.xy(4,12));
160

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

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

    
169
      lblRegisterConnection.setName("lblRegisterConnection");
170
      lblRegisterConnection.setText("_Register_connection");
171
      jpanel1.add(lblRegisterConnection,cc.xy(2,14));
172

    
173
      chkRegisterConnection.setName("chkRegisterConnection");
174
      jpanel1.add(chkRegisterConnection,cc.xy(4,14));
175

    
176
      lblConnectToRepository.setName("lblConnectToRepository");
177
      lblConnectToRepository.setText("_Connect_to_repository");
178
      jpanel1.add(lblConnectToRepository,cc.xy(2,16));
179

    
180
      chkConnectToRepository.setName("chkConnectToRepository");
181
      jpanel1.add(chkConnectToRepository,cc.xy(4,16));
182

    
183
      lblOverwriteDatabase.setName("lblOverwriteDatabase");
184
      lblOverwriteDatabase.setText("_Overwrite_database");
185
      jpanel1.add(lblOverwriteDatabase,cc.xy(2,18));
186

    
187
      chkOverwriteDatabase.setName("chkOverwriteDatabase");
188
      jpanel1.add(chkOverwriteDatabase,cc.xy(4,18));
189

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

    
194
      jpanel1.add(createPanel1(),cc.xy(4,2));
195
      jpanel1.add(createPanel2(),cc.xy(4,10));
196
      jpanel1.add(createPanel3(),cc.xy(4,8));
197
      jpanel1.add(createPanel4(),cc.xywh(2,20,3,1));
198
      cboLocale.setName("cboLocale");
199
      jpanel1.add(cboLocale,cc.xy(4,6));
200

    
201
      jpanel1.add(createPanel5(),cc.xy(4,4));
202
      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 });
203
      return jpanel1;
204
   }
205

    
206
   public JPanel createPanel1()
207
   {
208
      JPanel jpanel1 = new JPanel();
209
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
210
      CellConstraints cc = new CellConstraints();
211
      jpanel1.setLayout(formlayout1);
212

    
213
      txtXMLFile.setName("txtXMLFile");
214
      jpanel1.add(txtXMLFile,cc.xy(1,1));
215

    
216
      btnXMLFile.setActionCommand("...");
217
      btnXMLFile.setName("btnXMLFile");
218
      btnXMLFile.setText("...");
219
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
220
      btnXMLFile.setBorder(emptyborder1);
221
      jpanel1.add(btnXMLFile,cc.xy(3,1));
222

    
223
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
224
      return jpanel1;
225
   }
226

    
227
   public JPanel createPanel2()
228
   {
229
      JPanel jpanel1 = new JPanel();
230
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
231
      CellConstraints cc = new CellConstraints();
232
      jpanel1.setLayout(formlayout1);
233

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

    
241
      txtDatabaseFile.setName("txtDatabaseFile");
242
      jpanel1.add(txtDatabaseFile,cc.xy(1,1));
243

    
244
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
245
      return jpanel1;
246
   }
247

    
248
   public JPanel createPanel3()
249
   {
250
      JPanel jpanel1 = new JPanel();
251
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
252
      CellConstraints cc = new CellConstraints();
253
      jpanel1.setLayout(formlayout1);
254

    
255
      txtProjection.setName("txtProjection");
256
      jpanel1.add(txtProjection,cc.xy(1,1));
257

    
258
      btnProjection.setActionCommand("...");
259
      btnProjection.setName("btnProjection");
260
      btnProjection.setText("...");
261
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
262
      btnProjection.setBorder(emptyborder1);
263
      jpanel1.add(btnProjection,cc.xy(3,1));
264

    
265
      btnDetectProjection.setActionCommand("...");
266
      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"));
267
      btnDetectProjection.setName("btnDetectProjection");
268
      btnDetectProjection.setToolTipText("_Detect_projection");
269
      EmptyBorder emptyborder2 = new EmptyBorder(2,2,2,2);
270
      btnDetectProjection.setBorder(emptyborder2);
271
      jpanel1.add(btnDetectProjection,cc.xy(5,1));
272

    
273
      addFillComponents(jpanel1,new int[]{ 2,4 },new int[0]);
274
      return jpanel1;
275
   }
276

    
277
   public JPanel createPanel4()
278
   {
279
      JPanel jpanel1 = new JPanel();
280
      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");
281
      CellConstraints cc = new CellConstraints();
282
      jpanel1.setLayout(formlayout1);
283

    
284
      lblStatusCaption.setName("lblStatusCaption");
285
      jpanel1.add(lblStatusCaption,cc.xy(1,1));
286

    
287
      lblStatusMsg.setName("lblStatusMsg");
288
      jpanel1.add(lblStatusMsg,cc.xy(1,3));
289

    
290
      pbStatus.setName("pbStatus");
291
      pbStatus.setValue(25);
292
      jpanel1.add(pbStatus,cc.xy(1,2));
293

    
294
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
295
      return jpanel1;
296
   }
297

    
298
   public JPanel createPanel5()
299
   {
300
      JPanel jpanel1 = new JPanel();
301
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
302
      CellConstraints cc = new CellConstraints();
303
      jpanel1.setLayout(formlayout1);
304

    
305
      btnDetectCharset.setActionCommand("...");
306
      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"));
307
      btnDetectCharset.setName("btnDetectCharset");
308
      btnDetectCharset.setToolTipText("_Detect_charset");
309
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
310
      btnDetectCharset.setBorder(emptyborder1);
311
      jpanel1.add(btnDetectCharset,cc.xy(3,1));
312

    
313
      cboCharset.setName("cboCharset");
314
      jpanel1.add(cboCharset,cc.xy(1,1));
315

    
316
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
317
      return jpanel1;
318
   }
319

    
320
   /**
321
    * Initializer
322
    */
323
   protected void initializePanel()
324
   {
325
      setLayout(new BorderLayout());
326
      add(createPanel(), BorderLayout.CENTER);
327
   }
328

    
329

    
330
}