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.Font;
19 import java.util.Map;
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.MapTagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 /***
29 * Creates an Font and attaches it to the parent component or exports the font as
30 * a reusable variable that can be attached to multiple widgets.
31 *
32 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
33 * @version $Revision: 155420 $
34 */
35 public class FontTag extends MapTagSupport {
36
37 /*** The Log to which logging calls will be made. */
38 private static final Log log = LogFactory.getLog(FontTag.class);
39
40 /*** the current font instance */
41 private Font font;
42
43 public FontTag() {
44 }
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public void doTag(final XMLOutput output) throws JellyTagException {
62 Map attributes = getAttributes();
63 String var = (String) attributes.remove("var");
64
65 font = createFont(attributes);
66
67 if (var != null) {
68 context.setVariable(var, font);
69 }
70 else {
71
72 ComponentTag tag = (ComponentTag) findAncestorWithClass( ComponentTag.class );
73 if ( tag != null ) {
74 tag.setFont(font);
75 }
76 else {
77 throw new JellyTagException( "this tag must be nested within a JellySwing widget tag or the 'var' attribute must be specified" );
78 }
79 }
80 }
81
82
83
84
85 /***
86 * @return the Font object for this tag
87 */
88 public Font getFont() {
89 return font;
90 }
91
92
93
94
95
96 /***
97 * Factory method to create a new Font based on the given properties
98 */
99 protected Font createFont(Map map) {
100 log.info( "Creating font from properties: " + map );
101 Font font = new Font(map);
102
103 log.info( "Created font: " + font );
104 return font;
105 }
106 }