Skip to content
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

JDK-8353486 : Open source Swing Tests - Set 4 #24456

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4464774.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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.JFrame;
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()
.title("JFileChooser Instructions")
.instructions(INSTRUCTIONS)
.rows(10)
.columns(65)
.testUI(bug4464774::createAndShowUI)
.build()
.awaitAndCheck();
}

public static JFrame createAndShowUI() {
JFrame frame = new JFrame("JFileChooser bug4464774");
JFileChooser jfc = new JFileChooser();
frame.add(jfc);
frame.pack();
return frame;
}
}
70 changes: 70 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4522756.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 To verify that if for the first time JFileChooser is opened,
the icon for Desktop is not missing.
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual bug4522756
*/

import javax.swing.JFileChooser;
import javax.swing.JFrame;
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()
.title("Instructions")
.instructions(INSTRUCTIONS)
.rows(12)
.columns(50)
.testUI(bug4522756::createAndShowUI)
.build()
.awaitAndCheck();
}

public static JFrame createAndShowUI() {
JFrame frame = new JFrame("JFileChooser bug4522756");
JFileChooser jfc = new JFileChooser();
frame.add(jfc);
frame.pack();
return frame;
}
}
123 changes: 123 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4759934.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* 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");
fr.add(frameBtn);

frameBtn.addActionListener(e -> createDialog());
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);
}
}
115 changes: 115 additions & 0 deletions test/jdk/javax/swing/JFileChooser/bug4943900.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* 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 /test/lib
* @build PassFailJFrame jtreg.SkippedException
* @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;
import jtreg.SkippedException;

public class bug4943900 {
private static final String INSTRUCTIONS = """
1. Click "Show FileChooser" button below, FileChooser dialog must
appear.

2. Ensure that there is a Filter combo box with these two items:
- Text Files (*.txt) [must be selected when the dialog opens]
- All Files

3. Leave the "Text files" item selected and check that the
filter works: only *.txt files can appear in the files list
You can navigate directories in the FileChooser and find one
that contains some *.txt files to ensure they are shown in
the file list.

4. Try switching the filters and ensure that the file list
is updated properly.

If the FileFilter works correctly, press PASS else press FAIL.
""";

public static void main(String[] args) throws Exception {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
throw new SkippedException("LaF not supported", e);
}

PassFailJFrame.builder()
.title("bug4943900 Test Instructions")
.instructions(INSTRUCTIONS)
.rows(20)
.columns(65)
.testUI(bug4943900::createAndShowUI)
.build()
.awaitAndCheck();
}

public static JFrame createAndShowUI() {
JFrame frame = new JFrame("JFileChooser bug4464774");
JFileChooser fc = new JFileChooser();
TextFileFilter filter = new TextFileFilter();
fc.setFileFilter(filter);
frame.add(fc);
frame.pack();
return frame;
}

private static final class TextFileFilter extends FileFilter {
public boolean accept(File f) {
if (f != null) {
if (f.isDirectory()) {
return true;
}
String extension = getExtension(f);
return extension != null && extension.equals("txt");
}
return false;
}

public String getDescription() {
return "Text Files (*.txt)";
}

public 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;
}
}
}
Loading