-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8306409: Open source AWT KeyBoardFocusManger, LightWeightComponent re…
…lated tests Backport-of: 732179ca84ee1dab6530255c33de7f35cab649c2
- Loading branch information
Victor Rudometov
authored and
Paul Hohensee
committed
May 23, 2023
1 parent
536e133
commit 18ec008
Showing
6 changed files
with
615 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,93 @@ | ||
/* | ||
* Copyright (c) 2003, 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. | ||
*/ | ||
|
||
/* | ||
@test | ||
@bug 4467840 | ||
@summary Generate a PropertyChange when KeyboardFocusManager changes | ||
@key headful | ||
@run main ChangeKFMTest | ||
*/ | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.DefaultKeyboardFocusManager; | ||
import java.awt.EventQueue; | ||
import java.awt.KeyboardFocusManager; | ||
|
||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
|
||
public class ChangeKFMTest implements PropertyChangeListener { | ||
static final String CURRENT_PROP_NAME = "managingFocus"; | ||
boolean current_fired; | ||
boolean not_current_fired; | ||
KeyboardFocusManager kfm; | ||
public static void main(String[] args) throws Exception { | ||
ChangeKFMTest test = new ChangeKFMTest(); | ||
test.start(); | ||
} | ||
|
||
public void start () throws Exception { | ||
EventQueue.invokeAndWait(() -> { | ||
kfm = new DefaultKeyboardFocusManager(); | ||
kfm.addPropertyChangeListener(CURRENT_PROP_NAME, this); | ||
current_fired = false; | ||
not_current_fired = false; | ||
KeyboardFocusManager.setCurrentKeyboardFocusManager(kfm); | ||
if (!current_fired) { | ||
throw new RuntimeException("Change to current was not fired on KFM instalation"); | ||
} | ||
if (not_current_fired) { | ||
throw new RuntimeException("Change to non-current was fired on KFM instalation"); | ||
} else { | ||
System.out.println("Installation was complete correctly"); | ||
} | ||
|
||
current_fired = false; | ||
not_current_fired = false; | ||
KeyboardFocusManager.setCurrentKeyboardFocusManager(null); | ||
if (!not_current_fired) { | ||
throw new RuntimeException("Change to non-current was not fired on KFM uninstalation"); | ||
} | ||
if (current_fired) { | ||
throw new RuntimeException("Change to current was fired on KFM uninstalation"); | ||
} else { | ||
System.out.println("Uninstallation was complete correctly"); | ||
} | ||
}); | ||
} | ||
|
||
public void propertyChange(PropertyChangeEvent e) { | ||
System.out.println(e.toString()); | ||
if (!CURRENT_PROP_NAME.equals(e.getPropertyName())) { | ||
throw new RuntimeException("Unexpected property name - " + e.getPropertyName()); | ||
} | ||
if (((Boolean)e.getNewValue()).booleanValue()) { | ||
current_fired = true; | ||
} else { | ||
not_current_fired = true; | ||
} | ||
System.out.println("current_fired = " + current_fired); | ||
System.out.println("not_current_fired = " + not_current_fired); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
test/jdk/java/awt/KeyboardFocusmanager/PropertySupportNPETest.java
This file contains 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,47 @@ | ||
/* | ||
* Copyright (c) 2001, 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. | ||
*/ | ||
|
||
/* | ||
@test | ||
@bug 4458016 | ||
@summary KeyboardFocusManager.get[Property|Vetoable]ChangeListeners throw NPE | ||
@key headful | ||
@run main PropertySupportNPETest | ||
*/ | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.EventQueue; | ||
import java.awt.KeyboardFocusManager; | ||
|
||
public class PropertySupportNPETest { | ||
public static void main(String[] args) throws Exception { | ||
EventQueue.invokeAndWait(() -> { | ||
KeyboardFocusManager kfm = | ||
KeyboardFocusManager.getCurrentKeyboardFocusManager(); | ||
kfm.getVetoableChangeListeners(); | ||
kfm.getVetoableChangeListeners(""); | ||
kfm.getPropertyChangeListeners(); | ||
kfm.getPropertyChangeListeners(""); | ||
}); | ||
} | ||
} |
This file contains 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,59 @@ | ||
/* | ||
* Copyright (c) 2005, 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. | ||
*/ | ||
|
||
/* | ||
@test | ||
@bug 6215905 | ||
@summary Tests that passing null value to Label.setText(String) doesn't | ||
lead to VM crash. | ||
@key headful | ||
@run main NullLabelTest | ||
*/ | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.EventQueue; | ||
import java.awt.Label; | ||
import java.awt.Frame; | ||
|
||
public class NullLabelTest { | ||
|
||
static Frame frame; | ||
public static void main(String[] args) throws Exception { | ||
EventQueue.invokeAndWait(() -> { | ||
try { | ||
frame = new Frame(); | ||
Label l = new Label("A"); | ||
frame.add(l); | ||
frame.setLayout(new BorderLayout()); | ||
frame.setSize(200, 200); | ||
frame.setLocationRelativeTo(null); | ||
frame.setVisible(true); | ||
l.setText(null); | ||
} finally { | ||
if (frame != null) { | ||
frame.dispose(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains 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,96 @@ | ||
/* | ||
* Copyright (c) 1998, 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. | ||
*/ | ||
|
||
/* | ||
@test | ||
@bug 4087971 | ||
@summary Insets does not layout a component correctly | ||
@key headful | ||
@run main InsetsTest | ||
*/ | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Color; | ||
import java.awt.EventQueue; | ||
import java.awt.Insets; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
import javax.swing.JPanel; | ||
import javax.swing.border.EmptyBorder; | ||
|
||
public class InsetsTest { | ||
private int leftInsetValue; | ||
private InsetsClass IC; | ||
|
||
public static void main(String[] args) throws Exception { | ||
InsetsTest test = new InsetsTest(); | ||
test.start(); | ||
} | ||
|
||
public void start() throws Exception { | ||
EventQueue.invokeAndWait(() -> { | ||
try { | ||
IC = new InsetsClass(); | ||
IC.setLayout(new BorderLayout()); | ||
IC.setSize(200, 200); | ||
IC.setVisible(true); | ||
|
||
leftInsetValue = IC.returnLeftInset(); | ||
if (leftInsetValue != 30) { | ||
throw new RuntimeException("Test Failed - Left inset" + | ||
"is not taken correctly"); | ||
} | ||
} finally { | ||
if (IC != null) { | ||
IC.dispose(); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
class InsetsClass extends JFrame { | ||
private int value; | ||
private JPanel panel; | ||
|
||
public InsetsClass() { | ||
super("TestFrame"); | ||
setBackground(Color.lightGray); | ||
|
||
panel = new JPanel(); | ||
panel.setBorder(new EmptyBorder(new Insets(30, 30, 30, 30))); | ||
panel.add(new JButton("Test Button")); | ||
|
||
getContentPane().add(panel); | ||
pack(); | ||
setVisible(true); | ||
} | ||
|
||
public int returnLeftInset() { | ||
// Getting the left inset value | ||
Insets insets = panel.getInsets(); | ||
value = insets.left; | ||
return value; | ||
} | ||
} |
Oops, something went wrong.
18ec008
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues