1 7 8 package org.jdesktop.swing.actions; 9 10 import javax.swing.AbstractAction ; 11 import javax.swing.Action ; 12 import javax.swing.Icon ; 13 import javax.swing.KeyStroke ; 14 15 22 public class ActionFactory { 23 24 27 public static BoundAction createBoundAction(String id, String name, 28 String mnemonic) { 29 return createBoundAction(id, name, mnemonic, false); 30 } 31 32 public static BoundAction createBoundAction(String id, String name, 33 String mnemonic, boolean toggle) { 34 return createBoundAction(id, name, mnemonic, toggle, null); 35 } 36 37 38 public static BoundAction createBoundAction(String id, String name, 39 String mnemonic, boolean toggle, 40 String group) { 41 return (BoundAction)configureAction(new BoundAction(name, id), 42 mnemonic, toggle, group); 43 } 44 45 49 public static CompositeAction createCompositeAction(String id, String name, 50 String mnemonic) { 51 return createCompositeAction(id, name, mnemonic, false); 52 } 53 54 public static CompositeAction createCompositeAction(String id, String name, 55 String mnemonic, boolean toggle) { 56 return createCompositeAction(id, name, mnemonic, toggle, null); 57 } 58 59 public static CompositeAction createCompositeAction(String id, String name, 60 String mnemonic, boolean toggle, 61 String group) { 62 return (CompositeAction)configureAction(new CompositeAction(name, id), 63 mnemonic, toggle, group); 64 } 65 66 67 public static ServerAction createServerAction(String id, String name, 68 String mnemonic) { 69 ServerAction action = new ServerAction(name, id); 70 if (mnemonic != null && !mnemonic.equals("")) { 71 action.putValue(Action.MNEMONIC_KEY, new Integer (mnemonic.charAt(0))); 72 } 73 return action; 74 } 75 76 77 80 public static TargetableAction createTargetableAction(String id, String name) { 81 return createTargetableAction(id, name, null); 82 } 83 84 public static TargetableAction createTargetableAction(String id, String name, 85 String mnemonic) { 86 return createTargetableAction(id, name, mnemonic, false); 87 } 88 89 public static TargetableAction createTargetableAction(String id, String name, 90 String mnemonic, boolean toggle) { 91 return createTargetableAction(id, name, mnemonic, toggle, null); 92 } 93 94 public static TargetableAction createTargetableAction(String id, String name, 95 String mnemonic, boolean toggle, 96 String group) { 97 return (TargetableAction)configureAction(new TargetableAction(name, id), 98 mnemonic, toggle, group); 99 } 100 101 private static Action configureAction(AbstractActionExt action, 102 String mnemonic, boolean toggle, 103 String group) { 104 action.setMnemonic(mnemonic); 105 String description = action.getName() + " action with comand " + action.getActionCommand(); 106 action.setShortDescription(description); 107 action.setLongDescription(description); 108 109 if (toggle) { 110 action.setStateAction(); 111 } 112 if (group != null) { 113 action.setGroup(group); 114 } 115 return action; 116 } 117 118 126 public static void decorateAction(AbstractAction action, 127 String shortDesc, String longDesc, 128 Icon smallIcon, Icon largeIcon, 129 KeyStroke accel) { 130 if (action instanceof AbstractActionExt) { 131 AbstractActionExt a = (AbstractActionExt)action; 132 a.setShortDescription(shortDesc); 133 a.setLongDescription(longDesc); 134 a.setSmallIcon(smallIcon); 135 a.setLargeIcon(largeIcon); 136 a.setAccelerator(accel); 137 } 138 else { 139 action.putValue(Action.SHORT_DESCRIPTION, shortDesc); 140 action.putValue(Action.LONG_DESCRIPTION, longDesc); 141 action.putValue(Action.SMALL_ICON, smallIcon); 142 action.putValue(AbstractActionExt.LARGE_ICON, largeIcon); 143 action.putValue(Action.ACCELERATOR_KEY, accel); 144 } 145 } 146 } 147 | Popular Tags |