svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.h2spatial.app / org.gvsig.h2spatial.app.h2gis150 / src / main / java / org / gvsig / h2spatial / ImportTableView.java @ 45469
History | View | Annotate | Download (6.54 KB)
1 |
package org.gvsig.h2spatial; |
---|---|
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.Color; |
8 |
import java.awt.ComponentOrientation; |
9 |
import java.awt.Container; |
10 |
import java.awt.Dimension; |
11 |
import java.awt.event.WindowAdapter; |
12 |
import java.awt.event.WindowEvent; |
13 |
import javax.swing.Box; |
14 |
import javax.swing.ImageIcon; |
15 |
import javax.swing.JButton; |
16 |
import javax.swing.JCheckBox; |
17 |
import javax.swing.JComboBox; |
18 |
import javax.swing.JFrame; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JPanel; |
21 |
import javax.swing.JTextField; |
22 |
|
23 |
|
24 |
public class ImportTableView extends JPanel |
25 |
{ |
26 |
JLabel lblConnection = new JLabel(); |
27 |
JLabel lblFileType = new JLabel(); |
28 |
JLabel lblFile = new JLabel(); |
29 |
JLabel lblTableName = new JLabel(); |
30 |
JLabel lblDeleteTables = new JLabel(); |
31 |
JComboBox cboConnection = new JComboBox(); |
32 |
JButton btnConnection = new JButton(); |
33 |
JComboBox cboFileType = new JComboBox(); |
34 |
JTextField txtFile = new JTextField(); |
35 |
JButton btnFile = new JButton(); |
36 |
JTextField txtTableName = new JTextField(); |
37 |
JCheckBox chkDeleteTables = new JCheckBox(); |
38 |
|
39 |
/**
|
40 |
* Default constructor
|
41 |
*/
|
42 |
public ImportTableView()
|
43 |
{ |
44 |
initializePanel(); |
45 |
} |
46 |
|
47 |
/**
|
48 |
* Main method for panel
|
49 |
*/
|
50 |
public static void main(String[] args) |
51 |
{ |
52 |
JFrame frame = new JFrame(); |
53 |
frame.setSize(600, 400); |
54 |
frame.setLocation(100, 100); |
55 |
frame.getContentPane().add(new ImportTableView());
|
56 |
frame.setVisible(true);
|
57 |
|
58 |
frame.addWindowListener( new WindowAdapter() |
59 |
{ |
60 |
public void windowClosing( WindowEvent evt ) |
61 |
{ |
62 |
System.exit(0); |
63 |
} |
64 |
}); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
69 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
70 |
* @param cols an array of column indices in the first row where fill components should be added.
|
71 |
* @param rows an array of row indices in the first column where fill components should be added.
|
72 |
*/
|
73 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
74 |
{ |
75 |
Dimension filler = new Dimension(10,10); |
76 |
|
77 |
boolean filled_cell_11 = false; |
78 |
CellConstraints cc = new CellConstraints();
|
79 |
if ( cols.length > 0 && rows.length > 0 ) |
80 |
{ |
81 |
if ( cols[0] == 1 && rows[0] == 1 ) |
82 |
{ |
83 |
/** add a rigid area */
|
84 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
85 |
filled_cell_11 = true;
|
86 |
} |
87 |
} |
88 |
|
89 |
for( int index = 0; index < cols.length; index++ ) |
90 |
{ |
91 |
if ( cols[index] == 1 && filled_cell_11 ) |
92 |
{ |
93 |
continue;
|
94 |
} |
95 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
96 |
} |
97 |
|
98 |
for( int index = 0; index < rows.length; index++ ) |
99 |
{ |
100 |
if ( rows[index] == 1 && filled_cell_11 ) |
101 |
{ |
102 |
continue;
|
103 |
} |
104 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
/**
|
110 |
* Helper method to load an image file from the CLASSPATH
|
111 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
112 |
* @return an ImageIcon instance with the specified image file
|
113 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
114 |
*/
|
115 |
public ImageIcon loadImage( String imageName ) |
116 |
{ |
117 |
try
|
118 |
{ |
119 |
ClassLoader classloader = getClass().getClassLoader();
|
120 |
java.net.URL url = classloader.getResource( imageName ); |
121 |
if ( url != null ) |
122 |
{ |
123 |
ImageIcon icon = new ImageIcon( url ); |
124 |
return icon;
|
125 |
} |
126 |
} |
127 |
catch( Exception e ) |
128 |
{ |
129 |
e.printStackTrace(); |
130 |
} |
131 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* Method for recalculating the component orientation for
|
136 |
* right-to-left Locales.
|
137 |
* @param orientation the component orientation to be applied
|
138 |
*/
|
139 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
140 |
{ |
141 |
// Not yet implemented...
|
142 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
143 |
super.applyComponentOrientation(orientation);
|
144 |
} |
145 |
|
146 |
public JPanel createPanel() |
147 |
{ |
148 |
JPanel jpanel1 = new JPanel(); |
149 |
FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE,FILL:DEFAULT:NONE,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"); |
150 |
CellConstraints cc = new CellConstraints();
|
151 |
jpanel1.setLayout(formlayout1); |
152 |
|
153 |
lblConnection.setName("lblConnection");
|
154 |
lblConnection.setText("_Connection");
|
155 |
jpanel1.add(lblConnection,cc.xy(2,2)); |
156 |
|
157 |
lblFileType.setName("lblFileType");
|
158 |
lblFileType.setText("_File_type");
|
159 |
jpanel1.add(lblFileType,cc.xy(2,4)); |
160 |
|
161 |
lblFile.setName("lblFile");
|
162 |
lblFile.setText("_File");
|
163 |
jpanel1.add(lblFile,cc.xy(2,6)); |
164 |
|
165 |
lblTableName.setName("lblTableName");
|
166 |
lblTableName.setText("_Table_name");
|
167 |
jpanel1.add(lblTableName,cc.xy(2,8)); |
168 |
|
169 |
lblDeleteTables.setName("lblDeleteTables");
|
170 |
lblDeleteTables.setText("_Delete_tables");
|
171 |
jpanel1.add(lblDeleteTables,cc.xy(2,10)); |
172 |
|
173 |
cboConnection.setName("cboConnection");
|
174 |
jpanel1.add(cboConnection,cc.xy(4,2)); |
175 |
|
176 |
btnConnection.setActionCommand("...");
|
177 |
btnConnection.setName("btnConnection");
|
178 |
btnConnection.setText("...");
|
179 |
jpanel1.add(btnConnection,cc.xy(6,2)); |
180 |
|
181 |
cboFileType.setName("cboFileType");
|
182 |
jpanel1.add(cboFileType,cc.xywh(4,4,3,1)); |
183 |
|
184 |
txtFile.setBackground(new Color(236,233,216)); |
185 |
txtFile.setEditable(false);
|
186 |
txtFile.setName("txtFile");
|
187 |
jpanel1.add(txtFile,cc.xy(4,6)); |
188 |
|
189 |
btnFile.setActionCommand("...");
|
190 |
btnFile.setName("btnFile");
|
191 |
btnFile.setText("...");
|
192 |
jpanel1.add(btnFile,cc.xy(6,6)); |
193 |
|
194 |
txtTableName.setName("txtTableName");
|
195 |
jpanel1.add(txtTableName,cc.xywh(4,8,3,1)); |
196 |
|
197 |
chkDeleteTables.setName("chkDeleteTables");
|
198 |
chkDeleteTables.setSelected(true);
|
199 |
jpanel1.add(chkDeleteTables,cc.xywh(4,10,3,1)); |
200 |
|
201 |
addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11 }); |
202 |
return jpanel1;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Initializer
|
207 |
*/
|
208 |
protected void initializePanel() |
209 |
{ |
210 |
setLayout(new BorderLayout()); |
211 |
add(createPanel(), BorderLayout.CENTER);
|
212 |
} |
213 |
|
214 |
|
215 |
} |