Revision 2161
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/Test.java | ||
---|---|---|
1 |
package org.gvsig.tools.swing.impl.pickercontroller; |
|
2 |
|
|
3 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
4 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
5 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
6 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
7 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
8 |
import com.jgoodies.forms.layout.CellConstraints; |
|
9 |
import com.jgoodies.forms.layout.FormLayout; |
|
10 |
import java.awt.BorderLayout; |
|
11 |
import java.awt.ComponentOrientation; |
|
12 |
import java.awt.Container; |
|
13 |
import java.awt.Dimension; |
|
14 |
import javax.swing.Box; |
|
15 |
import javax.swing.ImageIcon; |
|
16 |
import javax.swing.JButton; |
|
17 |
import javax.swing.JComponent; |
|
18 |
import javax.swing.JFormattedTextField; |
|
19 |
import javax.swing.JLabel; |
|
20 |
import javax.swing.JPanel; |
|
21 |
import javax.swing.JTextField; |
|
22 |
import org.gvsig.tools.swing.api.Component; |
|
23 |
|
|
24 |
/** |
|
25 |
* |
|
26 |
* @author jjdelcerro |
|
27 |
*/ |
|
28 |
public class Test { |
|
29 |
|
|
30 |
public static class TestPanelView extends JPanel { |
|
31 |
|
|
32 |
JTextField txtFile1 = new JTextField(); |
|
33 |
JButton btnFile1 = new JButton(); |
|
34 |
JTextField txtColor1 = new JTextField(); |
|
35 |
JButton btnColor1 = new JButton(); |
|
36 |
JFormattedTextField txtDate = new JFormattedTextField(); |
|
37 |
JButton btnDate = new JButton(); |
|
38 |
|
|
39 |
/** |
|
40 |
* Default constructor |
|
41 |
*/ |
|
42 |
public TestPanelView() { |
|
43 |
initializePanel(); |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Adds fill components to empty cells in the first row and first column of |
|
48 |
* the grid. This ensures that the grid spacing will be the same as shown in |
|
49 |
* the designer. |
|
50 |
* |
|
51 |
* @param cols an array of column indices in the first row where fill |
|
52 |
* components should be added. |
|
53 |
* @param rows an array of row indices in the first column where fill |
|
54 |
* components should be added. |
|
55 |
*/ |
|
56 |
void addFillComponents(Container panel, int[] cols, int[] rows) { |
|
57 |
Dimension filler = new Dimension(10, 10); |
|
58 |
|
|
59 |
boolean filled_cell_11 = false; |
|
60 |
CellConstraints cc = new CellConstraints(); |
|
61 |
if (cols.length > 0 && rows.length > 0) { |
|
62 |
if (cols[0] == 1 && rows[0] == 1) { |
|
63 |
/** |
|
64 |
* add a rigid area |
|
65 |
*/ |
|
66 |
panel.add(Box.createRigidArea(filler), cc.xy(1, 1)); |
|
67 |
filled_cell_11 = true; |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
for (int index = 0; index < cols.length; index++) { |
|
72 |
if (cols[index] == 1 && filled_cell_11) { |
|
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 |
if (rows[index] == 1 && filled_cell_11) { |
|
80 |
continue; |
|
81 |
} |
|
82 |
panel.add(Box.createRigidArea(filler), cc.xy(1, rows[index])); |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Helper method to load an image file from the CLASSPATH |
|
89 |
* |
|
90 |
* @param imageName the package and name of the file to load relative to the |
|
91 |
* 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 |
try { |
|
97 |
ClassLoader classloader = getClass().getClassLoader(); |
|
98 |
java.net.URL url = classloader.getResource(imageName); |
|
99 |
if (url != null) { |
|
100 |
ImageIcon icon = new ImageIcon(url); |
|
101 |
return icon; |
|
102 |
} |
|
103 |
} catch (Exception e) { |
|
104 |
e.printStackTrace(); |
|
105 |
} |
|
106 |
throw new IllegalArgumentException("Unable to load image: " + imageName); |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Method for recalculating the component orientation for right-to-left |
|
111 |
* Locales. |
|
112 |
* |
|
113 |
* @param orientation the component orientation to be applied |
|
114 |
*/ |
|
115 |
public void applyComponentOrientation(ComponentOrientation orientation) { |
|
116 |
// Not yet implemented... |
|
117 |
// I18NUtils.applyComponentOrientation(this, orientation); |
|
118 |
super.applyComponentOrientation(orientation); |
|
119 |
} |
|
120 |
|
|
121 |
public JPanel createPanel() { |
|
122 |
JPanel jpanel1 = new JPanel(); |
|
123 |
FormLayout formlayout1 = new FormLayout("FILL:DEFAULT:NONE,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"); |
|
124 |
CellConstraints cc = new CellConstraints(); |
|
125 |
jpanel1.setLayout(formlayout1); |
|
126 |
|
|
127 |
JLabel jlabel1 = new JLabel(); |
|
128 |
jlabel1.setText("Fichero"); |
|
129 |
jpanel1.add(jlabel1, cc.xy(3, 2)); |
|
130 |
|
|
131 |
txtFile1.setName("txtFile1"); |
|
132 |
jpanel1.add(txtFile1, cc.xy(5, 2)); |
|
133 |
|
|
134 |
btnFile1.setActionCommand("..."); |
|
135 |
btnFile1.setName("btnFile1"); |
|
136 |
btnFile1.setText("..."); |
|
137 |
jpanel1.add(btnFile1, cc.xy(7, 2)); |
|
138 |
|
|
139 |
JLabel jlabel2 = new JLabel(); |
|
140 |
jlabel2.setText("Color"); |
|
141 |
jpanel1.add(jlabel2, cc.xy(3, 4)); |
|
142 |
|
|
143 |
txtColor1.setName("txtColor1"); |
|
144 |
jpanel1.add(txtColor1, cc.xy(5, 4)); |
|
145 |
|
|
146 |
btnColor1.setActionCommand("..."); |
|
147 |
btnColor1.setName("btnColor1"); |
|
148 |
btnColor1.setText("..."); |
|
149 |
jpanel1.add(btnColor1, cc.xy(7, 4)); |
|
150 |
|
|
151 |
JLabel jlabel3 = new JLabel(); |
|
152 |
jlabel3.setText("Fecha"); |
|
153 |
jpanel1.add(jlabel3, cc.xy(3, 6)); |
|
154 |
|
|
155 |
txtDate.setName("txtDate"); |
|
156 |
jpanel1.add(txtDate, cc.xy(5, 6)); |
|
157 |
|
|
158 |
btnDate.setActionCommand("..."); |
|
159 |
btnDate.setName("btnDate"); |
|
160 |
btnDate.setText("..."); |
|
161 |
jpanel1.add(btnDate, cc.xy(7, 6)); |
|
162 |
|
|
163 |
addFillComponents(jpanel1, new int[]{1, 2, 3, 4, 5, 6, 7, 8}, new int[]{1, 2, 3, 4, 5, 6, 7}); |
|
164 |
return jpanel1; |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* Initializer |
|
169 |
*/ |
|
170 |
protected void initializePanel() { |
|
171 |
setLayout(new BorderLayout()); |
|
172 |
add(createPanel(), BorderLayout.CENTER); |
|
173 |
} |
|
174 |
|
|
175 |
} |
|
176 |
|
|
177 |
private static class TestPanel |
|
178 |
extends TestPanelView |
|
179 |
implements Component |
|
180 |
{ |
|
181 |
|
|
182 |
private DatePickerControllerImpl pickerDate; |
|
183 |
private FilePickerControllerImpl pickerFile; |
|
184 |
private ColorPickerControllerImpl pickerColor; |
|
185 |
|
|
186 |
public TestPanel() { |
|
187 |
initComponents(); |
|
188 |
} |
|
189 |
|
|
190 |
@Override |
|
191 |
public JComponent asJComponent() { |
|
192 |
return this; |
|
193 |
} |
|
194 |
|
|
195 |
private void initComponents() { |
|
196 |
this.pickerDate = new DatePickerControllerImpl(txtDate, btnDate); |
|
197 |
this.pickerFile = new FilePickerControllerImpl(txtFile1, btnFile1); |
|
198 |
this.pickerColor = new ColorPickerControllerImpl(txtColor1, btnColor1); |
|
199 |
} |
|
200 |
} |
|
201 |
/** |
|
202 |
* @param args the command line arguments |
|
203 |
*/ |
|
204 |
public static void main(String[] args) throws Exception { |
|
205 |
Test test = new Test(); |
|
206 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
207 |
test.run(); |
|
208 |
} |
|
209 |
|
|
210 |
public void run() throws Exception { |
|
211 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
212 |
|
|
213 |
TestPanel panel = new TestPanel(); |
|
214 |
Dialog dialog = windowManager.createDialog( |
|
215 |
panel.asJComponent(), |
|
216 |
"Test", |
|
217 |
null, |
|
218 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
219 |
); |
|
220 |
dialog.show(WindowManager.MODE.WINDOW); |
|
221 |
} |
|
222 |
|
|
223 |
} |
Also available in: Unified diff