1040 invokerRootPane.removeKeyListener(this); 1041 invokerRootPane.setFocusTraversalKeysEnabled(focusTraversalKeysEnabled); 1042 removeUIInputMap(invokerRootPane, menuInputMap); 1043 removeUIActionMap(invokerRootPane, menuActionMap); 1044 invokerRootPane = null; 1045 } 1046 receivedKeyPressed = false; 1047 } 1048 1049 private FocusListener rootPaneFocusListener = new FocusAdapter() { 1050 public void focusGained(FocusEvent ev) { 1051 Component opposite = ev.getOppositeComponent(); 1052 if (opposite != null) { 1053 lastFocused = opposite; 1054 } 1055 ev.getComponent().removeFocusListener(this); 1056 } 1057 }; 1058 1059 /** 1060 * Return the last JPopupMenu in <code>path</code>, 1061 * or <code>null</code> if none found 1062 */ 1063 JPopupMenu getActivePopup(MenuElement[] path) { 1064 for (int i=path.length-1; i>=0; i--) { 1065 MenuElement elem = path[i]; 1066 if (elem instanceof JPopupMenu) { 1067 return (JPopupMenu)elem; 1068 } 1069 } 1070 return null; 1071 } 1072 1073 void addUIInputMap(JComponent c, InputMap map) { 1074 InputMap lastNonUI = null; 1075 InputMap parent = c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 1076 1077 while (parent != null && !(parent instanceof UIResource)) { 1078 lastNonUI = parent; 1079 parent = parent.getParent(); 1080 } 1081 | 1040 invokerRootPane.removeKeyListener(this); 1041 invokerRootPane.setFocusTraversalKeysEnabled(focusTraversalKeysEnabled); 1042 removeUIInputMap(invokerRootPane, menuInputMap); 1043 removeUIActionMap(invokerRootPane, menuActionMap); 1044 invokerRootPane = null; 1045 } 1046 receivedKeyPressed = false; 1047 } 1048 1049 private FocusListener rootPaneFocusListener = new FocusAdapter() { 1050 public void focusGained(FocusEvent ev) { 1051 Component opposite = ev.getOppositeComponent(); 1052 if (opposite != null) { 1053 lastFocused = opposite; 1054 } 1055 ev.getComponent().removeFocusListener(this); 1056 } 1057 }; 1058 1059 /** 1060 * Return the last JPopupMenu in {@code path}, 1061 * or {@code null} if none found 1062 */ 1063 JPopupMenu getActivePopup(MenuElement[] path) { 1064 for (int i=path.length-1; i>=0; i--) { 1065 MenuElement elem = path[i]; 1066 if (elem instanceof JPopupMenu) { 1067 return (JPopupMenu)elem; 1068 } 1069 } 1070 return null; 1071 } 1072 1073 void addUIInputMap(JComponent c, InputMap map) { 1074 InputMap lastNonUI = null; 1075 InputMap parent = c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); 1076 1077 while (parent != null && !(parent instanceof UIResource)) { 1078 lastNonUI = parent; 1079 parent = parent.getParent(); 1080 } 1081 |