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

History | View | Annotate | Download (7.8 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
   JTextField txtXMLFile = new JTextField();
29
   JButton btnXMLFile = new JButton();
30
   JButton btnConnection = new JButton();
31
   JComboBox cboConnection = new JComboBox();
32
   JLabel lblStatusCaption = new JLabel();
33
   JLabel lblStatusMsg = new JLabel();
34
   JProgressBar pbStatus = new JProgressBar();
35
   JComboBox cboCharset = new JComboBox();
36
   JLabel lblConnectToRepository = new JLabel();
37
   JCheckBox chkConnectToRepository = new JCheckBox();
38

    
39
   /**
40
    * Default constructor
41
    */
42
   public ImportXML2dbPanelView()
43
   {
44
      initializePanel();
45
   }
46

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

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

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

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

    
87
   }
88

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

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

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

    
133
      lblFileXML.setName("lblFileXML");
134
      lblFileXML.setText("_XML_File");
135
      jpanel1.add(lblFileXML,cc.xy(2,2));
136

    
137
      lblDatabase.setName("lblDatabase");
138
      lblDatabase.setText("_Database");
139
      jpanel1.add(lblDatabase,cc.xy(2,6));
140

    
141
      lblCharset.setName("lblCharset");
142
      lblCharset.setText("_Charset");
143
      jpanel1.add(lblCharset,cc.xy(2,4));
144

    
145
      jpanel1.add(createPanel1(),cc.xy(4,2));
146
      jpanel1.add(createPanel2(),cc.xy(4,6));
147
      jpanel1.add(createPanel3(),cc.xywh(2,10,3,1));
148
      cboCharset.setName("cboCharset");
149
      jpanel1.add(cboCharset,cc.xy(4,4));
150

    
151
      lblConnectToRepository.setName("lblConnectToRepository");
152
      lblConnectToRepository.setText("_Connect_to_repository");
153
      jpanel1.add(lblConnectToRepository,cc.xy(2,8));
154

    
155
      chkConnectToRepository.setName("chkConnectToRepository");
156
      jpanel1.add(chkConnectToRepository,cc.xy(4,8));
157

    
158
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11 });
159
      return jpanel1;
160
   }
161

    
162
   public JPanel createPanel1()
163
   {
164
      JPanel jpanel1 = new JPanel();
165
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
166
      CellConstraints cc = new CellConstraints();
167
      jpanel1.setLayout(formlayout1);
168

    
169
      txtXMLFile.setName("txtXMLFile");
170
      jpanel1.add(txtXMLFile,cc.xy(1,1));
171

    
172
      btnXMLFile.setActionCommand("...");
173
      btnXMLFile.setName("btnXMLFile");
174
      btnXMLFile.setOpaque(false);
175
      btnXMLFile.setRolloverEnabled(true);
176
      btnXMLFile.setText("...");
177
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
178
      btnXMLFile.setBorder(emptyborder1);
179
      jpanel1.add(btnXMLFile,cc.xy(3,1));
180

    
181
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
182
      return jpanel1;
183
   }
184

    
185
   public JPanel createPanel2()
186
   {
187
      JPanel jpanel1 = new JPanel();
188
      FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE");
189
      CellConstraints cc = new CellConstraints();
190
      jpanel1.setLayout(formlayout1);
191

    
192
      btnConnection.setActionCommand("...");
193
      btnConnection.setName("btnConnection");
194
      btnConnection.setOpaque(false);
195
      btnConnection.setRolloverEnabled(true);
196
      btnConnection.setText("...");
197
      EmptyBorder emptyborder1 = new EmptyBorder(2,2,2,2);
198
      btnConnection.setBorder(emptyborder1);
199
      jpanel1.add(btnConnection,cc.xy(3,1));
200

    
201
      cboConnection.setName("cboConnection");
202
      jpanel1.add(cboConnection,cc.xy(1,1));
203

    
204
      addFillComponents(jpanel1,new int[]{ 2 },new int[0]);
205
      return jpanel1;
206
   }
207

    
208
   public JPanel createPanel3()
209
   {
210
      JPanel jpanel1 = new JPanel();
211
      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");
212
      CellConstraints cc = new CellConstraints();
213
      jpanel1.setLayout(formlayout1);
214

    
215
      lblStatusCaption.setName("lblStatusCaption");
216
      jpanel1.add(lblStatusCaption,cc.xy(1,1));
217

    
218
      lblStatusMsg.setName("lblStatusMsg");
219
      jpanel1.add(lblStatusMsg,cc.xy(1,3));
220

    
221
      pbStatus.setName("pbStatus");
222
      pbStatus.setValue(25);
223
      jpanel1.add(pbStatus,cc.xy(1,2));
224

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

    
229
   /**
230
    * Initializer
231
    */
232
   protected void initializePanel()
233
   {
234
      setLayout(new BorderLayout());
235
      add(createPanel(), BorderLayout.CENTER);
236
   }
237

    
238

    
239
}