< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java

Print this page




 909                     // If the src is in popupMenu,
 910                     // do not forward event to MSM, let component handle it.
 911                     if (isInPopup(src)) {
 912                         break;
 913                     }
 914                 }
 915                 MenuSelectionManager.defaultManager().
 916                     processMouseEvent(me);
 917                 break;
 918             case MouseEvent.MOUSE_WHEEL:
 919                 if (isInPopup(src)
 920                     || ((src instanceof JComboBox) && ((JComboBox) src).isPopupVisible())) {
 921 
 922                     return;
 923                 }
 924                 cancelPopupMenu();
 925                 break;
 926             }
 927         }
 928 

 929         boolean isInPopup(Component src) {
 930             for (Component c=src; c!=null; c=c.getParent()) {
 931                 if (c instanceof Applet || c instanceof Window) {
 932                     break;
 933                 } else if (c instanceof JPopupMenu) {
 934                     return true;
 935                 }
 936             }
 937             return false;
 938         }
 939 
 940         void cancelPopupMenu() {
 941             // We should ungrab window if a user code throws
 942             // an unexpected runtime exception. See 6495920.
 943             try {
 944                 // 4234793: This action should call firePopupMenuCanceled but it's
 945                 // a protected method. The real solution could be to make
 946                 // firePopupMenuCanceled public and call it directly.
 947                 List<JPopupMenu> popups = getPopups();
 948                 for (JPopupMenu popup : popups) {


1126         }
1127 
1128         void removeUIActionMap(JComponent c, ActionMap map) {
1129             ActionMap im = null;
1130             ActionMap parent = c.getActionMap();
1131 
1132             while (parent != null) {
1133                 if (parent == map) {
1134                     if (im == null) {
1135                         c.setActionMap(map.getParent());
1136                     } else {
1137                         im.setParent(map.getParent());
1138                     }
1139                     break;
1140                 }
1141                 im = parent;
1142                 parent = parent.getParent();
1143             }
1144         }
1145 

1146         public void stateChanged(ChangeEvent ev) {
1147             if (!(UIManager.getLookAndFeel() instanceof BasicLookAndFeel)) {
1148                 uninstall();
1149                 return;
1150             }
1151             MenuSelectionManager msm = (MenuSelectionManager)ev.getSource();
1152             MenuElement[] p = msm.getSelectedPath();
1153             JPopupMenu popup = getActivePopup(p);
1154             if (popup != null && !popup.isFocusable()) {
1155                 // Do nothing for non-focusable popups
1156                 return;
1157             }
1158 
1159             if (lastPathSelected.length != 0 && p.length != 0 ) {
1160                 if (!checkInvokerEqual(p[0],lastPathSelected[0])) {
1161                     removeItems();
1162                     lastPathSelected = new MenuElement[0];
1163                 }
1164             }
1165 




 909                     // If the src is in popupMenu,
 910                     // do not forward event to MSM, let component handle it.
 911                     if (isInPopup(src)) {
 912                         break;
 913                     }
 914                 }
 915                 MenuSelectionManager.defaultManager().
 916                     processMouseEvent(me);
 917                 break;
 918             case MouseEvent.MOUSE_WHEEL:
 919                 if (isInPopup(src)
 920                     || ((src instanceof JComboBox) && ((JComboBox) src).isPopupVisible())) {
 921 
 922                     return;
 923                 }
 924                 cancelPopupMenu();
 925                 break;
 926             }
 927         }
 928 
 929         @SuppressWarnings("deprecation")
 930         boolean isInPopup(Component src) {
 931             for (Component c=src; c!=null; c=c.getParent()) {
 932                 if (c instanceof Applet || c instanceof Window) {
 933                     break;
 934                 } else if (c instanceof JPopupMenu) {
 935                     return true;
 936                 }
 937             }
 938             return false;
 939         }
 940 
 941         void cancelPopupMenu() {
 942             // We should ungrab window if a user code throws
 943             // an unexpected runtime exception. See 6495920.
 944             try {
 945                 // 4234793: This action should call firePopupMenuCanceled but it's
 946                 // a protected method. The real solution could be to make
 947                 // firePopupMenuCanceled public and call it directly.
 948                 List<JPopupMenu> popups = getPopups();
 949                 for (JPopupMenu popup : popups) {


1127         }
1128 
1129         void removeUIActionMap(JComponent c, ActionMap map) {
1130             ActionMap im = null;
1131             ActionMap parent = c.getActionMap();
1132 
1133             while (parent != null) {
1134                 if (parent == map) {
1135                     if (im == null) {
1136                         c.setActionMap(map.getParent());
1137                     } else {
1138                         im.setParent(map.getParent());
1139                     }
1140                     break;
1141                 }
1142                 im = parent;
1143                 parent = parent.getParent();
1144             }
1145         }
1146 
1147         @SuppressWarnings("deprecation")
1148         public void stateChanged(ChangeEvent ev) {
1149             if (!(UIManager.getLookAndFeel() instanceof BasicLookAndFeel)) {
1150                 uninstall();
1151                 return;
1152             }
1153             MenuSelectionManager msm = (MenuSelectionManager)ev.getSource();
1154             MenuElement[] p = msm.getSelectedPath();
1155             JPopupMenu popup = getActivePopup(p);
1156             if (popup != null && !popup.isFocusable()) {
1157                 // Do nothing for non-focusable popups
1158                 return;
1159             }
1160 
1161             if (lastPathSelected.length != 0 && p.length != 0 ) {
1162                 if (!checkInvokerEqual(p[0],lastPathSelected[0])) {
1163                     removeItems();
1164                     lastPathSelected = new MenuElement[0];
1165                 }
1166             }
1167 


< prev index next >