提交 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 {
}
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 {
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(),
......
......@@ -924,7 +924,8 @@ public class BasicFileChooserUI extends FileChooserUI {
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);
......
......@@ -33,7 +33,10 @@ import java.awt.FontMetrics;
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 @@ public class BasicGraphicsUtils
static boolean isLeftToRight( Component c ) {
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
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 @@ public class BasicListUI extends ListUI
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 @@ public class BasicListUI extends ListUI
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 class BasicListUI extends ListUI
}
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 @@ public class BasicListUI extends ListUI
return;
}
if (e.isShiftDown() || e.isControlDown()) {
if (e.isShiftDown() || BasicGraphicsUtils.isMenuShortcutKeyDown(e)) {
return;
}
......
......@@ -1027,7 +1027,7 @@ public class BasicTableUI extends TableUI
shouldStartTimer =
table.isCellSelected(pressedRow, pressedCol) &&
!e.isShiftDown() &&
!e.isControlDown() &&
!BasicGraphicsUtils.isMenuShortcutKeyDown(e) &&
!outsidePrefSize;
}
......@@ -1051,7 +1051,7 @@ public class BasicTableUI extends TableUI
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 @@ public class BasicTableUI extends TableUI
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 class BasicTableUI extends TableUI
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 @@ public class BasicTableUI extends TableUI
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
*/
protected boolean isToggleSelectionEvent(MouseEvent event) {
return (SwingUtilities.isLeftMouseButton(event) &&
event.isControlDown());
BasicGraphicsUtils.isMenuShortcutKeyDown(event));
}
/**
......@@ -3255,7 +3255,7 @@ public class BasicTreeUI extends TreeUI
// 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 @@ public class BasicTreeUI extends TreeUI
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 class BasicTreeUI extends TreeUI
public void dragStarting(MouseEvent me) {
dragStarted = true;
if (me.isControlDown()) {
if (BasicGraphicsUtils.isMenuShortcutKeyDown(me)) {
tree.addSelectionPath(pressedPath);
setAnchorSelectionPath(pressedPath);
setLeadSelectionPath(pressedPath, true);
......
......@@ -510,7 +510,7 @@ public class DefaultCaret extends Rectangle implements Caret, FocusListener, Mou
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 &&
getDot() != -1) {
moveCaret(e);
} else {
} else if (!e.isPopupTrigger()) {
positionCaret(e);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册