1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.util.Hashtable ; 11 import java.util.Map ; 12 13 import org.w3c.dom.Element ; 14 15 import net.openmarkup.AttributeHandler; 16 import net.openmarkup.ElementAssimilator; 17 import net.openmarkup.ElementHandler; 18 import net.openmarkup.ElementType; 19 import net.openmarkup.Realizable; 20 21 import org.jdesktop.jdnc.markup.Attributes; 22 import org.jdesktop.jdnc.markup.ElementTypes; 23 import org.jdesktop.jdnc.markup.Namespace; 24 import org.jdesktop.jdnc.markup.attr.ComponentAttributes; 25 26 import org.jdesktop.jdnc.JNComponent; 27 28 import javax.swing.JPopupMenu ; 29 30 34 public class ComponentElement extends ElementProxy { 35 private static final Map attrMap = new Hashtable (); 36 private static final Map elementMap = new Hashtable (); 37 38 public ComponentElement(Element element, ElementType elementType) { 39 super(element, elementType); 40 } 41 42 protected Map getAttributeHandlerMap() { 43 return attrMap; 44 } 45 46 protected Map getElementHandlerMap() { 47 return elementMap; 48 } 49 50 protected void applyAttributesAfter() { 51 super.applyAttributesAfter(); 52 applyAttribute(Namespace.JDNC, Attributes.BACKGROUND); 53 applyAttribute(Namespace.JDNC, Attributes.FOREGROUND); 54 applyAttribute(Namespace.JDNC, Attributes.FONT); 55 applyAttribute(Namespace.JDNC, Attributes.IS_ENABLED); 56 applyAttribute(Namespace.JDNC, Attributes.IS_VISIBLE); 57 applyAttribute(Namespace.JDNC, Attributes.NAME); 58 } 59 60 protected Map registerAttributeHandlers() { 61 Map handlerMap = super.registerAttributeHandlers(); 62 if (handlerMap != null) { 63 handlerMap.put(Namespace.JDNC + ":" + Attributes.BACKGROUND, backgroundHandler); 64 handlerMap.put(Namespace.JDNC + ":" + Attributes.FOREGROUND, foregroundHandler); 65 handlerMap.put(Namespace.JDNC + ":" + Attributes.FONT, fontHandler); 66 handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_ENABLED, isEnabledHandler); 67 handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_VISIBLE, isVisibleHandler); 68 handlerMap.put(Namespace.JDNC + ":" + Attributes.NAME, nameHandler); 69 } 70 return handlerMap; 71 } 72 73 protected Map registerElementHandlers() { 74 Map handlerMap = super.registerElementHandlers(); 75 if (handlerMap != null) { 76 handlerMap.put(Namespace.JDNC + ":" + ElementTypes.POPUPMENU.getLocalName(), 77 popupElementHandler); 78 } 79 return handlerMap; 80 } 81 82 public static final ElementAssimilator popupAssimilator = new ElementAssimilator() { 83 public void assimilate(Realizable parent, Realizable child) { 84 JNComponent comp = (JNComponent)parent.getObject(); 85 JPopupMenu popup = (JPopupMenu )child.getObject(); 86 comp.setPopupMenu(popup); 87 } 88 }; 89 90 protected static final ElementHandler popupElementHandler = 91 new ElementHandler(ElementTypes.POPUPMENU, ComponentElement.popupAssimilator); 92 93 94 private static final AttributeHandler backgroundHandler = 95 new AttributeHandler(Namespace.JDNC, Attributes.BACKGROUND, 96 ComponentAttributes.backgroundApplier); 97 98 private static final AttributeHandler foregroundHandler = 99 new AttributeHandler(Namespace.JDNC, Attributes.FOREGROUND, 100 ComponentAttributes.foregroundApplier); 101 102 private static final AttributeHandler fontHandler = 103 new AttributeHandler(Namespace.JDNC, Attributes.FONT, 104 ComponentAttributes.fontApplier); 105 106 private static final AttributeHandler isEnabledHandler = 107 new AttributeHandler(Namespace.JDNC, Attributes.IS_ENABLED, 108 ComponentAttributes.isEnabledApplier); 109 110 private static final AttributeHandler isVisibleHandler = 111 new AttributeHandler(Namespace.JDNC, Attributes.IS_VISIBLE, 112 ComponentAttributes.isVisibleApplier); 113 114 private static final AttributeHandler nameHandler = 115 new AttributeHandler(Namespace.JDNC, Attributes.NAME, ComponentAttributes.nameApplier); 116 } 117 | Popular Tags |