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