From 59a79632ace2984c1b7659ac38c0af005e8bc8b7 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Mon, 16 Jan 2023 16:45:33 +0530 Subject: [PATCH 1/3] fix + test --- .../com/apple/laf/AquaFileChooserUI.java | 5 ++ .../JFileChooser/AquaDefaultButtonTest.java | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java index 2cfaa5a36ca97..8f3bb5b7f6968 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java @@ -593,6 +593,11 @@ protected JButton getApproveButton(final JFileChooser fc) { return fApproveButton; } + @Override + public JButton getDefaultButton(JFileChooser fc) { + return getApproveButton(fc); + } + public int getApproveButtonMnemonic(final JFileChooser fc) { return fSubPanel.getApproveButtonMnemonic(fc); } diff --git a/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java b/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java new file mode 100644 index 0000000000000..96f0affe0d7a6 --- /dev/null +++ b/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +/* + * @test + * @bug 8300084 + * @key headful + * @summary Test to check if getDefaultButton() return valid default approve button. + * @requires (os.family == "mac") + * @run main AquaDefaultButtonTest + */ + +public class AquaDefaultButtonTest { + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + JFileChooser fileChooser = new JFileChooser(); + JButton defaultApproveButton = fileChooser.getUI().getDefaultButton(fileChooser); + if (defaultApproveButton == null) { + throw new RuntimeException("getDefaultButton() method returns null for Aqua L&F!"); + } + } + }); + System.out.println("Test Pass!"); + } +} From 81d2cda2ee316c294db4a8b4e79ba0abc04a59e1 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Mon, 16 Jan 2023 18:28:09 +0530 Subject: [PATCH 2/3] Updated based on review comments --- .../macosx/classes/com/apple/laf/AquaFileChooserUI.java | 2 +- .../javax/swing/JFileChooser/AquaDefaultButtonTest.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java index 8f3bb5b7f6968..c6d198bed438e 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it diff --git a/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java b/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java index 96f0affe0d7a6..9bcdcf9fb2155 100644 --- a/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java +++ b/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java @@ -41,10 +41,11 @@ public static void main(String[] args) throws Exception { UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); SwingUtilities.invokeAndWait(new Runnable() { public void run() { - JFileChooser fileChooser = new JFileChooser(); - JButton defaultApproveButton = fileChooser.getUI().getDefaultButton(fileChooser); - if (defaultApproveButton == null) { - throw new RuntimeException("getDefaultButton() method returns null for Aqua L&F!"); + JFileChooser fc = new JFileChooser(); + JButton defApproveBtn = fc.getUI().getDefaultButton(fc); + if (defApproveBtn == null) { + throw new RuntimeException("getDefaultButton() method " + + "returns null for Aqua L&F!"); } } }); From 603fd66af490d4ef4104911088b1c3fd74a620d1 Mon Sep 17 00:00:00 2001 From: Tejesh R Date: Mon, 16 Jan 2023 19:13:46 +0530 Subject: [PATCH 3/3] Removed the test - Updating #11901 test --- .../JFileChooser/AquaDefaultButtonTest.java | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java diff --git a/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java b/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java deleted file mode 100644 index 9bcdcf9fb2155..0000000000000 --- a/test/jdk/javax/swing/JFileChooser/AquaDefaultButtonTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; - -/* - * @test - * @bug 8300084 - * @key headful - * @summary Test to check if getDefaultButton() return valid default approve button. - * @requires (os.family == "mac") - * @run main AquaDefaultButtonTest - */ - -public class AquaDefaultButtonTest { - - public static void main(String[] args) throws Exception { - UIManager.setLookAndFeel("com.apple.laf.AquaLookAndFeel"); - SwingUtilities.invokeAndWait(new Runnable() { - public void run() { - JFileChooser fc = new JFileChooser(); - JButton defApproveBtn = fc.getUI().getDefaultButton(fc); - if (defApproveBtn == null) { - throw new RuntimeException("getDefaultButton() method " + - "returns null for Aqua L&F!"); - } - } - }); - System.out.println("Test Pass!"); - } -}