1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.commons.jelly.tags.swing.impl; |
17 |
|
|
18 |
|
import java.awt.GridBagConstraints; |
19 |
|
import java.awt.Insets; |
20 |
|
import java.lang.reflect.Field; |
21 |
|
|
22 |
|
import org.apache.commons.logging.Log; |
23 |
|
import org.apache.commons.logging.LogFactory; |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
public class GridBagConstraintBean extends GridBagConstraints { |
34 |
|
|
35 |
0 |
private boolean gridxSet = false; |
36 |
0 |
private boolean gridySet = false; |
37 |
0 |
private boolean gridwidthSet = false; |
38 |
0 |
private boolean gridheightSet = false; |
39 |
0 |
private boolean weightxSet = false; |
40 |
0 |
private boolean weightySet = false; |
41 |
0 |
private boolean ipadxSet = false; |
42 |
0 |
private boolean ipadySet = false; |
43 |
0 |
private boolean anchorSet = false; |
44 |
0 |
private boolean fillSet = false; |
45 |
|
|
46 |
|
|
47 |
0 |
private static final Log LOG = LogFactory.getLog(GridBagConstraintBean.class); |
48 |
|
|
49 |
|
|
50 |
|
private static final String ILLEGAL_ANCHOR_MSG = "Anchor must be one of the GridBagLayout constants for the current Java version."; |
51 |
|
|
52 |
0 |
public GridBagConstraintBean() { |
53 |
0 |
} |
54 |
|
|
55 |
|
public int getGridx() { |
56 |
0 |
return gridx; |
57 |
|
} |
58 |
|
public void setGridx(int gridx) { |
59 |
0 |
this.gridx = gridx; |
60 |
0 |
this.gridxSet = true; |
61 |
0 |
} |
62 |
|
|
63 |
|
public int getGridy() { |
64 |
0 |
return gridy; |
65 |
|
} |
66 |
|
public void setGridy(int gridy) { |
67 |
0 |
this.gridy = gridy; |
68 |
0 |
this.gridySet = true; |
69 |
0 |
} |
70 |
|
|
71 |
|
public int getGridwidth() { |
72 |
0 |
return gridwidth; |
73 |
|
} |
74 |
|
public void setGridwidth(int gridwidth) { |
75 |
0 |
this.gridwidth = gridwidth; |
76 |
0 |
this.gridwidthSet = true; |
77 |
0 |
} |
78 |
|
|
79 |
|
public int getGridheight() { |
80 |
0 |
return gridheight; |
81 |
|
} |
82 |
|
public void setGridheight(int gridheight) { |
83 |
0 |
this.gridheight = gridheight; |
84 |
0 |
this.gridheightSet = true; |
85 |
0 |
} |
86 |
|
|
87 |
|
public double getWeightx() { |
88 |
0 |
return weightx; |
89 |
|
} |
90 |
|
public void setWeightx(double weightx) { |
91 |
0 |
this.weightx = weightx; |
92 |
0 |
this.weightxSet = true; |
93 |
0 |
} |
94 |
|
|
95 |
|
public double getWeighty() { |
96 |
0 |
return weighty; |
97 |
|
} |
98 |
|
public void setWeighty(double weighty) { |
99 |
0 |
this.weighty = weighty; |
100 |
0 |
this.weightySet = true; |
101 |
0 |
} |
102 |
|
|
103 |
|
public int getIpadx() { |
104 |
0 |
return ipadx; |
105 |
|
} |
106 |
|
public void setIpadx(int ipadx) { |
107 |
0 |
this.ipadx = ipadx; |
108 |
0 |
this.ipadxSet = true; |
109 |
0 |
} |
110 |
|
|
111 |
|
public int getIpady() { |
112 |
0 |
return ipady; |
113 |
|
} |
114 |
|
public void setIpady(int ipady) { |
115 |
0 |
this.ipady = ipady; |
116 |
0 |
this.ipadySet = true; |
117 |
0 |
} |
118 |
|
|
119 |
|
|
120 |
|
public Insets getInsets() { |
121 |
0 |
return insets; |
122 |
|
} |
123 |
|
public void setInsets(Insets insets) { |
124 |
0 |
this.insets = insets; |
125 |
0 |
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
public String getAnchor() { |
133 |
0 |
switch (this.anchor) { |
134 |
|
case CENTER : |
135 |
0 |
return "center"; |
136 |
|
case NORTH : |
137 |
0 |
return "north"; |
138 |
|
case NORTHEAST : |
139 |
0 |
return "northeast"; |
140 |
|
case EAST : |
141 |
0 |
return "east"; |
142 |
|
case SOUTHEAST : |
143 |
0 |
return "southeast"; |
144 |
|
case SOUTH : |
145 |
0 |
return "south"; |
146 |
|
case SOUTHWEST : |
147 |
0 |
return "southwest"; |
148 |
|
case WEST : |
149 |
0 |
return "west"; |
150 |
|
case NORTHWEST : |
151 |
0 |
return "northwest"; |
152 |
|
} |
153 |
|
|
154 |
0 |
if (this.anchor == getByReflection("LINE_START")) |
155 |
0 |
return "line_start"; |
156 |
0 |
else if (this.anchor == getByReflection("LINE_END")) |
157 |
0 |
return "line_end"; |
158 |
0 |
else if (this.anchor == getByReflection("PAGE_START")) |
159 |
0 |
return "page_start"; |
160 |
0 |
else if (this.anchor == getByReflection("PAGE_END")) |
161 |
0 |
return "page_end"; |
162 |
0 |
else if (this.anchor == getByReflection("FIRST_LINE_START")) |
163 |
0 |
return "first_line_start"; |
164 |
0 |
else if (this.anchor == getByReflection("FIRST_LINE_END")) |
165 |
0 |
return "first_line_end"; |
166 |
0 |
else if (this.anchor == getByReflection("LAST_LINE_START")) |
167 |
0 |
return "last_line_start"; |
168 |
0 |
else if (this.anchor == getByReflection("LAST_LINE_END")) |
169 |
0 |
return "last_line_end"; |
170 |
|
|
171 |
0 |
throw new IllegalArgumentException(ILLEGAL_ANCHOR_MSG); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
public void setAnchor(String anchorString) { |
181 |
0 |
String lcAnchorString = anchorString.toLowerCase(); |
182 |
0 |
if (lcAnchorString.equals("center")) |
183 |
0 |
this.anchor = CENTER; |
184 |
0 |
else if (lcAnchorString.equals("north")) |
185 |
0 |
this.anchor = NORTH; |
186 |
0 |
else if (lcAnchorString.equals("northeast")) |
187 |
0 |
this.anchor = NORTHEAST; |
188 |
0 |
else if (lcAnchorString.equals("east")) |
189 |
0 |
this.anchor = EAST; |
190 |
0 |
else if (lcAnchorString.equals("southeast")) |
191 |
0 |
this.anchor = SOUTHEAST; |
192 |
0 |
else if (lcAnchorString.equals("south")) |
193 |
0 |
this.anchor = SOUTH; |
194 |
0 |
else if (lcAnchorString.equals("southwest")) |
195 |
0 |
this.anchor = SOUTHWEST; |
196 |
0 |
else if (lcAnchorString.equals("west")) |
197 |
0 |
this.anchor = WEST; |
198 |
0 |
else if (lcAnchorString.equals("northwest")) |
199 |
0 |
this.anchor = NORTHWEST; |
200 |
0 |
else if (lcAnchorString.equals("page_start")) |
201 |
0 |
this.anchor = getByReflection("PAGE_START"); |
202 |
0 |
else if (lcAnchorString.equals("page_end")) |
203 |
0 |
this.anchor = getByReflection("PAGE_END"); |
204 |
0 |
else if (lcAnchorString.equals("line_start")) |
205 |
0 |
this.anchor = getByReflection("LINE_START"); |
206 |
0 |
else if (lcAnchorString.equals("line_end")) |
207 |
0 |
this.anchor = getByReflection("LINE_END"); |
208 |
0 |
else if (lcAnchorString.equals("first_line_start")) |
209 |
0 |
this.anchor = getByReflection("FIRST_LINE_START"); |
210 |
0 |
else if (lcAnchorString.equals("first_line_end")) |
211 |
0 |
this.anchor = getByReflection("FIRST_LINE_END"); |
212 |
0 |
else if (lcAnchorString.equals("last_line_end")) |
213 |
0 |
this.anchor = getByReflection("LAST_LINE_END"); |
214 |
0 |
else if (lcAnchorString.equals("last_line_start")) |
215 |
0 |
this.anchor = getByReflection("LAST_LINE_START"); |
216 |
|
else |
217 |
0 |
throw new IllegalArgumentException("Anchor must be the name of one of the GridBagLayoutConstants (case doesn't matter): center, north, northeast, east, southeast, south, southwest, west, or northwest."); |
218 |
0 |
this.anchorSet = true; |
219 |
0 |
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
public String getFill() { |
227 |
0 |
switch (fill) { |
228 |
|
case NONE : |
229 |
0 |
return "none"; |
230 |
|
case HORIZONTAL : |
231 |
0 |
return "horizontal"; |
232 |
|
case VERTICAL : |
233 |
0 |
return "vertical"; |
234 |
|
case BOTH : |
235 |
0 |
return "both"; |
236 |
|
default : |
237 |
0 |
throw new IllegalArgumentException("Fill must be the name of one of the GridBagLayoutConstants: NONE, HORIZONTAL, VERTICAL, BOTH."); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
public void setFill(String fillString) { |
247 |
0 |
String lcFillString = fillString.toLowerCase(); |
248 |
0 |
if (lcFillString.equals("none")) |
249 |
0 |
this.fill = NONE; |
250 |
0 |
else if (lcFillString.equals("horizontal")) |
251 |
0 |
this.fill = HORIZONTAL; |
252 |
0 |
else if (lcFillString.equals("vertical")) |
253 |
0 |
this.fill = VERTICAL; |
254 |
0 |
else if (lcFillString.equals("both")) |
255 |
0 |
this.fill = BOTH; |
256 |
|
else |
257 |
0 |
throw new IllegalArgumentException("Fill must be the name of one of the GridBagLayoutConstants (case does not matter): NONE, HORIZONTAL, VERTICAL, BOTH."); |
258 |
0 |
this.fillSet = true; |
259 |
0 |
} |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
public void setBasedOn(GridBagConstraintBean from) { |
265 |
0 |
if (!gridxSet && from.gridxSet) { |
266 |
0 |
gridx = from.gridx; |
267 |
0 |
this.gridxSet = true; |
268 |
|
} |
269 |
0 |
if (!gridySet && from.gridySet) { |
270 |
0 |
gridy = from.gridy; |
271 |
0 |
this.gridySet = true; |
272 |
|
} |
273 |
0 |
if (!gridwidthSet && from.gridwidthSet) { |
274 |
0 |
gridwidth = from.gridwidth; |
275 |
0 |
this.gridwidthSet = true; |
276 |
|
} |
277 |
0 |
if (!gridheightSet && from.gridheightSet) { |
278 |
0 |
gridheight = from.gridheight; |
279 |
0 |
this.gridheightSet = true; |
280 |
|
} |
281 |
0 |
if (!weightxSet && from.weightxSet) { |
282 |
0 |
weightx = from.weightx; |
283 |
0 |
this.weightxSet = true; |
284 |
|
} |
285 |
0 |
if (!weightySet && from.weightySet) { |
286 |
0 |
weighty = from.weighty; |
287 |
0 |
this.weightySet = true; |
288 |
|
} |
289 |
0 |
if (!ipadxSet && from.ipadxSet) { |
290 |
0 |
ipadx = from.ipadx; |
291 |
0 |
this.ipadxSet = true; |
292 |
|
} |
293 |
0 |
if (!ipadySet && from.ipadySet) { |
294 |
0 |
ipady = from.ipady; |
295 |
0 |
this.ipadySet = true; |
296 |
|
} |
297 |
0 |
if (!fillSet && from.fillSet) { |
298 |
0 |
fill = from.fill; |
299 |
0 |
this.fillSet = true; |
300 |
|
} |
301 |
0 |
if (!anchorSet && from.anchorSet) { |
302 |
0 |
anchor = from.anchor; |
303 |
0 |
this.anchorSet = true; |
304 |
|
} |
305 |
0 |
} |
306 |
|
|
307 |
|
public String toString() { |
308 |
0 |
return "GridBagConstraintBean[" |
309 |
|
+ "gridx=" |
310 |
|
+ gridx |
311 |
|
+ ", gridy=" |
312 |
|
+ gridy |
313 |
|
+ ", gridwidth=" |
314 |
|
+ gridwidth |
315 |
|
+ ", gridheight=" |
316 |
|
+ gridheight |
317 |
|
+ ", weightx=" |
318 |
|
+ weightx |
319 |
|
+ ", weighty=" |
320 |
|
+ weighty |
321 |
|
+ ", ipadx=" |
322 |
|
+ ipadx |
323 |
|
+ ", ipady=" |
324 |
|
+ ipady |
325 |
|
+ ", anchor=" |
326 |
|
+ getAnchor() |
327 |
|
+ ", fill=" |
328 |
|
+ getFill() |
329 |
|
+ ", insets=" |
330 |
|
+ insets |
331 |
|
+ "]"; |
332 |
|
} |
333 |
|
|
334 |
|
private int getByReflection(String field) { |
335 |
|
try { |
336 |
0 |
Field f = getClass().getField(field); |
337 |
0 |
Integer rv = (Integer) f.get(this); |
338 |
0 |
return rv.intValue(); |
339 |
0 |
} catch (SecurityException e) { |
340 |
0 |
LOG.debug(e); |
341 |
0 |
throw new IllegalArgumentException(ILLEGAL_ANCHOR_MSG); |
342 |
0 |
} catch (NoSuchFieldException e) { |
343 |
0 |
LOG.debug(e); |
344 |
0 |
throw new IllegalArgumentException(ILLEGAL_ANCHOR_MSG); |
345 |
0 |
} catch (IllegalArgumentException e) { |
346 |
0 |
LOG.debug(e); |
347 |
0 |
throw new IllegalArgumentException(ILLEGAL_ANCHOR_MSG); |
348 |
0 |
} catch (IllegalAccessException e) { |
349 |
0 |
LOG.debug(e); |
350 |
0 |
throw new IllegalArgumentException(ILLEGAL_ANCHOR_MSG); |
351 |
|
} |
352 |
|
} |
353 |
|
|
354 |
|
} |