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 / importxml2db / ImportXML2dbPanelView.java @ 47472

History | View | Annotate | Download (9.07 KB)

1
package org.gvsig.xml2db.swing.impl.importxml2db;
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 ImportXML2dbPanelView extends JPanel
24
{
25
   JLabel lblFileXML = new JLabel();
26
   JLabel lblDatabase = new JLabel();
27
   JLabel lblCharset = new JLabel();
28
   JLabel lblConnectToRepository = new JLabel();
29
   JCheckBox chkConnectToRepository = new JCheckBox();
30
   JLabel lblPrefixesForTables = new JLabel();
31
   JTextField txtPrefixesForTables = new JTextField();
32
   JTextField txtXMLFile = new JTextField();
33
   JButton btnXMLFile = new JButton();
34
   JButton btnConnection = new JButton();
35
   JComboBox cboConnection = new JComboBox();
36
   JLabel lblStatusCaption = new JLabel();
37
   JLabel lblStatusMsg = new JLabel();
38
   JProgressBar pbStatus = new JProgressBar();
39
   JButton btnDetectCharset = new JButton();
40
   JComboBox cboCharset = new JComboBox();
41

    
42
   /**
43
    * Default constructor
44
    */
45
   public ImportXML2dbPanelView()
46
   {
47
      initializePanel();
48
   }
49

    
50
   /**
51
    * Adds fill components to empty cells in the first row and first column of the grid.
52
    * This ensures that the grid spacing will be the same as shown in the designer.
53
    * @param cols an array of column indices in the first row where fill components should be added.
54
    * @param rows an array of row indices in the first column where fill components should be added.
55
    */
56
   void addFillComponents( Container panel, int[] cols, int[] rows )
57
   {
58
      Dimension filler = new Dimension(10,10);
59

    
60
      boolean filled_cell_11 = false;
61
      CellConstraints cc = new CellConstraints();
62
      if ( cols.length > 0 && rows.length > 0 )
63
      {
64
         if ( cols[0] == 1 && rows[0] == 1 )
65
         {
66
            /** add a rigid area  */
67
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
68
            filled_cell_11 = true;
69
         }
70
      }
71

    
72
      for( int index = 0; index < cols.length; index++ )
73
      {
74
         if ( cols[index] == 1 && filled_cell_11 )
75
         {
76
            continue;
77
         }
78
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
79
      }
80

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

    
90
   }
91

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

    
117
   /**
118
    * Method for recalculating the component orientation for 
119
    * right-to-left Locales.
120
    * @param orientation the component orientation to be applied
121
    */
122
   public void applyComponentOrientation( ComponentOrientation orientation )
123
   {
124
      // Not yet implemented...
125
      // I18NUtils.applyComponentOrientation(this, orientation);
126
      super.applyComponentOrientation(orientation);
127
   }
128

    
129
   public JPanel createPanel()
130
   {
131
      JPanel jpanel1 = new JPanel();
132
      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");
133
      CellConstraints cc = new CellConstraints();
134
      jpanel1.setLayout(formlayout1);
135

    
136
      lblFileXML.setName("lblFileXML");
137
      lblFileXML.setText("_XML_File");
138
      jpanel1.add(lblFileXML,cc.xy(2,2));
139

    
140
      lblDatabase.setName("lblDatabase");
141
      lblDatabase.setText("_Database");
142
      jpanel1.add(lblDatabase,cc.xy(2,6));
143

    
144
      lblCharset.setName("lblCharset");
145
      lblCharset.setText("_Charset");
146
      jpanel1.add(lblCharset,cc.xy(2,4));
147

    
148
      lblConnectToRepository.setName("lblConnectToRepository");
149
      lblConnectToRepository.setText("_Connect_to_repository");
150
      jpanel1.add(lblConnectToRepository,cc.xy(2,10));
151

    
152
      chkConnectToRepository.setName("chkConnectToRepository");
153
      jpanel1.add(chkConnectToRepository,cc.xy(4,10));
154

    
155
      lblPrefixesForTables.setName("lblPrefixesForTables");
156
      lblPrefixesForTables.setText("_Prefixes_for_tables");
157
      jpanel1.add(lblPrefixesForTables,cc.xy(2,8));
158

    
159
      txtPrefixesForTables.setName("txtPrefixesForTables");
160
      jpanel1.add(txtPrefixesForTables,cc.xy(4,8));
161

    
162
      jpanel1.add(createPanel1(),cc.xy(4,2));
163
      jpanel1.add(createPanel2(),cc.xy(4,6));
164
      jpanel1.add(createPanel3(),cc.xywh(2,12,3,1));
165
      jpanel1.add(createPanel4(),cc.xy(4,4));
166
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13 });
167
      return jpanel1;
168
   }
169

    
170
   public JPanel createPanel1()
171
   {
172
      JPanel jpanel1 = new JPanel();
173
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
174
      CellConstraints cc = new CellConstraints();
175
      jpanel1.setLayout(formlayout1);
176

    
177
      txtXMLFile.setName("txtXMLFile");
178
      jpanel1.add(txtXMLFile,cc.xy(1,1));
179

    
180
      btnXMLFile.setActionCommand("...");
181
      btnXMLFile.setName("btnXMLFile");
182
      btnXMLFile.setText("...");
183
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
184
      btnXMLFile.setBorder(emptyborder1);
185
      jpanel1.add(btnXMLFile,cc.xy(3,1));
186

    
187
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
188
      return jpanel1;
189
   }
190

    
191
   public JPanel createPanel2()
192
   {
193
      JPanel jpanel1 = new JPanel();
194
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
195
      CellConstraints cc = new CellConstraints();
196
      jpanel1.setLayout(formlayout1);
197

    
198
      btnConnection.setActionCommand("...");
199
      btnConnection.setName("btnConnection");
200
      btnConnection.setText("...");
201
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
202
      btnConnection.setBorder(emptyborder1);
203
      jpanel1.add(btnConnection,cc.xy(3,1));
204

    
205
      cboConnection.setName("cboConnection");
206
      jpanel1.add(cboConnection,cc.xy(1,1));
207

    
208
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
209
      return jpanel1;
210
   }
211

    
212
   public JPanel createPanel3()
213
   {
214
      JPanel jpanel1 = new JPanel();
215
      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");
216
      CellConstraints cc = new CellConstraints();
217
      jpanel1.setLayout(formlayout1);
218

    
219
      lblStatusCaption.setName("lblStatusCaption");
220
      jpanel1.add(lblStatusCaption,cc.xy(1,1));
221

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

    
225
      pbStatus.setName("pbStatus");
226
      pbStatus.setValue(25);
227
      jpanel1.add(pbStatus,cc.xy(1,2));
228

    
229
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
230
      return jpanel1;
231
   }
232

    
233
   public JPanel createPanel4()
234
   {
235
      JPanel jpanel1 = new JPanel();
236
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
237
      CellConstraints cc = new CellConstraints();
238
      jpanel1.setLayout(formlayout1);
239

    
240
      btnDetectCharset.setActionCommand("...");
241
      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"));
242
      btnDetectCharset.setName("btnDetectCharset");
243
      btnDetectCharset.setToolTipText("_Detect_charset");
244
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
245
      btnDetectCharset.setBorder(emptyborder1);
246
      jpanel1.add(btnDetectCharset,cc.xy(3,1));
247

    
248
      cboCharset.setName("cboCharset");
249
      jpanel1.add(cboCharset,cc.xy(1,1));
250

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

    
255
   /**
256
    * Initializer
257
    */
258
   protected void initializePanel()
259
   {
260
      setLayout(new BorderLayout());
261
      add(createPanel(), BorderLayout.CENTER);
262
   }
263

    
264

    
265
}