1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.swt;
17
18 import org.apache.commons.jelly.JellyTagException;
19 import org.apache.commons.jelly.TagSupport;
20 import org.apache.commons.jelly.XMLOutput;
21 import org.eclipse.swt.graphics.Drawable;
22 import org.eclipse.swt.graphics.GC;
23
24 /***
25 * Class to create a {@link GC} instance within Jelly SWT.
26 *
27 * @author <a href="mailto:crafterm@apache.org">Marcus Crafter</a>
28 * @version CVS $Id: GCTag.java 155420 2005-02-26 13:06:03Z dirkv $
29 */
30 public class GCTag extends TagSupport {
31
32 /*** Drawable name */
33 private Drawable drawable;
34
35 /*** Variable name */
36 private String var;
37
38 /***
39 * Obtain the {@link Drawable} name for this {@link GC}.
40 *
41 * @return a {@link GC} {@link Drawable}
42 */
43 public Drawable getDrawable() {
44 return this.drawable;
45 }
46
47 /***
48 * Set the {@link Drawable} name for this {@link GC}.
49 *
50 * @param drawable a {@link GC} {@link Drawable}
51 */
52 public void setDrawable(final Drawable drawable) {
53 this.drawable = drawable;
54 }
55
56 /***
57 * Sets the variable name.
58 *
59 * @param var the variable name of this {@link GC} instance
60 */
61 public void setVar(final String var) {
62 this.var = var;
63 }
64
65 /***
66 * Obtain the variable name.
67 *
68 * @return the variable name of this {@link GC} instance
69 */
70 public String getVar() {
71 return this.var;
72 }
73
74
75
76
77 /***
78 * Creates a {@link GC} instance and stores it in the Context under a
79 * particular variable name. Note, {@link GC} objects can only be created on
80 * {@link Drawable} objects.
81 *
82 * @param output {@link XMLOutput} reference
83 * @throws JellyTagException if an error occurs
84 * @see org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
85 */
86 public void doTag(final XMLOutput output) throws JellyTagException {
87
88 invokeBody(output);
89
90 final boolean nullDrawable = drawable == null;
91 final boolean drawableParent = drawable instanceof Drawable;
92
93 if (nullDrawable || !drawableParent) {
94 throw new JellyTagException(
95 "This tag must specify a Drawable attribute (ie. Image or Control)"
96 );
97 }
98
99 if (var == null) {
100 throw new JellyTagException("This tag requires a context variable name");
101 }
102
103
104 context.setVariable(var, new GC(drawable));
105 }
106 }