1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.util.Hashtable ; 11 import java.util.Map ; 12 13 import javax.swing.Action ; 14 15 import org.w3c.dom.Element ; 16 import org.jdesktop.swing.Application; 17 import org.jdesktop.swing.actions.ActionManager; 18 import org.jdesktop.jdnc.markup.Attributes; 19 import org.jdesktop.jdnc.markup.Namespace; 20 import org.jdesktop.jdnc.markup.RealizationUtils; 21 import org.jdesktop.jdnc.markup.attr.ActionAttributes; 22 import org.jdesktop.jdnc.markup.attr.NullAttribute; 23 import net.openmarkup.AttributeHandler; 24 import net.openmarkup.ElementType; 25 26 31 public class ActionElement 32 extends ElementProxy { 33 private static final Map attrMap = new Hashtable (); 34 35 public ActionElement(Element element, ElementType elementType) { 36 super(element, elementType); 37 } 38 39 protected Object instantiate() { 40 Action action; 41 String id = this.getAttributeNSOptional(Namespace.JDNC, 42 Attributes.ACTION_REF); 43 if (id.length() > 0) { 44 action = (Action ) RealizationUtils.getReferencedObject(this, id); 46 if (action == null) { 47 throw new RuntimeException (id + " action not found"); 48 } 49 } 50 else { 51 action = (Action )super.instantiate(); 52 53 id = this.getAttribute("xml:id"); 55 if (id.equals("")) { 56 id = (String ) action.getValue(Action.NAME); 58 } 59 60 69 70 ActionManager manager = Application.getInstance().getActionManager(); 71 action.putValue(Action.ACTION_COMMAND_KEY, id); 72 manager.addAction(action); 73 } 74 return action; 75 } 76 77 protected void applyAttributesAfter() { 78 super.applyAttributesAfter(); 79 applyAttribute(Namespace.JDNC, Attributes.DELEGATE); 80 applyAttribute(Namespace.JDNC, Attributes.IS_TOGGLE); 82 applyAttribute(Namespace.JDNC, Attributes.GROUP); 83 applyAttribute(Namespace.JDNC, Attributes.TITLE); 84 applyAttribute(Namespace.JDNC, Attributes.MNEMONIC); 85 applyAttribute(Namespace.JDNC, Attributes.ICON); 86 applyAttribute(Namespace.JDNC, Attributes.SMALL_ICON); 87 applyAttribute(Namespace.JDNC, Attributes.ACCELERATOR); 88 applyAttribute(Namespace.JDNC, Attributes.DESCRIPTION); 89 } 90 91 protected Map registerAttributeHandlers() { 92 Map handlerMap = super.registerAttributeHandlers(); 93 if (handlerMap != null) { 94 handlerMap.put(Namespace.JDNC + ":" + Attributes.DELEGATE, 95 delegateHandler); 96 handlerMap.put(Namespace.JDNC + ":" + Attributes.IS_TOGGLE, 98 toggleHandler); 99 handlerMap.put(Namespace.JDNC + ":" + Attributes.GROUP, 100 groupHandler); 101 handlerMap.put(Namespace.JDNC + ":" + Attributes.TITLE, 102 titleHandler); 103 handlerMap.put(Namespace.JDNC + ":" + Attributes.MNEMONIC, 104 mnemonicHandler); 105 handlerMap.put(Namespace.JDNC + ":" + Attributes.ICON, iconHandler); 106 handlerMap.put(Namespace.JDNC + ":" + Attributes.SMALL_ICON, 107 smallIconHandler); 108 handlerMap.put(Namespace.JDNC + ":" + Attributes.ACCELERATOR, 109 acceleratorHandler); 110 handlerMap.put(Namespace.JDNC + ":" + Attributes.DESCRIPTION, 111 descriptionHandler); 112 handlerMap.put(Namespace.JDNC + ":" + Attributes.ID, 115 NullAttribute.idHandler); 116 handlerMap.put(Namespace.JDNC + ":" + Attributes.ACTION_REF, 117 actionRefHandler); 118 119 } 120 121 return handlerMap; 122 } 123 124 protected Map getAttributeHandlerMap() { 125 return attrMap; 126 } 127 128 private static final AttributeHandler delegateHandler = 129 new AttributeHandler(Namespace.JDNC, Attributes.DELEGATE, 130 ActionAttributes.delegateApplier); 131 private static final AttributeHandler actionRefHandler = 132 new AttributeHandler(Namespace.JDNC, Attributes.ACTION_REF, 133 NullAttribute.nullApplier); 134 private static final AttributeHandler toggleHandler = 135 new AttributeHandler(Namespace.JDNC, Attributes.IS_TOGGLE, 136 ActionAttributes.isToggleApplier); 137 private static final AttributeHandler groupHandler = 138 new AttributeHandler(Namespace.JDNC, Attributes.GROUP, 139 ActionAttributes.groupApplier); 140 private static final AttributeHandler titleHandler = 141 new AttributeHandler(Namespace.JDNC, Attributes.TITLE, 142 ActionAttributes.titleApplier); 143 private static final AttributeHandler mnemonicHandler = 144 new AttributeHandler(Namespace.JDNC, Attributes.MNEMONIC, 145 ActionAttributes.mnemonicApplier); 146 private static final AttributeHandler iconHandler = 147 new AttributeHandler(Namespace.JDNC, Attributes.ICON, 148 ActionAttributes.iconApplier); 149 private static final AttributeHandler smallIconHandler = 150 new AttributeHandler(Namespace.JDNC, Attributes.SMALL_ICON, 151 ActionAttributes.smallIconApplier); 152 private static final AttributeHandler acceleratorHandler = 153 new AttributeHandler(Namespace.JDNC, Attributes.ACCELERATOR, 154 ActionAttributes.acceleratorApplier); 155 private static final AttributeHandler descriptionHandler = 156 new AttributeHandler(Namespace.JDNC, Attributes.DESCRIPTION, 157 ActionAttributes.descriptionApplier); 158 } 159 | Popular Tags |