gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / pickercontroller / TestView.java @ 2491
History | View | Annotate | Download (7.79 KB)
1 |
package org.gvsig.tools.swing.impl.pickercontroller; |
---|---|
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.JFrame; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JScrollPane; |
17 |
import javax.swing.JSpinner; |
18 |
import javax.swing.JTextArea; |
19 |
import javax.swing.JTextField; |
20 |
|
21 |
|
22 |
public class TestView extends JPanel |
23 |
{ |
24 |
JTextField txtFile1 = new JTextField(); |
25 |
JTextField txtColor1 = new JTextField(); |
26 |
JTextField txtDate = new JTextField(); |
27 |
JTextArea txtFile2 = new JTextArea(); |
28 |
JButton btnFile1 = new JButton(); |
29 |
JButton btnColor1 = new JButton(); |
30 |
JButton btnDate = new JButton(); |
31 |
JButton btnFile2 = new JButton(); |
32 |
JSpinner spnTime = new JSpinner(); |
33 |
JTextField txtDatetime = new JTextField(); |
34 |
JButton btnDatetime = new JButton(); |
35 |
JSpinner spnDatetime = new JSpinner(); |
36 |
JSpinner spnDatetimeMillis = new JSpinner(); |
37 |
|
38 |
/**
|
39 |
* Default constructor
|
40 |
*/
|
41 |
public TestView()
|
42 |
{ |
43 |
initializePanel(); |
44 |
} |
45 |
|
46 |
/**
|
47 |
* Adds fill components to empty cells in the first row and first column of the grid.
|
48 |
* This ensures that the grid spacing will be the same as shown in the designer.
|
49 |
* @param cols an array of column indices in the first row where fill components should be added.
|
50 |
* @param rows an array of row indices in the first column where fill components should be added.
|
51 |
*/
|
52 |
void addFillComponents( Container panel, int[] cols, int[] rows ) |
53 |
{ |
54 |
Dimension filler = new Dimension(10,10); |
55 |
|
56 |
boolean filled_cell_11 = false; |
57 |
CellConstraints cc = new CellConstraints();
|
58 |
if ( cols.length > 0 && rows.length > 0 ) |
59 |
{ |
60 |
if ( cols[0] == 1 && rows[0] == 1 ) |
61 |
{ |
62 |
/** add a rigid area */
|
63 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,1) ); |
64 |
filled_cell_11 = true;
|
65 |
} |
66 |
} |
67 |
|
68 |
for( int index = 0; index < cols.length; index++ ) |
69 |
{ |
70 |
if ( cols[index] == 1 && filled_cell_11 ) |
71 |
{ |
72 |
continue;
|
73 |
} |
74 |
panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) ); |
75 |
} |
76 |
|
77 |
for( int index = 0; index < rows.length; index++ ) |
78 |
{ |
79 |
if ( rows[index] == 1 && filled_cell_11 ) |
80 |
{ |
81 |
continue;
|
82 |
} |
83 |
panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) ); |
84 |
} |
85 |
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Helper method to load an image file from the CLASSPATH
|
90 |
* @param imageName the package and name of the file to load relative to the CLASSPATH
|
91 |
* @return an ImageIcon instance with the specified image file
|
92 |
* @throws IllegalArgumentException if the image resource cannot be loaded.
|
93 |
*/
|
94 |
public ImageIcon loadImage( String imageName ) |
95 |
{ |
96 |
try
|
97 |
{ |
98 |
ClassLoader classloader = getClass().getClassLoader();
|
99 |
java.net.URL url = classloader.getResource( imageName ); |
100 |
if ( url != null ) |
101 |
{ |
102 |
ImageIcon icon = new ImageIcon( url ); |
103 |
return icon;
|
104 |
} |
105 |
} |
106 |
catch( Exception e ) |
107 |
{ |
108 |
e.printStackTrace(); |
109 |
} |
110 |
throw new IllegalArgumentException( "Unable to load image: " + imageName ); |
111 |
} |
112 |
|
113 |
/**
|
114 |
* Method for recalculating the component orientation for
|
115 |
* right-to-left Locales.
|
116 |
* @param orientation the component orientation to be applied
|
117 |
*/
|
118 |
public void applyComponentOrientation( ComponentOrientation orientation ) |
119 |
{ |
120 |
// Not yet implemented...
|
121 |
// I18NUtils.applyComponentOrientation(this, orientation);
|
122 |
super.applyComponentOrientation(orientation);
|
123 |
} |
124 |
|
125 |
public JPanel createPanel() |
126 |
{ |
127 |
JPanel jpanel1 = new JPanel(); |
128 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE","CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),CENTER:DEFAULT:NONE,CENTER:2DLU:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE,CENTER:DEFAULT:NONE"); |
129 |
CellConstraints cc = new CellConstraints();
|
130 |
jpanel1.setLayout(formlayout1); |
131 |
|
132 |
JLabel jlabel1 = new JLabel(); |
133 |
jlabel1.setText("Fichero");
|
134 |
jpanel1.add(jlabel1,cc.xy(2,2)); |
135 |
|
136 |
JLabel jlabel2 = new JLabel(); |
137 |
jlabel2.setText("Color");
|
138 |
jpanel1.add(jlabel2,cc.xy(2,4)); |
139 |
|
140 |
JLabel jlabel3 = new JLabel(); |
141 |
jlabel3.setText("Fecha");
|
142 |
jpanel1.add(jlabel3,cc.xy(2,6)); |
143 |
|
144 |
JLabel jlabel4 = new JLabel(); |
145 |
jlabel4.setText("Fichero2");
|
146 |
jpanel1.add(jlabel4,new CellConstraints(2,8,1,1,CellConstraints.DEFAULT,CellConstraints.TOP)); |
147 |
|
148 |
txtFile1.setName("txtFile1");
|
149 |
jpanel1.add(txtFile1,cc.xy(4,2)); |
150 |
|
151 |
txtColor1.setName("txtColor1");
|
152 |
jpanel1.add(txtColor1,cc.xy(4,4)); |
153 |
|
154 |
txtDate.setName("txtDate");
|
155 |
jpanel1.add(txtDate,cc.xy(4,6)); |
156 |
|
157 |
txtFile2.setName("txtFile2");
|
158 |
JScrollPane jscrollpane1 = new JScrollPane(); |
159 |
jscrollpane1.setViewportView(txtFile2); |
160 |
jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
161 |
jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
162 |
jpanel1.add(jscrollpane1,cc.xy(4,8)); |
163 |
|
164 |
btnFile1.setActionCommand("...");
|
165 |
btnFile1.setName("btnFile1");
|
166 |
btnFile1.setOpaque(false);
|
167 |
btnFile1.setText("...");
|
168 |
jpanel1.add(btnFile1,cc.xy(6,2)); |
169 |
|
170 |
btnColor1.setActionCommand("...");
|
171 |
btnColor1.setName("btnColor1");
|
172 |
btnColor1.setOpaque(false);
|
173 |
btnColor1.setText("...");
|
174 |
jpanel1.add(btnColor1,cc.xy(6,4)); |
175 |
|
176 |
btnDate.setActionCommand("...");
|
177 |
btnDate.setName("btnDate");
|
178 |
btnDate.setOpaque(false);
|
179 |
btnDate.setText("...");
|
180 |
jpanel1.add(btnDate,cc.xy(6,6)); |
181 |
|
182 |
btnFile2.setActionCommand("...");
|
183 |
btnFile2.setName("btnFile2");
|
184 |
btnFile2.setOpaque(false);
|
185 |
btnFile2.setText("...");
|
186 |
jpanel1.add(btnFile2,new CellConstraints(6,8,1,1,CellConstraints.DEFAULT,CellConstraints.TOP)); |
187 |
|
188 |
JLabel jlabel5 = new JLabel(); |
189 |
jlabel5.setText("Hora");
|
190 |
jpanel1.add(jlabel5,cc.xy(2,9)); |
191 |
|
192 |
spnTime.setName("spnTime");
|
193 |
spnTime.setOpaque(false);
|
194 |
jpanel1.add(spnTime,cc.xy(4,9)); |
195 |
|
196 |
JLabel jlabel6 = new JLabel(); |
197 |
jlabel6.setText("Datetime");
|
198 |
jpanel1.add(jlabel6,cc.xy(2,11)); |
199 |
|
200 |
jpanel1.add(createPanel1(),cc.xy(4,11)); |
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,12,13 }); |
202 |
return jpanel1;
|
203 |
} |
204 |
|
205 |
public JPanel createPanel1() |
206 |
{ |
207 |
JPanel jpanel1 = new JPanel(); |
208 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:GROW(0.6),FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.2),FILL:4DLU:NONE,FILL:DEFAULT:GROW(0.2)","CENTER:DEFAULT:NONE"); |
209 |
CellConstraints cc = new CellConstraints();
|
210 |
jpanel1.setLayout(formlayout1); |
211 |
|
212 |
txtDatetime.setName("txtDatetime");
|
213 |
jpanel1.add(txtDatetime,cc.xy(1,1)); |
214 |
|
215 |
btnDatetime.setActionCommand("...");
|
216 |
btnDatetime.setName("btnDatetime");
|
217 |
btnDatetime.setOpaque(false);
|
218 |
btnDatetime.setText("...");
|
219 |
jpanel1.add(btnDatetime,cc.xy(3,1)); |
220 |
|
221 |
spnDatetime.setName("spnDatetime");
|
222 |
spnDatetime.setOpaque(false);
|
223 |
jpanel1.add(spnDatetime,cc.xy(5,1)); |
224 |
|
225 |
spnDatetimeMillis.setName("spnDatetimeMillis");
|
226 |
jpanel1.add(spnDatetimeMillis,cc.xy(7,1)); |
227 |
|
228 |
addFillComponents(jpanel1,new int[]{ 2,4,6 },new int[0]); |
229 |
return jpanel1;
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* Initializer
|
234 |
*/
|
235 |
protected void initializePanel() |
236 |
{ |
237 |
setLayout(new BorderLayout()); |
238 |
add(createPanel(), BorderLayout.CENTER);
|
239 |
} |
240 |
|
241 |
|
242 |
} |