-
Notifications
You must be signed in to change notification settings - Fork 6.1k
JDK-8353486 : Open source Swing Tests - Set 4 #24456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
be62d05
Swing tests Set4
honkar-jdk f1af1eb
review changes
honkar-jdk 491a642
JOptionPane changes
honkar-jdk fa9529d
review update
honkar-jdk d9e08d0
instruction update
honkar-jdk 1cd5ec6
jfc.setControlButtonsAreShown() added
honkar-jdk 5e5cbb4
remove redudant frame
honkar-jdk 7d43f12
review changes
honkar-jdk fa05f0c
bug4943900 instruction update
honkar-jdk a26d98e
minor
honkar-jdk 1841963
minor update
honkar-jdk bb9d764
instruction update, jfc added to a JFrame
honkar-jdk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2003, 2025, 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. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 4464774 | ||
* @requires (os.family == "windows") | ||
* @summary JFileChooser: selection of left-side folder buttons shown incorrectly | ||
in Windows L&F | ||
* @library /java/awt/regtesthelpers | ||
* @build PassFailJFrame | ||
* @run main/manual bug4464774 | ||
*/ | ||
|
||
import javax.swing.JFileChooser; | ||
import javax.swing.UIManager; | ||
|
||
public class bug4464774 { | ||
private static final String INSTRUCTIONS = """ | ||
Click any button from the buttons to the left | ||
("Documents", "Desktop", "My Computer" etc.) in FileChooser dialog. | ||
When the button is toggled, it should be lowered and | ||
should NOT have focus painted inside it (black dotted frame). | ||
|
||
If the above is true, press PASS else FAIL. | ||
"""; | ||
|
||
public static void main(String[] argv) throws Exception { | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
PassFailJFrame.builder() | ||
.instructions(INSTRUCTIONS) | ||
.columns(65) | ||
.rows(10) | ||
.testUI(() -> { | ||
JFileChooser jfc = new JFileChooser(); | ||
jfc.setControlButtonsAreShown(false); | ||
return jfc; | ||
}) | ||
.build() | ||
.awaitAndCheck(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2002, 2025, 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. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 4522756 | ||
* @requires (os.family == "windows") | ||
* @summary Verifies that the Desktop icon is not missing when | ||
JFileChooser is opened for the first time. | ||
* @library /java/awt/regtesthelpers | ||
* @build PassFailJFrame | ||
* @run main/manual bug4522756 | ||
*/ | ||
|
||
import javax.swing.JFileChooser; | ||
import javax.swing.UIManager; | ||
|
||
public class bug4522756 { | ||
private static final String INSTRUCTIONS = """ | ||
Verify the following: | ||
|
||
1. If Desktop icon image is present on the Desktop button | ||
on the left panel of JFileChooser. | ||
2. Press Desktop button. Check that you actually | ||
go up to the desktop. | ||
|
||
If the above is true, press PASS else FAIL. | ||
"""; | ||
|
||
public static void main(String[] args) throws Exception { | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
PassFailJFrame.builder() | ||
.instructions(INSTRUCTIONS) | ||
.columns(50) | ||
.rows(12) | ||
.testUI(() -> { | ||
JFileChooser jfc = new JFileChooser(); | ||
jfc.setControlButtonsAreShown(false); | ||
return jfc; | ||
}) | ||
.build() | ||
.awaitAndCheck(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (c) 2003, 2025, 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. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @key headful | ||
* @bug 4759934 | ||
* @summary windows activation problem | ||
* @library /javax/swing/regtesthelpers | ||
* @build Util | ||
* @run main bug4759934 | ||
*/ | ||
|
||
import java.awt.Dialog; | ||
import java.awt.Point; | ||
import java.awt.Robot; | ||
import java.awt.event.KeyEvent; | ||
import java.awt.event.MouseEvent; | ||
import javax.swing.JButton; | ||
import javax.swing.JDialog; | ||
import javax.swing.JFileChooser; | ||
import javax.swing.JFrame; | ||
import javax.swing.SwingUtilities; | ||
|
||
public class bug4759934 { | ||
private static JFrame fr; | ||
private static Dialog dlg; | ||
private static JFileChooser jfc; | ||
|
||
private static JButton frameBtn; | ||
private static JButton dialogBtn; | ||
|
||
public static void main(String[] args) throws Exception { | ||
try { | ||
Robot robot = new Robot(); | ||
robot.setAutoWaitForIdle(true); | ||
robot.setAutoDelay(50); | ||
|
||
SwingUtilities.invokeAndWait(bug4759934::createTestUI); | ||
robot.waitForIdle(); | ||
robot.delay(1000); | ||
|
||
Point frameBtnLoc = Util.getCenterPoint(frameBtn); | ||
robot.mouseMove(frameBtnLoc.x, frameBtnLoc.y); | ||
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); | ||
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(500); | ||
|
||
Point dlgBtnLoc = Util.getCenterPoint(dialogBtn); | ||
robot.mouseMove(dlgBtnLoc.x , dlgBtnLoc.y); | ||
robot.mousePress(MouseEvent.BUTTON1_DOWN_MASK); | ||
robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK); | ||
robot.delay(500); | ||
|
||
robot.keyPress(KeyEvent.VK_ESCAPE); | ||
robot.keyRelease(KeyEvent.VK_ESCAPE); | ||
robot.delay(500); | ||
|
||
SwingUtilities.invokeAndWait(() -> { | ||
if (frameBtn.hasFocus() && !dialogBtn.hasFocus()) { | ||
throw new RuntimeException("Test failed! Focus was passed back" + | ||
" to Frame instead of Dialog"); | ||
} | ||
}); | ||
} finally { | ||
SwingUtilities.invokeAndWait(() -> { | ||
if (dlg != null) { | ||
dlg.dispose(); | ||
} | ||
if (fr != null) { | ||
fr.dispose(); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private static void createTestUI() { | ||
fr = new JFrame("bug4759934 - JFrame"); | ||
|
||
frameBtn = new JButton("Show Dialog"); | ||
frameBtn.addActionListener(e -> createDialog()); | ||
fr.add(frameBtn); | ||
|
||
fr.setSize(300, 200); | ||
fr.setLocationRelativeTo(null); | ||
fr.setVisible(true); | ||
} | ||
|
||
private static void createDialog() { | ||
dlg = new JDialog(fr, "bug4759934 - JDialog"); | ||
|
||
dialogBtn = new JButton("Show FileChooser"); | ||
dlg.add(dialogBtn); | ||
|
||
dialogBtn.addActionListener(e -> { | ||
jfc = new JFileChooser(); | ||
jfc.showOpenDialog(dlg); | ||
}); | ||
|
||
dlg.setSize(300, 200); | ||
dlg.setLocation(fr.getX() + fr.getWidth() + 10, fr.getY()); | ||
dlg.setVisible(true); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (c) 2004, 2025, 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. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 4943900 | ||
* @summary Tests that FileFilter combo box is shown in FileChooser | ||
* @library /java/awt/regtesthelpers | ||
* @build PassFailJFrame | ||
* @run main/manual bug4943900 | ||
*/ | ||
|
||
import java.io.File; | ||
import javax.swing.JFileChooser; | ||
import javax.swing.JFrame; | ||
import javax.swing.UIManager; | ||
import javax.swing.filechooser.FileFilter; | ||
|
||
public class bug4943900 { | ||
private static final String INSTRUCTIONS = """ | ||
honkar-jdk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<html> | ||
<ol> | ||
<li>When the test runs, a <code>JFileChooser</code> will be displayed. | ||
<li>Ensure that there is a filter combo box with these two items: | ||
<ul> | ||
<li><b>Text Files (*.txt)</b> | ||
— <em>[must be selected when the dialog opens]</em> | ||
<li><b>All Files</b> | ||
</ul> | ||
<li>Leave the <b>Text files</b> item selected and check that the | ||
filter works: only <code>*.txt</code> files can appear in the file list. | ||
You can navigate directories in the file chooser and find one | ||
that contains some <code>*.txt</code> files to ensure they are shown in | ||
the file list. On macOS when the text filter is applied verify | ||
that the non-text files are greyed out. | ||
<li>Try switching the filters and ensure that the file list | ||
is updated properly. | ||
<li>If the <code>FileFilter</code> works correctly, | ||
press <b>Pass</b> else press <b>Fail</b>. | ||
</ol> | ||
</html> | ||
"""; | ||
|
||
public static void main(String[] args) throws Exception { | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
|
||
PassFailJFrame.builder() | ||
.title("bug4943900 Test Instructions") | ||
.instructions(INSTRUCTIONS) | ||
.rows(14) | ||
.columns(50) | ||
.testUI(bug4943900::createAndShowUI) | ||
.build() | ||
.awaitAndCheck(); | ||
} | ||
|
||
public static JFrame createAndShowUI() { | ||
JFileChooser fc = new JFileChooser(); | ||
fc.setControlButtonsAreShown(false); | ||
TextFileFilter filter = new TextFileFilter(); | ||
fc.setFileFilter(filter); | ||
|
||
JFrame frame = new JFrame("bug4943900 - JFileChooser"); | ||
frame.add(fc); | ||
frame.pack(); | ||
return frame; | ||
} | ||
|
||
private static final class TextFileFilter extends FileFilter { | ||
@Override | ||
public boolean accept(File f) { | ||
honkar-jdk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (f != null) { | ||
if (f.isDirectory()) { | ||
return true; | ||
} | ||
String extension = getExtension(f); | ||
return extension != null && extension.equals("txt"); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Text Files (*.txt)"; | ||
} | ||
|
||
private static String getExtension(File f) { | ||
if (f != null) { | ||
String filename = f.getName(); | ||
int i = filename.lastIndexOf('.'); | ||
if (i > 0 && i < filename.length() - 1) { | ||
return filename.substring(i + 1).toLowerCase(); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.