changeset 1958:481c01572c62

4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers Reviewed-by: rupashka
author alexp
date Thu, 17 Sep 2009 19:08:15 +0400
parents a64dbe61a984
children 1c7abc800502
files src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java src/share/classes/javax/swing/plaf/basic/BasicListUI.java src/share/classes/javax/swing/plaf/basic/BasicTableUI.java src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java src/share/classes/javax/swing/text/DefaultCaret.java
diffstat 8 files changed, 34 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java	Thu Sep 17 19:08:15 2009 +0400
@@ -1766,7 +1766,7 @@
         }
 
         private boolean isTypeAheadKey( KeyEvent e ) {
-            return !e.isAltDown() && !e.isControlDown() && !e.isMetaDown();
+            return !e.isAltDown() && !BasicGraphicsUtils.isMenuShortcutKeyDown(e);
         }
 
         //
--- a/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicComboPopup.java	Thu Sep 17 19:08:15 2009 +0400
@@ -483,11 +483,12 @@
     protected JList createList() {
         return new JList( comboBox.getModel() ) {
             public void processMouseEvent(MouseEvent e)  {
-                if (e.isControlDown())  {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e))  {
                     // Fix for 4234053. Filter out the Control Key from the list.
                     // ie., don't allow CTRL key deselection.
+                    Toolkit toolkit = Toolkit.getDefaultToolkit();
                     e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
-                                       e.getModifiers() ^ InputEvent.CTRL_MASK,
+                                       e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
                                        e.getX(), e.getY(),
                                        e.getXOnScreen(), e.getYOnScreen(),
                                        e.getClickCount(),
--- a/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicFileChooserUI.java	Thu Sep 17 19:08:15 2009 +0400
@@ -924,7 +924,8 @@
                 boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
                 boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
                 boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
-                boolean isCtrl = (e != null && (e.getModifiers() & ActionEvent.CTRL_MASK) != 0);
+                boolean isCtrl = (e != null && (e.getModifiers() &
+                            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);
 
                 if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
                     changeDirectory(selectedFile);
--- a/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicGraphicsUtils.java	Thu Sep 17 19:08:15 2009 +0400
@@ -33,7 +33,10 @@
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
+import java.awt.Toolkit;
 import java.awt.event.KeyEvent;
+import java.awt.event.InputEvent;
+
 import sun.swing.SwingUtilities2;
 
 
@@ -303,4 +306,9 @@
     static boolean isLeftToRight( Component c ) {
         return c.getComponentOrientation().isLeftToRight();
     }
+
+    static boolean isMenuShortcutKeyDown(InputEvent event) {
+        return (event.getModifiers() &
+                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
+    }
 }
--- a/src/share/classes/javax/swing/plaf/basic/BasicListUI.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicListUI.java	Thu Sep 17 19:08:15 2009 +0400
@@ -2371,8 +2371,9 @@
             JList src = (JList)e.getSource();
             ListModel model = src.getModel();
 
-            if (model.getSize() == 0 || e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
-                isNavigationKey(e)) {
+            if (model.getSize() == 0 || e.isAltDown() ||
+                    BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
+                    isNavigationKey(e)) {
                 // Nothing to select
                 return;
             }
@@ -2665,7 +2666,7 @@
                 if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
                     dragPressDidSelection = false;
 
-                    if (e.isControlDown()) {
+                    if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                         // do nothing for control - will be handled on release
                         // or when drag starts
                         return;
@@ -2717,7 +2718,7 @@
                     anchorSelected = list.isSelectedIndex(anchorIndex);
                 }
 
-                if (e.isControlDown()) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                     if (e.isShiftDown()) {
                         if (anchorSelected) {
                             list.addSelectionInterval(anchorIndex, row);
@@ -2742,7 +2743,7 @@
         }
 
         public void dragStarting(MouseEvent me) {
-            if (me.isControlDown()) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
                 int row = SwingUtilities2.loc2IndexFileList(list, me.getPoint());
                 list.addSelectionInterval(row, row);
             }
@@ -2758,7 +2759,7 @@
                 return;
             }
 
-            if (e.isShiftDown() || e.isControlDown()) {
+            if (e.isShiftDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                 return;
             }
 
--- a/src/share/classes/javax/swing/plaf/basic/BasicTableUI.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicTableUI.java	Thu Sep 17 19:08:15 2009 +0400
@@ -1027,7 +1027,7 @@
                 shouldStartTimer =
                     table.isCellSelected(pressedRow, pressedCol) &&
                     !e.isShiftDown() &&
-                    !e.isControlDown() &&
+                    !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
                     !outsidePrefSize;
             }
 
@@ -1051,7 +1051,7 @@
 
                 dragPressDidSelection = false;
 
-                if (e.isControlDown() && isFileList) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e) && isFileList) {
                     // do nothing for control - will be handled on release
                     // or when drag starts
                     return;
@@ -1115,7 +1115,9 @@
 
             CellEditor editor = table.getCellEditor();
             if (dragEnabled || editor == null || editor.shouldSelectCell(e)) {
-                table.changeSelection(pressedRow, pressedCol, e.isControlDown(), e.isShiftDown());
+                table.changeSelection(pressedRow, pressedCol,
+                        BasicGraphicsUtils.isMenuShortcutKeyDown(e),
+                        e.isShiftDown());
             }
         }
 
@@ -1212,7 +1214,7 @@
         public void dragStarting(MouseEvent me) {
             dragStarted = true;
 
-            if (me.isControlDown() && isFileList) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me) && isFileList) {
                 table.getSelectionModel().addSelectionInterval(pressedRow,
                                                                pressedRow);
                 table.getColumnModel().getSelectionModel().
@@ -1251,7 +1253,8 @@
                 return;
             }
 
-            table.changeSelection(row, column, e.isControlDown(), true);
+            table.changeSelection(row, column,
+                    BasicGraphicsUtils.isMenuShortcutKeyDown(e), true);
         }
 
 
--- a/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/plaf/basic/BasicTreeUI.java	Thu Sep 17 19:08:15 2009 +0400
@@ -2265,7 +2265,7 @@
      */
     protected boolean isToggleSelectionEvent(MouseEvent event) {
         return (SwingUtilities.isLeftMouseButton(event) &&
-                event.isControlDown());
+                BasicGraphicsUtils.isMenuShortcutKeyDown(event));
     }
 
     /**
@@ -3255,7 +3255,7 @@
             // handle first letter navigation
             if(tree != null && tree.getRowCount()>0 && tree.hasFocus() &&
                tree.isEnabled()) {
-                if (e.isAltDown() || e.isControlDown() || e.isMetaDown() ||
+                if (e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
                     isNavigationKey(e)) {
                     return;
                 }
@@ -3511,7 +3511,7 @@
 
                 dragPressDidSelection = false;
 
-                if (e.isControlDown()) {
+                if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
                     // do nothing for control - will be handled on release
                     // or when drag starts
                     return;
@@ -3565,7 +3565,7 @@
         public void dragStarting(MouseEvent me) {
             dragStarted = true;
 
-            if (me.isControlDown()) {
+            if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
                 tree.addSelectionPath(pressedPath);
                 setAnchorSelectionPath(pressedPath);
                 setLeadSelectionPath(pressedPath, true);
--- a/src/share/classes/javax/swing/text/DefaultCaret.java	Wed Sep 16 16:15:41 2009 +0400
+++ b/src/share/classes/javax/swing/text/DefaultCaret.java	Thu Sep 17 19:08:15 2009 +0400
@@ -510,7 +510,7 @@
         if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 &&
             getDot() != -1) {
             moveCaret(e);
-        } else {
+        } else if (!e.isPopupTrigger()) {
             positionCaret(e);
         }
     }