From 68ed55d6e9f239899f32ae6b58bd25b94df58eb1 Mon Sep 17 00:00:00 2001 From: pchelko Date: Wed, 19 Nov 2014 18:57:39 +0400 Subject: [PATCH] 8058193: [macosx] Potential incomplete fix for JDK-8031485 Reviewed-by: alexsch, serb --- .../classes/com/apple/laf/AquaComboBoxUI.java | 7 ++++- .../ConsumedKeyTest.java} | 30 +++++++++++-------- 2 files changed, 24 insertions(+), 13 deletions(-) rename test/javax/swing/JComboBox/{ConsumedEscTest/ConsumedEscTest.java => ConsumedKeyTest/ConsumedKeyTest.java} (81%) diff --git a/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java b/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java index c9a86b851..5345828c4 100644 --- a/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java +++ b/src/macosx/classes/com/apple/laf/AquaComboBoxUI.java @@ -486,10 +486,15 @@ public class AquaComboBoxUI extends BasicComboBoxUI implements Sizeable { // This is somewhat messy. The difference here from BasicComboBoxUI.EnterAction is that // 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) { triggerSelectionEvent((JComboBox)e.getSource(), e); } + + @Override + public boolean isEnabled() { + return comboBox.isPopupVisible() && super.isEnabled(); + } }; private static final Action toggleSelectionAction = new AbstractAction() { diff --git a/test/javax/swing/JComboBox/ConsumedEscTest/ConsumedEscTest.java b/test/javax/swing/JComboBox/ConsumedKeyTest/ConsumedKeyTest.java similarity index 81% rename from test/javax/swing/JComboBox/ConsumedEscTest/ConsumedEscTest.java rename to test/javax/swing/JComboBox/ConsumedKeyTest/ConsumedKeyTest.java index 9976730a6..ab283691d 100644 --- a/test/javax/swing/JComboBox/ConsumedEscTest/ConsumedEscTest.java +++ b/test/javax/swing/JComboBox/ConsumedKeyTest/ConsumedKeyTest.java @@ -24,22 +24,28 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; -import java.awt.Robot; import java.awt.Toolkit; +import java.awt.Robot; import sun.awt.SunToolkit; /* @test - @bug 8031485 + @bug 8031485 8058193 @summary Combo box consuming escape and enter key events @author Petr Pchelko - @run main ConsumedEscTest + @run main ConsumedKeyTest */ -public class ConsumedEscTest { +public class ConsumedKeyTest { private static volatile JFrame frame; - private static volatile boolean passed = false; + private static volatile boolean passed; 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 { SwingUtilities.invokeAndWait(() -> { frame = new JFrame(); @@ -48,7 +54,7 @@ public class ConsumedEscTest { panel.add(combo); combo.requestFocusInWindow(); frame.setBounds(100, 150, 300, 100); - addAction(panel); + addAction(panel, key); frame.add(panel); frame.setVisible(true); }); @@ -56,24 +62,25 @@ public class ConsumedEscTest { Robot robot = new Robot(); robot.waitForIdle(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - robot.keyPress(KeyEvent.VK_ESCAPE); + robot.keyPress(key); robot.waitForIdle(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); - robot.keyRelease(KeyEvent.VK_ESCAPE); + robot.keyRelease(key); robot.waitForIdle(); ((SunToolkit)Toolkit.getDefaultToolkit()).realSync(); 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 { if (frame != null) { frame.dispose(); } } + } - private static void addAction(JComponent comp) { - KeyStroke k = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); + private static void addAction(JComponent comp, final int key) { + KeyStroke k = KeyStroke.getKeyStroke(key, 0); Object actionKey = "cancel"; comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(k, actionKey); Action cancelAction = new AbstractAction() { @@ -84,5 +91,4 @@ public class ConsumedEscTest { }; comp.getActionMap().put(actionKey, cancelAction); } - } -- GitLab