1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.awt.Font ; 11 12 import java.util.Hashtable ; 13 import java.util.Map ; 14 15 import org.w3c.dom.Element ; 16 17 import net.openmarkup.AttributeHandler; 18 import net.openmarkup.ElementType; 19 import net.openmarkup.Scribe; 20 21 import org.jdesktop.jdnc.markup.Attributes; 22 import org.jdesktop.jdnc.markup.Namespace; 23 import org.jdesktop.jdnc.markup.attr.*; 24 25 29 public class FontElement extends ElementProxy { 30 31 private static final Map attrMap = new Hashtable (); 32 33 public FontElement(Element element, ElementType elementType) { 34 super(element, elementType); 35 } 36 37 public Object instantiate() { 38 String fontName = null; int fontSize = 12; 40 int fontStyle = Font.PLAIN; 41 42 44 String attrValue = getAttributeNSOptional(Namespace.JDNC, Attributes.NAME); 45 if (attrValue.length() == 0) { 46 Scribe.getLogger().warning("Font has no name attribute defined, default to \"Default\""); 47 } else { 48 fontName = attrValue; 49 } 50 attrValue = getAttributeNSOptional(Namespace.JDNC, Attributes.SIZE); 51 if (attrValue.length() == 0) { 52 Scribe.getLogger().warning("Font has no size attribute defined, default to 12"); 53 } else { 54 fontSize = Integer.parseInt(attrValue); 55 } 56 attrValue = getAttributeNSOptional(Namespace.JDNC, Attributes.STYLE); 57 if (attrValue.length() > 0) { 58 fontStyle = Decoder.decodeFontStyle(attrValue); 59 } 60 61 return new Font (fontName, fontStyle, fontSize); 62 } 63 64 protected Map registerAttributeHandlers() { 65 Map handlerMap = super.registerAttributeHandlers(); 66 if (handlerMap != null) { 67 handlerMap.put(Namespace.JDNC + ":" + Attributes.ID, 69 NullAttribute.idHandler); 70 handlerMap.put(Namespace.JDNC + ":" + Attributes.NAME, 71 nameHandler); 72 handlerMap.put(Namespace.JDNC + ":" + Attributes.SIZE, 73 sizeHandler); 74 handlerMap.put(Namespace.JDNC + ":" + Attributes.STYLE, 75 styleHandler); 76 } 77 return handlerMap; 78 } 79 80 private static final AttributeHandler nameHandler = 81 new AttributeHandler(Namespace.JDNC, Attributes.NAME, NullAttribute.nullApplier); 82 83 private static final AttributeHandler sizeHandler = 84 new AttributeHandler(Namespace.JDNC, Attributes.SIZE, NullAttribute.nullApplier); 85 86 private static final AttributeHandler styleHandler = 87 new AttributeHandler(Namespace.JDNC, Attributes.STYLE, NullAttribute.nullApplier); 88 89 protected Map getAttributeHandlerMap() { 90 return attrMap; 91 } 92 93 } 94 | Popular Tags |