提交 faf9c616 编写于 作者: A alexp

4833524: BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers

Reviewed-by: rupashka
上级 e5c72fdd
...@@ -1766,7 +1766,7 @@ public class BasicComboBoxUI extends ComboBoxUI { ...@@ -1766,7 +1766,7 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
private boolean isTypeAheadKey( KeyEvent e ) { private boolean isTypeAheadKey( KeyEvent e ) {
return !e.isAltDown() && !e.isControlDown() && !e.isMetaDown(); return !e.isAltDown() && !BasicGraphicsUtils.isMenuShortcutKeyDown(e);
} }
// //
......
...@@ -483,11 +483,12 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup { ...@@ -483,11 +483,12 @@ public class BasicComboPopup extends JPopupMenu implements ComboPopup {
protected JList createList() { protected JList createList() {
return new JList( comboBox.getModel() ) { return new JList( comboBox.getModel() ) {
public void processMouseEvent(MouseEvent e) { public void processMouseEvent(MouseEvent e) {
if (e.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
// Fix for 4234053. Filter out the Control Key from the list. // Fix for 4234053. Filter out the Control Key from the list.
// ie., don't allow CTRL key deselection. // ie., don't allow CTRL key deselection.
Toolkit toolkit = Toolkit.getDefaultToolkit();
e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(), e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(),
e.getModifiers() ^ InputEvent.CTRL_MASK, e.getModifiers() ^ toolkit.getMenuShortcutKeyMask(),
e.getX(), e.getY(), e.getX(), e.getY(),
e.getXOnScreen(), e.getYOnScreen(), e.getXOnScreen(), e.getYOnScreen(),
e.getClickCount(), e.getClickCount(),
......
...@@ -924,7 +924,8 @@ public class BasicFileChooserUI extends FileChooserUI { ...@@ -924,7 +924,8 @@ public class BasicFileChooserUI extends FileChooserUI {
boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile)); boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled(); boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
boolean isFileSelEnabled = chooser.isFileSelectionEnabled(); 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)) { if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
changeDirectory(selectedFile); changeDirectory(selectedFile);
......
...@@ -33,7 +33,10 @@ import java.awt.FontMetrics; ...@@ -33,7 +33,10 @@ import java.awt.FontMetrics;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
...@@ -303,4 +306,9 @@ public class BasicGraphicsUtils ...@@ -303,4 +306,9 @@ public class BasicGraphicsUtils
static boolean isLeftToRight( Component c ) { static boolean isLeftToRight( Component c ) {
return c.getComponentOrientation().isLeftToRight(); return c.getComponentOrientation().isLeftToRight();
} }
static boolean isMenuShortcutKeyDown(InputEvent event) {
return (event.getModifiers() &
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
}
} }
...@@ -2371,8 +2371,9 @@ public class BasicListUI extends ListUI ...@@ -2371,8 +2371,9 @@ public class BasicListUI extends ListUI
JList src = (JList)e.getSource(); JList src = (JList)e.getSource();
ListModel model = src.getModel(); ListModel model = src.getModel();
if (model.getSize() == 0 || e.isAltDown() || e.isControlDown() || e.isMetaDown() || if (model.getSize() == 0 || e.isAltDown() ||
isNavigationKey(e)) { BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
isNavigationKey(e)) {
// Nothing to select // Nothing to select
return; return;
} }
...@@ -2665,7 +2666,7 @@ public class BasicListUI extends ListUI ...@@ -2665,7 +2666,7 @@ public class BasicListUI extends ListUI
if (row != -1 && DragRecognitionSupport.mousePressed(e)) { if (row != -1 && DragRecognitionSupport.mousePressed(e)) {
dragPressDidSelection = false; dragPressDidSelection = false;
if (e.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
// do nothing for control - will be handled on release // do nothing for control - will be handled on release
// or when drag starts // or when drag starts
return; return;
...@@ -2717,7 +2718,7 @@ public class BasicListUI extends ListUI ...@@ -2717,7 +2718,7 @@ public class BasicListUI extends ListUI
anchorSelected = list.isSelectedIndex(anchorIndex); anchorSelected = list.isSelectedIndex(anchorIndex);
} }
if (e.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
if (e.isShiftDown()) { if (e.isShiftDown()) {
if (anchorSelected) { if (anchorSelected) {
list.addSelectionInterval(anchorIndex, row); list.addSelectionInterval(anchorIndex, row);
...@@ -2742,7 +2743,7 @@ public class BasicListUI extends ListUI ...@@ -2742,7 +2743,7 @@ public class BasicListUI extends ListUI
} }
public void dragStarting(MouseEvent me) { public void dragStarting(MouseEvent me) {
if (me.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
int row = SwingUtilities2.loc2IndexFileList(list, me.getPoint()); int row = SwingUtilities2.loc2IndexFileList(list, me.getPoint());
list.addSelectionInterval(row, row); list.addSelectionInterval(row, row);
} }
...@@ -2758,7 +2759,7 @@ public class BasicListUI extends ListUI ...@@ -2758,7 +2759,7 @@ public class BasicListUI extends ListUI
return; return;
} }
if (e.isShiftDown() || e.isControlDown()) { if (e.isShiftDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
return; return;
} }
......
...@@ -1027,7 +1027,7 @@ public class BasicTableUI extends TableUI ...@@ -1027,7 +1027,7 @@ public class BasicTableUI extends TableUI
shouldStartTimer = shouldStartTimer =
table.isCellSelected(pressedRow, pressedCol) && table.isCellSelected(pressedRow, pressedCol) &&
!e.isShiftDown() && !e.isShiftDown() &&
!e.isControlDown() && !BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
!outsidePrefSize; !outsidePrefSize;
} }
...@@ -1051,7 +1051,7 @@ public class BasicTableUI extends TableUI ...@@ -1051,7 +1051,7 @@ public class BasicTableUI extends TableUI
dragPressDidSelection = false; dragPressDidSelection = false;
if (e.isControlDown() && isFileList) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(e) && isFileList) {
// do nothing for control - will be handled on release // do nothing for control - will be handled on release
// or when drag starts // or when drag starts
return; return;
...@@ -1115,7 +1115,9 @@ public class BasicTableUI extends TableUI ...@@ -1115,7 +1115,9 @@ public class BasicTableUI extends TableUI
CellEditor editor = table.getCellEditor(); CellEditor editor = table.getCellEditor();
if (dragEnabled || editor == null || editor.shouldSelectCell(e)) { 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 class BasicTableUI extends TableUI ...@@ -1212,7 +1214,7 @@ public class BasicTableUI extends TableUI
public void dragStarting(MouseEvent me) { public void dragStarting(MouseEvent me) {
dragStarted = true; dragStarted = true;
if (me.isControlDown() && isFileList) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(me) && isFileList) {
table.getSelectionModel().addSelectionInterval(pressedRow, table.getSelectionModel().addSelectionInterval(pressedRow,
pressedRow); pressedRow);
table.getColumnModel().getSelectionModel(). table.getColumnModel().getSelectionModel().
...@@ -1251,7 +1253,8 @@ public class BasicTableUI extends TableUI ...@@ -1251,7 +1253,8 @@ public class BasicTableUI extends TableUI
return; return;
} }
table.changeSelection(row, column, e.isControlDown(), true); table.changeSelection(row, column,
BasicGraphicsUtils.isMenuShortcutKeyDown(e), true);
} }
......
...@@ -2265,7 +2265,7 @@ public class BasicTreeUI extends TreeUI ...@@ -2265,7 +2265,7 @@ public class BasicTreeUI extends TreeUI
*/ */
protected boolean isToggleSelectionEvent(MouseEvent event) { protected boolean isToggleSelectionEvent(MouseEvent event) {
return (SwingUtilities.isLeftMouseButton(event) && return (SwingUtilities.isLeftMouseButton(event) &&
event.isControlDown()); BasicGraphicsUtils.isMenuShortcutKeyDown(event));
} }
/** /**
...@@ -3255,7 +3255,7 @@ public class BasicTreeUI extends TreeUI ...@@ -3255,7 +3255,7 @@ public class BasicTreeUI extends TreeUI
// handle first letter navigation // handle first letter navigation
if(tree != null && tree.getRowCount()>0 && tree.hasFocus() && if(tree != null && tree.getRowCount()>0 && tree.hasFocus() &&
tree.isEnabled()) { tree.isEnabled()) {
if (e.isAltDown() || e.isControlDown() || e.isMetaDown() || if (e.isAltDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e) ||
isNavigationKey(e)) { isNavigationKey(e)) {
return; return;
} }
...@@ -3511,7 +3511,7 @@ public class BasicTreeUI extends TreeUI ...@@ -3511,7 +3511,7 @@ public class BasicTreeUI extends TreeUI
dragPressDidSelection = false; dragPressDidSelection = false;
if (e.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
// do nothing for control - will be handled on release // do nothing for control - will be handled on release
// or when drag starts // or when drag starts
return; return;
...@@ -3565,7 +3565,7 @@ public class BasicTreeUI extends TreeUI ...@@ -3565,7 +3565,7 @@ public class BasicTreeUI extends TreeUI
public void dragStarting(MouseEvent me) { public void dragStarting(MouseEvent me) {
dragStarted = true; dragStarted = true;
if (me.isControlDown()) { if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
tree.addSelectionPath(pressedPath); tree.addSelectionPath(pressedPath);
setAnchorSelectionPath(pressedPath); setAnchorSelectionPath(pressedPath);
setLeadSelectionPath(pressedPath, true); setLeadSelectionPath(pressedPath, true);
......
...@@ -510,7 +510,7 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou ...@@ -510,7 +510,7 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 && if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 &&
getDot() != -1) { getDot() != -1) {
moveCaret(e); moveCaret(e);
} else { } else if (!e.isPopupTrigger()) {
positionCaret(e); positionCaret(e);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册