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