1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swing;
17
18 import java.awt.BorderLayout;
19 import java.awt.Component;
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.TagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24
25 /***
26 * Represents a layout of a child component within its parent <borderLayout> layout.
27 *
28 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
29 * @version $Revision: 155420 $
30 */
31 public class BorderAlignTag extends TagSupport implements ContainerTag {
32
33 private String align;
34
35
36
37
38 /***
39 * Adds a child component to this parent
40 */
41 public void addChild(Component component, Object constraints) throws JellyTagException {
42 BorderLayoutTag tag = (BorderLayoutTag) findAncestorWithClass( BorderLayoutTag.class );
43 if (tag == null) {
44 throw new JellyTagException( "this tag must be nested within a <borderLayout> tag" );
45 }
46 tag.addLayoutComponent(component, getConstraints());
47 }
48
49
50
51 public void doTag(final XMLOutput output) throws JellyTagException {
52 invokeBody(output);
53 }
54
55
56
57
58 /***
59 * Returns the align.
60 * @return String
61 */
62 public String getAlign() {
63 return align;
64 }
65
66 /***
67 * Sets the alignment of the child component which is a case insensitive value
68 * of {NORTH, SOUTH, EAST, WEST, CENTER} which defaults to CENTER
69 */
70 public void setAlign(String align) {
71 this.align = align;
72 }
73
74
75
76
77 protected Object getConstraints() {
78 if ("north".equalsIgnoreCase(align)) {
79 return BorderLayout.NORTH;
80 }
81 else if ("south".equalsIgnoreCase(align)) {
82 return BorderLayout.SOUTH;
83 }
84 else if ("east".equalsIgnoreCase(align)) {
85 return BorderLayout.EAST;
86 }
87 else if ("west".equalsIgnoreCase(align)) {
88 return BorderLayout.WEST;
89 }
90 else {
91
92 return BorderLayout.CENTER;
93 }
94 }
95 }
96