1 22 23 package org.gjt.sp.jedit; 24 25 import java.util.*; 26 27 40 public abstract class ActionContext 41 { 42 49 public abstract void invokeAction(EventObject evt, EditAction action); 50 52 57 public void addActionSet(ActionSet actionSet) 58 { 59 actionNames = null; 60 actionSets.addElement(actionSet); 61 actionSet.context = this; 62 String [] actions = actionSet.getActionNames(); 63 for(int i = 0; i < actions.length; i++) 64 { 65 66 if (actionHash.containsKey(actions[i])) 67 { 68 69 ActionSet oldAction = actionHash.get(actions[i]); 70 overriddenActions.put(actions[i], oldAction); 71 } 72 actionHash.put(actions[i],actionSet); 73 } 74 } 76 81 public void removeActionSet(ActionSet actionSet) 82 { 83 actionNames = null; 84 actionSets.removeElement(actionSet); 85 actionSet.context = null; 86 String [] actions = actionSet.getActionNames(); 87 for(int i = 0; i < actions.length; i++) 88 { 89 actionHash.remove(actions[i]); 90 if (overriddenActions.containsKey(actions[i])) 91 { 92 ActionSet oldAction = overriddenActions.remove(actions[i]); 93 actionHash.put(actions[i], oldAction); 94 } 95 } 96 } 98 103 public ActionSet[] getActionSets() 104 { 105 ActionSet[] retVal = new ActionSet[actionSets.size()]; 106 actionSets.copyInto(retVal); 107 return retVal; 108 } 110 116 public EditAction getAction(String name) 117 { 118 ActionSet set = (ActionSet)actionHash.get(name); 119 if(set == null) 120 return null; 121 else 122 return set.getAction(name); 123 } 125 132 public ActionSet getActionSetForAction(String action) 133 { 134 return (ActionSet)actionHash.get(action); 135 } 137 141 public String [] getActionNames() 142 { 143 if(actionNames == null) 144 { 145 List vec = new LinkedList(); 146 for(int i = 0; i < actionSets.size(); i++) 147 (actionSets.elementAt(i)).getActionNames(vec); 148 149 actionNames = (String [])vec.toArray( 150 new String [vec.size()]); 151 Arrays.sort(actionNames, 152 new MiscUtilities.StringICaseCompare()); 153 } 154 155 return actionNames; 156 } 158 String [] actionNames; 160 Hashtable<String , ActionSet> actionHash = new Hashtable<String , ActionSet>(); 161 162 163 Hashtable<String , ActionSet> overriddenActions = new Hashtable<String , ActionSet>(); 164 166 private Vector<ActionSet> actionSets = new Vector<ActionSet>(); 168 } 170 | Popular Tags |