1 43 44 package org.jfree.ui.action; 45 46 import java.util.ArrayList ; 47 import java.util.HashMap ; 48 49 import javax.swing.Action ; 50 51 62 public class DowngradeActionMap { 63 64 65 private final HashMap actionMap; 66 67 68 private final ArrayList actionList; 69 70 71 private DowngradeActionMap parent; 72 73 76 public DowngradeActionMap() { 77 this.actionMap = new HashMap (); 78 this.actionList = new ArrayList (); 79 } 80 81 86 public void setParent(final DowngradeActionMap map) { 87 this.parent = map; 88 } 89 90 96 public DowngradeActionMap getParent() { 97 return this.parent; 98 } 99 100 110 public void put(final Object key, final Action action) { 111 if (action == null) { 112 remove(key); 113 } 114 else { 115 if (this.actionMap.containsKey(key)) { 116 remove(key); 117 } 118 this.actionMap.put(key, action); 119 this.actionList.add (key); 120 } 121 } 122 123 130 public Action get(final Object key) { 131 final Action retval = (Action ) this.actionMap.get(key); 132 if (retval != null) { 133 return retval; 134 } 135 if (this.parent != null) { 136 return this.parent.get(key); 137 } 138 return null; 139 } 140 141 146 public void remove(final Object key) { 147 this.actionMap.remove(key); 148 this.actionList.remove(key); 149 } 150 151 154 public void clear() { 155 this.actionMap.clear(); 156 this.actionList.clear(); 157 } 158 159 164 public Object [] keys() { 165 return this.actionList.toArray(); 166 } 167 168 173 public int size() { 174 return this.actionMap.size(); 175 } 176 177 184 public Object [] allKeys() { 185 if (this.parent == null) { 186 return keys(); 187 } 188 final Object [] parentKeys = this.parent.allKeys(); 189 final Object [] key = keys(); 190 final Object [] retval = new Object [parentKeys.length + key.length]; 191 System.arraycopy(key, 0, retval, 0, key.length); 192 System.arraycopy(retval, 0, retval, key.length, retval.length); 193 return retval; 194 } 195 196 } 197 | Popular Tags |