提交 68ed55d6 编写于 作者: P pchelko

8058193: [macosx] Potential incomplete fix for JDK-8031485

Reviewed-by: alexsch, serb
上级 0071d180
...@@ -486,10 +486,15 @@ public class AquaComboBoxUI extends BasicComboBoxUI implements Sizeable { ...@@ -486,10 +486,15 @@ public class AquaComboBoxUI extends BasicComboBoxUI implements Sizeable {
// This is somewhat messy. The difference here from BasicComboBoxUI.EnterAction is that // This is somewhat messy. The difference here from BasicComboBoxUI.EnterAction is that
// arrow up or down does not automatically select the // arrow up or down does not automatically select the
private static final Action triggerSelectionAction = new AbstractAction() { private final Action triggerSelectionAction = new AbstractAction() {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
triggerSelectionEvent((JComboBox)e.getSource(), e); triggerSelectionEvent((JComboBox)e.getSource(), e);
} }
@Override
public boolean isEnabled() {
return comboBox.isPopupVisible() && super.isEnabled();
}
}; };
private static final Action toggleSelectionAction = new AbstractAction() { private static final Action toggleSelectionAction = new AbstractAction() {
......
...@@ -24,22 +24,28 @@ ...@@ -24,22 +24,28 @@
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.Robot;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Robot;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
/* /*
@test @test
@bug 8031485 @bug 8031485 8058193
@summary Combo box consuming escape and enter key events @summary Combo box consuming escape and enter key events
@author Petr Pchelko @author Petr Pchelko
@run main ConsumedEscTest @run main ConsumedKeyTest
*/ */
public class ConsumedEscTest { public class ConsumedKeyTest {
private static volatile JFrame frame; private static volatile JFrame frame;
private static volatile boolean passed = false; private static volatile boolean passed;
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
test(KeyEvent.VK_ESCAPE);
test(KeyEvent.VK_ENTER);
}
private static void test(final int key) throws Exception {
passed = false;
try { try {
SwingUtilities.invokeAndWait(() -> { SwingUtilities.invokeAndWait(() -> {
frame = new JFrame(); frame = new JFrame();
...@@ -48,7 +54,7 @@ public class ConsumedEscTest { ...@@ -48,7 +54,7 @@ public class ConsumedEscTest {
panel.add(combo); panel.add(combo);
combo.requestFocusInWindow(); combo.requestFocusInWindow();
frame.setBounds(100, 150, 300, 100); frame.setBounds(100, 150, 300, 100);
addAction(panel); addAction(panel, key);
frame.add(panel); frame.add(panel);
frame.setVisible(true); frame.setVisible(true);
}); });
...@@ -56,24 +62,25 @@ public class ConsumedEscTest { ...@@ -56,24 +62,25 @@ public class ConsumedEscTest {
Robot robot = new Robot(); Robot robot = new Robot();
robot.waitForIdle(); robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
robot.keyPress(KeyEvent.VK_ESCAPE); robot.keyPress(key);
robot.waitForIdle(); robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
robot.keyRelease(KeyEvent.VK_ESCAPE); robot.keyRelease(key);
robot.waitForIdle(); robot.waitForIdle();
((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
if (!passed) { if (!passed) {
throw new RuntimeException("FAILED: ESC was consumed by combo box"); throw new RuntimeException("FAILED: " + KeyEvent.getKeyText(key) + " was consumed by combo box");
} }
} finally { } finally {
if (frame != null) { if (frame != null) {
frame.dispose(); frame.dispose();
} }
} }
} }
private static void addAction(JComponent comp) { private static void addAction(JComponent comp, final int key) {
KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); KeyStroke k = KeyStroke.getKeyStroke(key, 0);
Object actionKey = "cancel"; Object actionKey = "cancel";
comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(k, actionKey); comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(k, actionKey);
Action cancelAction = new AbstractAction() { Action cancelAction = new AbstractAction() {
...@@ -84,5 +91,4 @@ public class ConsumedEscTest { ...@@ -84,5 +91,4 @@ public class ConsumedEscTest {
}; };
comp.getActionMap().put(actionKey, cancelAction); comp.getActionMap().put(actionKey, cancelAction);
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册