1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import java.net.URL ; 11 12 import javax.swing.Action ; 13 import javax.swing.Icon ; 14 import javax.swing.ImageIcon ; 15 import javax.swing.KeyStroke ; 16 17 import org.jdesktop.swing.Application; 18 import org.jdesktop.swing.actions.AbstractActionExt; 19 20 import net.openmarkup.ApplierException; 21 import net.openmarkup.AttributeApplier; 22 import net.openmarkup.Realizable; 23 import net.openmarkup.Scribe; 24 25 31 public class ActionAttributes { 32 42 public static final AttributeApplier titleApplier = new AttributeApplier() { 43 public void apply(Realizable target, String namespaceURI, 44 String attributeName, String attributeValue) throws 45 ApplierException { 46 Action action = (Action ) target.getObject(); 47 action.putValue(Action.NAME, attributeValue); 48 } 49 }; 50 51 public static final AttributeApplier isToggleApplier = new AttributeApplier() { 52 public void apply(Realizable target, String namespaceURI, 53 String attributeName, String attributeValue) throws 54 ApplierException { 55 AbstractActionExt action = (AbstractActionExt) target.getObject(); 56 action.setStateAction(Boolean.valueOf(attributeValue).booleanValue()); 57 } 58 }; 59 60 public static final AttributeApplier groupApplier = new AttributeApplier() { 61 public void apply(Realizable target, String namespaceURI, 62 String attributeName, String attributeValue) throws 63 ApplierException { 64 AbstractActionExt action = (AbstractActionExt) target.getObject(); 65 action.setGroup(attributeValue); 66 } 67 }; 68 69 public static final AttributeApplier mnemonicApplier = new AttributeApplier() { 70 public void apply(Realizable target, String namespaceURI, 71 String attributeName, String attributeValue) throws 72 ApplierException { 73 Action action = (Action ) target.getObject(); 74 action.putValue(Action.MNEMONIC_KEY, 75 new Integer (attributeValue.charAt(0))); 76 } 77 }; 78 79 public static final AttributeApplier iconApplier = new AttributeApplier() { 80 public void apply(Realizable target, String namespaceURI, 81 String attributeName, String attributeValue) throws 82 ApplierException { 83 Action action = (Action ) target.getObject(); 84 85 Icon icon = ActionAttributes.getIcon(target, attributeValue); 86 action.putValue(AbstractActionExt.LARGE_ICON, icon); 87 } 88 }; 89 90 public static Icon getIcon(Realizable target, String uri) { 93 URL url = ActionAttributes.class.getResource(uri); 94 if (url == null) { 95 url = target.getResolvedURL(uri); 96 } 97 Icon icon = null; 98 try { 99 url.openStream(); 101 icon = new ImageIcon (url); 103 } 104 catch (Exception ex) { 105 Scribe.getLogger().warning("Error getting icon: " + url.toExternalForm()); 106 icon = Application.getIcon(uri, (Action ) target.getObject()); 112 } 113 return icon; 114 } 115 116 public static final AttributeApplier smallIconApplier = new 117 AttributeApplier() { 118 public void apply(Realizable target, String namespaceURI, 119 String attributeName, String attributeValue) throws 120 ApplierException { 121 Action action = (Action ) target.getObject(); 122 action.putValue(Action.SMALL_ICON, 123 ActionAttributes.getIcon(target, attributeValue)); 124 } 125 }; 126 127 public static final AttributeApplier acceleratorApplier = new 128 AttributeApplier() { 129 public void apply(Realizable target, String namespaceURI, 130 String attributeName, String attributeValue) throws 131 ApplierException { 132 Action action = (Action ) target.getObject(); 133 action.putValue(Action.ACCELERATOR_KEY, 134 KeyStroke.getKeyStroke(attributeValue)); 135 } 136 }; 137 138 public static final AttributeApplier descriptionApplier = new 139 AttributeApplier() { 140 public void apply(Realizable target, String namespaceURI, 141 String attributeName, String attributeValue) throws 142 ApplierException { 143 Action action = (Action ) target.getObject(); 144 action.putValue(Action.SHORT_DESCRIPTION, attributeValue); 145 action.putValue(Action.LONG_DESCRIPTION, attributeValue); 147 } 148 }; 149 150 public static final AttributeApplier delegateApplier = new AttributeApplier() { 152 public void apply(Realizable target, String namespaceURI, 153 String attributeName, String attributeValue) throws 154 ApplierException { 155 Action action = (Action ) target.getObject(); 156 Object delegate = BaseAttribute.getReferencedObject(target, 157 attributeValue); 158 action.putValue("delegate", delegate); 159 } 160 }; 161 } 162 | Popular Tags |