1 19 package org.openide.windows; 20 21 import javax.swing.Action ; 22 import javax.swing.ActionMap ; 23 import javax.swing.JComponent ; 24 25 26 28 35 final class DelegateActionMap extends ActionMap { 36 private JComponent component; 37 private ActionMap delegate; 38 39 public DelegateActionMap(JComponent c) { 40 this.component = c; 41 } 42 43 public DelegateActionMap(TopComponent c, ActionMap delegate) { 44 this.component = c; 45 this.delegate = delegate; 46 } 47 48 public int size() { 49 return keys().length; 50 } 51 52 public Action get(Object key) { 53 javax.swing.ActionMap m = (delegate == null) ? component.getActionMap() : delegate; 54 55 if (m != null) { 56 Action a = m.get(key); 57 58 if (a != null) { 59 return a; 60 } 61 } 62 63 java.awt.Component owner = java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 64 Action found = null; 65 66 while ((owner != null) && (owner != component)) { 67 if ((found == null) && (owner instanceof JComponent )) { 68 m = ((JComponent ) owner).getActionMap(); 69 70 if (m != null) { 71 found = m.get(key); 72 } 73 } 74 75 owner = owner.getParent(); 76 } 77 78 return (owner == component) ? found : null; 79 } 80 81 public Object [] allKeys() { 82 return keys(true); 83 } 84 85 public Object [] keys() { 86 return keys(false); 87 } 88 89 private Object [] keys(boolean all) { 90 java.util.Set <Object > keys = new java.util.HashSet <Object >(); 91 92 javax.swing.ActionMap m = (delegate == null) ? component.getActionMap() : delegate; 93 94 if (m != null) { 95 java.util.List <Object > l; 96 97 if (all) { 98 l = java.util.Arrays.asList(m.allKeys()); 99 } else { 100 l = java.util.Arrays.asList(m.keys()); 101 } 102 103 keys.addAll(l); 104 } 105 106 return keys.toArray(); 107 } 108 109 public void remove(Object key) { 113 if (delegate != null) { 114 delegate.remove(key); 115 } 116 } 117 118 public void setParent(ActionMap map) { 119 if (delegate != null) { 120 delegate.setParent(map); 121 } 122 } 123 124 public void clear() { 125 if (delegate != null) { 126 delegate.clear(); 127 } 128 } 129 130 public void put(Object key, Action action) { 131 if (delegate != null) { 132 delegate.put(key, action); 133 } 134 } 135 136 public ActionMap getParent() { 137 return (delegate == null) ? null : delegate.getParent(); 138 } 139 140 public String toString() { 141 return super.toString() + " for " + this.component; 142 } 143 } 144 | Popular Tags |