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 javax.swing.border.Border;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.TagSupport;
22 import org.apache.commons.jelly.XMLOutput;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 /***
27 * An abstract base class used for concrete border tags which create new Border implementations
28 * and sets then on parent widgets and optionally export them as variables .
29 *
30 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
31 * @version $Revision: 155420 $
32 */
33 public abstract class BorderTagSupport extends TagSupport {
34
35 /*** The Log to which logging calls will be made. */
36 private static final Log log = LogFactory.getLog(BorderTagSupport.class);
37
38 private String var;
39
40 public BorderTagSupport() {
41 }
42
43
44
45 public void doTag(final XMLOutput output) throws JellyTagException {
46
47 Border border = createBorder();
48
49
50 invokeBody(output);
51
52 if (var != null) {
53 context.setVariable(var, border);
54 }
55 ComponentTag tag = (ComponentTag) findAncestorWithClass( ComponentTag.class );
56 if ( tag != null ) {
57 tag.setBorder(border);
58 }
59 else {
60 if (var == null) {
61 throw new JellyTagException( "Either the 'var' attribute must be specified to export this Border or this tag must be nested within a JellySwing widget tag" );
62 }
63 }
64 }
65
66
67
68
69
70 /***
71 * Sets the name of the variable to use to expose the new Border object.
72 * If this attribute is not set then the parent widget tag will have its
73 * border property set.
74 */
75 public void setVar(String var) {
76 this.var = var;
77 }
78
79
80
81
82 /***
83 * Factory method to create a new Border instance.
84 */
85 protected abstract Border createBorder();
86 }