This commit is contained in:
Andrei Dmitriev 2008-03-27 12:31:18 +03:00
commit 44f8b333b5
20 changed files with 1700 additions and 20 deletions

View File

@ -1078,6 +1078,9 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
focusNextComponent(focusedComponent);
}
return;
} else if (e.getID() == KeyEvent.KEY_PRESSED) {
// Fix for 6637607: consumeNextKeyTyped should be reset.
consumeNextKeyTyped = false;
}
toTest = focusedComponent.getFocusTraversalKeys(

View File

@ -1013,6 +1013,16 @@ abstract class XDecoratedPeer extends XWindowPeer {
private void handleWmTakeFocus(XClientMessageEvent cl) {
focusLog.log(Level.FINE, "WM_TAKE_FOCUS on {0}", new Object[]{this});
// A workaround to Metacity issue (see 6613426).
// The first check is to skip redundant WM_TAKE_FOCUS on click
// in a focused frame. The second check is to allow requesting focus
// on click in a frame when its owned window is currently focused.
if (this == getNativeFocusedWindowPeer() &&
target == XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow())
{
focusLog.fine("The window is already focused, skipping.");
return;
}
requestWindowFocus(cl.get_data(1), true);
}

View File

@ -436,6 +436,7 @@ SplashInitPlatform(Splash * splash) {
break;
}
case PseudoColor: {
int availableColors;
int numColors;
int numComponents[3];
unsigned long colorIndex[SPLASH_COLOR_MAP_SIZE];
@ -444,9 +445,20 @@ SplashInitPlatform(Splash * splash) {
int depth = XDefaultDepthOfScreen(splash->screen);
int scale = 65535 / MAX_COLOR_VALUE;
numColors = GetNumAvailableColors(splash->display, splash->screen,
availableColors = GetNumAvailableColors(splash->display, splash->screen,
splash->visual->map_entries);
numColors = quantizeColors(numColors, numComponents);
numColors = quantizeColors(availableColors, numComponents);
if (numColors > availableColors) {
// Could not allocate the color cells. Most probably
// the pool got exhausted. Disable the splash screen.
XCloseDisplay(splash->display);
splash->isVisible = -1;
splash->display = NULL;
splash->screen = NULL;
splash->visual = NULL;
fprintf(stderr, "Warning: unable to initialize the splashscreen. Not enough available color cells.\n");
return;
}
splash->cmap = AllocColors(splash->display, splash->screen,
numColors, colorIndex);
for (i = 0; i < numColors; i++) {

View File

@ -5740,6 +5740,10 @@ void AwtComponent::_NativeHandleEvent(void *param)
env->DeleteGlobalRef(event);
delete nhes;
return;
} else if (id == java_awt_event_KeyEvent_KEY_PRESSED) {
// Fix for 6637607: reset consuming
keyDownConsumed = FALSE;
}
/* Consume a KEY_TYPED event if a KEY_PRESSED had been, to support

View File

@ -1,5 +1,5 @@
/*
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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
@ -428,8 +428,12 @@ void AwtDialog::ModalActivateNextWindow(HWND dialogHWnd,
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jlongArray windows = (jlongArray)(env->CallStaticObjectMethod(AwtWindow::wwindowPeerCls,
AwtWindow::getActiveWindowsMID));
jclass wwindowPeerCls = env->FindClass("sun/awt/windows/WWindowPeer");
jmethodID getActiveWindowsMID = env->GetStaticMethodID(wwindowPeerCls,
"getActiveWindowHandles", "()[J");
DASSERT(getActiveWindowsMID != NULL);
jlongArray windows = (jlongArray)(env->CallStaticObjectMethod(wwindowPeerCls,
getActiveWindowsMID));
if (windows == NULL) {
return;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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
@ -122,9 +122,6 @@ jfieldID AwtWindow::warningStringID;
jfieldID AwtWindow::locationByPlatformID;
jfieldID AwtWindow::autoRequestFocusID;
jclass AwtWindow::wwindowPeerCls;
jmethodID AwtWindow::getActiveWindowsMID;
jfieldID AwtWindow::sysXID;
jfieldID AwtWindow::sysYID;
jfieldID AwtWindow::sysWID;
@ -2159,11 +2156,6 @@ Java_sun_awt_windows_WWindowPeer_initIDs(JNIEnv *env, jclass cls)
{
TRY;
AwtWindow::wwindowPeerCls = cls;
AwtWindow::getActiveWindowsMID =
env->GetStaticMethodID(cls, "getActiveWindowHandles", "()[J");
DASSERT(AwtWindow::getActiveWindowsMID != NULL);
AwtWindow::sysXID = env->GetFieldID(cls, "sysX", "I");
AwtWindow::sysYID = env->GetFieldID(cls, "sysY", "I");
AwtWindow::sysWID = env->GetFieldID(cls, "sysW", "I");

View File

@ -1,5 +1,5 @@
/*
* Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 1996-2008 Sun Microsystems, Inc. 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
@ -57,11 +57,6 @@ public:
static jfieldID screenID; /* screen number passed over from WindowPeer */
static jfieldID autoRequestFocusID;
/* WWindowPeer class */
static jclass wwindowPeerCls;
/* long[] getActiveWindowHandles() method in WWindowPeer */
static jmethodID getActiveWindowsMID;
// The coordinates at the peer.
static jfieldID sysXID;
static jfieldID sysYID;

View File

@ -0,0 +1,64 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 6610244
@library ../../regtesthelpers
@build Util Sysout AbstractTest
@summary modal dialog closes with fatal error if -Xcheck:jni is set
@author Andrei Dmitriev : area=awt.dialog
@run main/othervm -Xcheck:jni CrashXCheckJni
*/
import java.awt.*;
import java.awt.event.*;
import java.util.Timer;
import java.util.TimerTask;
import test.java.awt.regtesthelpers.Util;
import test.java.awt.regtesthelpers.AbstractTest;
import test.java.awt.regtesthelpers.Sysout;
public class CrashXCheckJni {
public static void main(String []s)
{
final Dialog fd = new Dialog(new Frame(), true);
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
System.out.println("RUNNING TASK");
fd.setVisible(false);
fd.dispose();
System.out.println("FINISHING TASK");
}
}, 3000L);
fd.setVisible(true);
t.cancel();
Util.waitForIdle(null);
AbstractTest.pass();
}
}

View File

@ -0,0 +1,165 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 6314575
@summary Tests that previosly focused owned window doesn't steal focus when an owner's component requests focus.
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main ActualFocusedWindowBlockingTest
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.lang.reflect.InvocationTargetException;
import sun.awt.SunToolkit;
import test.java.awt.regtesthelpers.Util;
public class ActualFocusedWindowBlockingTest extends Applet {
Robot robot = Util.createRobot();
Frame owner = new Frame("Owner Frame");
Window win = new Window(owner);
Frame frame = new Frame("Auxiliary Frame");
Button fButton = new Button("frame button") {public String toString() {return "Frame_Button";}};
Button wButton = new Button("window button") {public String toString() {return "Window_Button";}};
Button aButton = new Button("auxiliary button") {public String toString() {return "Auxiliary_Button";}};
public static void main(String[] args) {
ActualFocusedWindowBlockingTest app = new ActualFocusedWindowBlockingTest();
app.init();
app.start();
}
public void init() {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.out.println("--> " + e);
}
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK);
owner.add(fButton);
win.add(wButton);
frame.add(aButton);
owner.setName("OWNER_FRAME");
win.setName("OWNED_WINDOW");
frame.setName("AUX_FRAME");
tuneAndShowWindows(new Window[] {owner, win, frame});
}
public void start() {
if ("sun.awt.motif.MToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName())) {
System.out.println("No testing on Motif. Test passed.");
return;
}
System.out.println("\nTest started:\n");
// Test 1.
clickOnCheckFocus(wButton);
clickOnCheckFocus(aButton);
Util.clickOnComp(fButton, robot);
if (!testFocused(fButton)) {
throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused by click");
}
// Test 2.
clickOnCheckFocus(wButton);
clickOnCheckFocus(aButton);
fButton.requestFocus();
Util.waitForIdle(robot);
if (!testFocused(fButton)) {
throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused by request");
}
// Test 3.
clickOnCheckFocus(wButton);
clickOnCheckFocus(aButton);
clickOnCheckFocus(fButton);
clickOnCheckFocus(aButton);
Util.clickOnTitle(owner, robot);
if (!testFocused(fButton)) {
throw new TestFailedException("The owner's component [" + fButton + "] couldn't be focused as the most recent focus owner");
}
System.out.println("Test passed.");
}
void tuneAndShowWindows(Window[] arr) {
int y = 0;
for (Window w: arr) {
w.setLayout(new FlowLayout());
w.setBounds(100, y, 400, 150);
w.setBackground(Color.blue);
w.setVisible(true);
y += 200;
Util.waitForIdle(robot);
}
}
void clickOnCheckFocus(Component c) {
if (c instanceof Frame) {
Util.clickOnTitle((Frame)c, robot);
} else {
Util.clickOnComp(c, robot);
}
if (!testFocused(c)) {
throw new TestErrorException(c + "couldn't get focus by click.");
}
}
boolean testFocused(Component c) {
for (int i=0; i<10; i++) {
if (KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == c) {
return true;
}
Util.waitForIdle(robot);
}
return false;
}
// Thrown when the behavior being verified is found wrong.
class TestFailedException extends RuntimeException {
TestFailedException(String msg) {
super("Test failed: " + msg);
}
}
// Thrown when an error not related to the behavior being verified is encountered.
class TestErrorException extends RuntimeException {
TestErrorException(String msg) {
super("Unexpected error: " + msg);
}
}
}

View File

@ -0,0 +1,211 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4823903
@summary Tests actual focused window retaining.
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main ActualFocusedWindowRetaining
*/
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.*;
import java.applet.*;
import test.java.awt.regtesthelpers.Util;
public class ActualFocusedWindowRetaining extends Applet {
public static Frame frame = new Frame("Other Frame");
public static Frame owner = new Frame("Test Frame");
public static Button otherButton1 = new Button("Other Button 1");
public static Button otherButton2 = new Button("Other Button 2");
public static Button otherButton3 = new Button("Other Button 3");
public static Button testButton1 = new Button("Test Button 1");
public static Button testButton2 = new Button("Test Button 2");
public static Button testButton3 = new Button("Test Button 3");
public static Window window1 = new TestWindow(owner, otherButton2, testButton2, 800, 200);
public static Window window2 = new TestWindow(owner, otherButton3, testButton3, 800, 300);
public static int step;
public static Robot robot = Util.createRobot();
public static void main(String[] args) {
ActualFocusedWindowRetaining a = new ActualFocusedWindowRetaining();
a.init();
a.start();
}
public void start () {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
Object src = e.getSource();
Class cls = src.getClass();
if (cls == TestWindow.class) {
System.out.println(e.paramString() + " on <" + (src == window1 ? "Window 1" : "Window 2") + ">");
} else if (cls == Frame.class) {
System.out.println(e.paramString() + " on <" + ((Frame)src).getTitle() + ">");
} else if (cls == Button.class) {
System.out.println(e.paramString() + " on <" + ((Button)src).getLabel() + ">");
} else {
System.out.println(e.paramString() + " on <Non-testing component>");
}
}
}, AWTEvent.WINDOW_EVENT_MASK | AWTEvent.WINDOW_FOCUS_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
setSize (500, 200);
setVisible(true);
validate();
frame.setSize(new Dimension(400, 100));
frame.setLocation(800, 400);
frame.setVisible(true);
frame.toFront();
owner.setLayout(new FlowLayout());
owner.add(testButton1);
owner.add(otherButton1);
owner.pack();
owner.setLocation(800, 100);
owner.setSize(new Dimension(400, 100));
owner.setVisible(true);
owner.toFront();
Util.waitTillShown(owner);
window1.setVisible(true);
window2.setVisible(true);
window1.toFront();
window2.toFront();
// Wait longer...
Util.waitTillShown(window1);
Util.waitTillShown(window2);
test();
frame.dispose();
owner.dispose();
}
public void test() {
Button[] butArr = new Button[] {testButton3, testButton2, testButton1};
Window[] winArr = new Window[] {window2, window1, owner};
step = 1;
for (int i = 0; i < 3; i++) {
clickInSeriesCheckFocus(null, butArr[i], frame);
clickOwnerCheckFocus(winArr[i], butArr[i]);
step++;
}
step = 4;
clickInSeriesCheckFocus(testButton3, testButton1, frame);
clickOwnerCheckFocus(owner, testButton1);
step = 5;
clickInSeriesCheckFocus(testButton3, testButton2, frame);
clickOwnerCheckFocus(window1, testButton2);
step = 6;
clickInSeriesCheckFocus(testButton1, testButton2, frame);
clickOwnerCheckFocus(window1, testButton2);
step = 7;
clickInSeriesCheckFocus(testButton1, testButton2, frame);
window1.setVisible(false);
Util.waitForIdle(robot);
clickOwnerCheckFocus(owner, testButton1);
step = 8;
window1.setVisible(true);
Util.waitTillShown(window1);
clickInSeriesCheckFocus(null, testButton2, frame);
clickOwnerCheckFocus(window1, testButton2);
}
boolean checkFocusOwner(Component comp) {
return (comp == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
}
boolean checkFocusedWindow(Window win) {
return (win == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
}
void clickOwnerCheckFocus(Window focusedWindow, Component focusedComp) {
Util.clickOnTitle(owner, robot);
robot.delay(500);
if (!checkFocusedWindow(focusedWindow)) {
stopTest("Test failed: actual focused window didn't get a focus");
}
if (!checkFocusOwner(focusedComp)) {
stopTest("Test failed: actual focus owner didn't get a focus");
}
}
void clickInSeriesCheckFocus(Component comp1, Component comp2, Frame frame) {
if (comp1 != null) {
clickOnCheckFocusOwner(comp1);
}
if (comp2 != null) {
clickOnCheckFocusOwner(comp2);
}
clickOnCheckFocusedWindow(frame);
}
void clickOnCheckFocusOwner(Component c) {
Util.clickOnComp(c, robot);
robot.delay(500);
if (!checkFocusOwner(c)) {
stopTest("Error: can't bring a focus on Component by clicking on it");
}
}
void clickOnCheckFocusedWindow(Frame f) {
Util.clickOnTitle(f, robot);
robot.delay(500);
if (!checkFocusedWindow(f)) {
stopTest("Error: can't bring a focus on Frame by clicking on it");
}
}
void stopTest(String msg) {
throw new RuntimeException(new String("Step " + step + ": " + msg));
}
}
class TestWindow extends Window {
TestWindow(Frame owner, Button otherButton, Button testButton, int x, int y) {
super(owner);
setLayout(new FlowLayout());
setLocation(x, y);
add(testButton);
add(otherButton);
pack();
setBackground(Color.green);
}
}

View File

@ -0,0 +1,23 @@
<html>
<!--
@test
@bug 4041703 4096228 4025223 4260929
@summary Ensures that appletviewer sets a reasonable default focus for an Applet on start
@author das area=appletviewer
@library ../../regtesthelpers
@build Util
@run applet AppletInitialFocusTest.html
-->
<head>
<title> AppletInitialFocusTest </title>
</head>
<body>
<h1>AppletInitialFocusTest<br>Bug ID: 4041703</h1>
<p> See the dialog box (usually in upper left corner) for instructions</p>
<APPLET CODE="AppletInitialFocusTest.class" WIDTH=200 HEIGHT=200></APPLET>
</body>
</html>

View File

@ -0,0 +1,59 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
test
@bug 4041703 4096228 4025223 4260929
@summary Ensures that appletviewer sets a reasonable default focus for an Applet on start
@author das area=appletviewer
@run applet AppletInitialFocusTest.html
*/
import java.applet.Applet;
import java.awt.Button;
import java.awt.Component;
import java.awt.Robot;
import java.awt.Window;
import test.java.awt.regtesthelpers.Util;
public class AppletInitialFocusTest extends Applet {
Robot robot = Util.createRobot();
Button button = new Button("Button");
public void init() {
add(button);
}
public void start() {
new Thread(new Runnable() {
public void run() {
Util.waitTillShown(button);
robot.delay(1000); // delay the thread to let EDT to start dispatching focus events
Util.waitForIdle(robot);
if (!button.hasFocus()) {
throw new RuntimeException("Appletviewer doesn't set default focus correctly.");
}
}
}).start();
}
}

View File

@ -0,0 +1,24 @@
<html>
<!--
@test
@bug 4411534 4517274
@summary ensures that user's requestFocus() during applet initialization
is not ignored
@author prs area=appletviewer
@library ../../regtesthelpers
@build Util
@run applet AppletInitialFocusTest1.html
-->
<head>
<title> AppletInitialFocusTest1 </title>
</head>
<body>
<h1>AppletInitialFocusTest1<br>Bug ID: 4517274</h1>
<p> See the dialog box (usually in upper left corner) for instructions</p>
<APPLET CODE="AppletInitialFocusTest1.class" WIDTH=200 HEIGHT=200></APPLET>
</body>
</html>

View File

@ -0,0 +1,71 @@
/*
test %W% %E%
@bug 4411534 4517274
@summary ensures that user's requestFocus() during applet initialization
is not ignored.
@author prs@sparc.spb.su area=appletviewer
@run shell AppletInitialFocusTest1.sh
*/
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class AppletInitialFocusTest1 extends Applet implements FocusListener {
Button button1 = new Button("Button1");
Button button2 = new Button("Button2");
Object lock = new Object();
public void init() {
Component parent = this;
while (parent != null && !(parent instanceof Window)) {
parent = parent.getParent();
}
/*
* This applet is designed to be run only with appletviewer,
* so there always should be a toplevel frame.
*/
if (parent == null) {
synchronized (lock) {
System.err.println("appletviewer not running");
System.exit(3);
}
}
button1.addFocusListener(this);
button2.addFocusListener(this);
add(button1);
add(button2);
button2.requestFocus();
}
public void focusGained(FocusEvent e) {
if (e.getSource() == button1) {
synchronized (lock) {
System.err.println("failed: focus on the wrong button");
System.exit(2);
}
}
}
public void focusLost(FocusEvent e) {
}
public void start() {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(10000);
synchronized (lock) {
System.err.println("passed");
System.exit(0);
}
} catch(InterruptedException e) {
}
}
});
thread.start();
}
}

View File

@ -0,0 +1,110 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test %W% %E%
@bug 6637607
@summary Showing a modal dlg on TAB KEY_PRESS shouldn't consume inappropriate KEY_TYPED.
@author Anton Tarasov: area=awt-focus
@library ../../regtesthelpers
@build Util
@run main ConsumeNextKeyTypedOnModalShowTest
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.lang.reflect.InvocationTargetException;
import test.java.awt.regtesthelpers.Util;
public class ConsumeNextKeyTypedOnModalShowTest extends Applet {
Robot robot;
Frame frame = new Frame("Frame");
Dialog dialog = new Dialog(frame, "Dialog", true);
TextField tf0 = new TextField();
TextField tf1 = new TextField();
Button button = new Button("Button");
public static void main(String[] args) {
ConsumeNextKeyTypedOnModalShowTest app = new ConsumeNextKeyTypedOnModalShowTest();
app.init();
app.start();
}
public void init() {
robot = Util.createRobot();
tf0.setPreferredSize(new Dimension(50, 30));
tf1.setPreferredSize(new Dimension(50, 30));
frame.setLayout(new FlowLayout());
frame.add(tf0);
frame.add(tf1);
frame.pack();
dialog.add(button);
dialog.pack();
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED && e.getSource() == tf0) {
dialog.setVisible(true);
}
}
}, KeyEvent.KEY_EVENT_MASK);
}
public void start() {
frame.setVisible(true);
Util.waitTillShown(frame);
// Show the dialog.
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_TAB);
Util.waitForIdle(robot);
// Dispose the dialog.
Runnable action = new Runnable() {
public void run() {
dialog.dispose();
}
};
if (!Util.trackFocusGained(tf1, action, 2000, false)) {
throw new RuntimeException("Test failed: TAB was processed incorrectly!");
}
// Check for type-ability.
robot.keyPress(KeyEvent.VK_A);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_A);
Util.waitForIdle(robot);
if (tf1.getText().equals("")) {
throw new RuntimeException("Test failed: couldn't type a char!");
}
System.out.println("Test passed.");
}
}

View File

@ -0,0 +1,86 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4752312
@summary Tests that after moving non-focusable window it ungrabs mouse pointer
@author Denis Mikhalkin: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main FrameJumpingToMouse
*/
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.TextArea;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import javax.swing.JFrame;
import test.java.awt.regtesthelpers.Util;
public class FrameJumpingToMouse extends Applet
{
JFrame frame = new JFrame("Test jumping frame");
Robot robot = Util.createRobot();
public static void main(String[] args) {
FrameJumpingToMouse test = new FrameJumpingToMouse();
test.init();
test.start();
}
public void init() {
frame.setFocusableWindowState(false);
frame.setBounds(100, 100, 100, 100);
}
public void start() {
frame.setVisible(true);
Util.waitTillShown(frame);
Point loc = frame.getLocationOnScreen();
robot.mouseMove(loc.x + frame.getWidth() / 4, loc.y + frame.getInsets().top / 2);
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseMove(loc.x + 100, loc.y + 50);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
Util.waitForIdle(robot);
loc = frame.getLocation();
robot.mouseMove(loc.x + frame.getWidth() / 2, loc.y + frame.getHeight() / 2);
Util.waitForIdle(robot);
if (!(frame.getLocation().equals(loc))) {
throw new RuntimeException("Test failed: frame is moving to mouse with grab!");
}
System.out.println("Test passed.");
}
}

View File

@ -0,0 +1,420 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4452384
@summary Tests that non-focusable windows doesn't generate any focus events when accessed.
@author Denis.Mikhalkin: area=awt.focus
@run main NoEventsTest
*/
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class NoEventsTest extends Frame {
public static final int DEF_WIDTH = 400,
DEF_HEIGHT = 300,
DEF_TOP = 1,
DEF_LEFT = 100,
DEF_ROW = 0,
DEF_COL = 0;
static boolean automatic = true;
static Window[] windows;
static Frame main_frame, jumpingFrame;
static Button focus_button;
static Robot robot;
static void pause(int timeout) {
Toolkit.getDefaultToolkit().sync();
robot.waitForIdle();
robot.delay(100);
}
static GlobalListener listener;
public static void main(String[] args) {
listener = new GlobalListener();
Toolkit.getDefaultToolkit().addAWTEventListener(listener,
AWTEvent.FOCUS_EVENT_MASK |
AWTEvent.WINDOW_EVENT_MASK);
try{
robot = new Robot();
} catch(Exception e) {}
// Create several pairs - focusable Frame with focusable component(button) and non-focusable:
// window, resizable frame, non-resizable frame, dialog, non-resiable dialog
main_frame = new Frame("focusable frame");
focus_button = new Button("button to focus");
main_frame.add(focus_button);
main_frame.pack();
main_frame.setVisible(true);
main_frame.setLocation(10, 600);
main_frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
listener.report();
System.exit(0);
}
});
jumpingFrame = new Frame("Jumping frame");
jumpingFrame.setBounds(DEF_LEFT, DEF_TOP, DEF_WIDTH, DEF_HEIGHT);
windows = new Window[7];
windows[0] = new TestWindow(0, 0, false, main_frame);
//windows[1] = new TestWindow(2, 1, true, main_frame);
windows[2] = new NoEventsTest(1, 0, false, true);
windows[3] = new NoEventsTest(2, 0, false, false);
//windows[4] = new Test(3, 0, true, true);
windows[5] = new TestDialog(0, 1, false, true, main_frame);
windows[6] = new TestDialog(1, 1, false, false, main_frame);
if (!automatic) {
int windowInd;
for (windowInd = 0; windowInd < windows.length; windowInd++) {
if (windows[windowInd] != null) {
windows[windowInd].setVisible(true);
}
}
}
// Run the test
// 1. Click on all controls, check for no focus events for non-focusable, right focus events for focusable
// 2. Perform some action with control, check if it works
if (automatic) {
int windowInd;
for (windowInd = 0; windowInd < windows.length; windowInd++) {
if (windows[windowInd] != null) {
windows[windowInd].setVisible(true);
focus_button.requestFocus();
pause(1000);
// Verify that click on non-focusable window causes no focus lost on active window
performFocusClick(windows[windowInd]);
focus_button.requestFocus();
pause(500);
performActionClick(windows[windowInd]);
// Verify that toFront, toBack doesn't cause non-focusable window to become active
jumpingFrame.setVisible(true);
pause(1000);
jumpingFrame.toBack();
pause(500);
jumpingFrame.toFront();
pause(500);
windows[windowInd].toBack();
pause(500);
windows[windowInd].toFront();
pause(500);
// Verify that iconifiyng/deiconfiying and
// zooming/unzooming doesn't cause non-focusable
// window to become active
if (windows[windowInd] instanceof Frame) {
Frame toTest = (Frame)windows[windowInd];
// Deiconification currently doesn't work!
// toTest.setExtendedState(Frame.ICONIFIED);
// pause(500);
// toTest.setExtendedState(Frame.NORMAL);
pause(500);
toTest.setExtendedState(Frame.MAXIMIZED_BOTH);
pause(500);
toTest.setExtendedState(Frame.NORMAL);
}
windows[windowInd].dispose();
jumpingFrame.dispose();
}
}
pause(1000);
System.err.println("Test finished.");
if (!listener.report()) {
throw new RuntimeException("Test Failed. See error stream output for details");
}
}
}
static void performFocusClick(Window parent) {
if (parent == null) {
return;
}
for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
Component child = parent.getComponent(compInd);
if (child instanceof TestPanel) {
TestPanel pan = (TestPanel)child;
pan.performFocusClicks(robot);
pause(100);
}
}
}
static void performActionClick(Window parent) {
if (parent == null) {
return;
}
for (int compInd = 0; compInd < parent.getComponentCount(); compInd++) {
Component child = parent.getComponent(compInd);
if (child instanceof TestPanel) {
TestPanel pan = (TestPanel)child;
pan.performActionClicks(robot);
pause(100);
}
}
}
public NoEventsTest(int row, int col, boolean focusable, boolean resizable) {
super("Frame" + row + "" + col);
TestPanel panel = new TestPanel(row, col);
if (NoEventsTest.automatic) {
row = NoEventsTest.DEF_ROW;
col = NoEventsTest.DEF_COL;
}
setName(getTitle());
add("Center", panel);
Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
", " + (resizable?"resizable":"non-resizable"));
l.setBackground(Color.green);
add("North", l);
setBounds(NoEventsTest.DEF_LEFT + DEF_WIDTH*col, DEF_TOP + DEF_HEIGHT*row, DEF_WIDTH, DEF_HEIGHT);
if (!focusable) {
setFocusableWindowState(false);
}
if (!resizable) {
setResizable(false);
}
// setVisible(true);
}
}
class TestWindow extends Window {
public TestWindow(int row, int col, boolean focusable, Frame owner) {
super(owner);
setName("Window" + row + "" + col);
TestPanel panel = new TestPanel(row, col);
if (NoEventsTest.automatic) {
row = NoEventsTest.DEF_ROW;
col = NoEventsTest.DEF_COL;
}
add("Center", panel);
Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
", " + (false?"resizable":"non-resizable"));
l.setBackground(Color.green);
add("North", l);
setBounds(NoEventsTest.DEF_LEFT + NoEventsTest.DEF_WIDTH*col, NoEventsTest.DEF_TOP + NoEventsTest.DEF_HEIGHT*row, NoEventsTest.DEF_WIDTH, NoEventsTest.DEF_HEIGHT);
if (!focusable) {
setFocusableWindowState(false);
}
// setVisible(true);
}
}
class TestDialog extends Dialog {
public TestDialog(int row, int col, boolean focusable, boolean resizable, Frame owner) {
super(owner);
setName("Dialog" + row + "" + col);
TestPanel panel = new TestPanel(row, col);
if (NoEventsTest.automatic) {
row = NoEventsTest.DEF_ROW;
col = NoEventsTest.DEF_COL;
}
add("Center", panel);
Label l = new Label(getClass().getSuperclass().getName() + ", " + (focusable?"focusable":"non-focusable") +
", " + (resizable?"resizable":"non-resizable"));
l.setBackground(Color.green);
add("North", l);
setBounds(NoEventsTest.DEF_LEFT + NoEventsTest.DEF_WIDTH*col, NoEventsTest.DEF_TOP + NoEventsTest.DEF_HEIGHT*row, NoEventsTest.DEF_WIDTH, NoEventsTest.DEF_HEIGHT);
if (!focusable) {
setFocusableWindowState(false);
}
if (!resizable) {
setResizable(false);
}
// setVisible(true);
}
}
class TestPanel extends Panel {
void clickComponent(Component comp, Robot robot) {
if (comp instanceof Choice) {
return;
}
Point compLoc = comp.getLocationOnScreen();
Dimension size = comp.getSize();
robot.mouseMove(compLoc.x + size.width/2, compLoc.y + size.height/2);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
void performFocusClicks(Robot robot) {
for (int childInd = 0; childInd < getComponentCount(); childInd++) {
performFocusClick(getComponent(childInd), robot);
}
}
void performFocusClick(Component comp, Robot robot) {
clickComponent(comp, robot);
}
void performActionClicks(Robot robot) {
for (int childInd = 0; childInd < getComponentCount(); childInd++) {
performActionClick(getComponent(childInd), robot);
}
}
void performActionClick(Component comp, Robot robot) {
}
public TestPanel(int row, int col) {
setLayout(new FlowLayout());
Button b;
add(b = new Button("press"+ row + "" + col));
b.setName(b.getLabel());
// b.addMouseListener(new MouseAdapter() {
// public void mousePressed(MouseEvent e) {
// System.err.println(e);
// }
// });
TextField t;
add(t = new TextField("text" + row + "" + col));
t.setName(t.getText());
java.awt.List list = new java.awt.List();
add(list);
list.setName("list");
list.add("one");
list.add("two");
list.add("three");
list.setMultipleMode(true);
list.setName("list" + row + "" + col);
Checkbox check = new Checkbox("checker");
add(check);
check.setName("check" + row + "" + col);
Choice choice = new Choice();
choice.add("one");
choice.add("two");
choice.add("three");
add(choice);
choice.setName("choice" + row + "" + col);
Canvas can = new Canvas() {
public Dimension getPreferredSize() {
return new Dimension(10, 10);
}
};
can.setBackground(Color.blue);
add(can);
can.setName("canvas" + row + "" + col);
TextArea ta = new TextArea("text\ntttt\naaaa\nwwwww\nqqqqqq\neeeeee\nrrrrrr\nyyyyyy\nuuuuu", 3, 5);
add(ta);
ta.setName("textarea" + row + "" + col);
Scrollbar bar = new Scrollbar(Scrollbar.HORIZONTAL);
add(bar);
bar.setName("scrollbar" + row + "" + col);
CheckboxGroup group = new CheckboxGroup();
Checkbox ch1 = new Checkbox("one", group, true);
Checkbox ch2 = new Checkbox("two", group, false);
add(ch1);
add(ch2);
ch1.setName("checkbox1 " + row + "" + col);
ch2.setName("checkbox2 " + row + "" + col);
ScrollPane pane = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
add(pane);
Button bigButton = new Button("abc") {
public Dimension getPreferredSize() {
return new Dimension(100, 100);
}
};
pane.add(bigButton);
bigButton.setName("bigbutton" + row + "" + col);
}
}
class GlobalListener implements AWTEventListener {
java.util.List errors = new java.util.LinkedList();
public boolean report() {
if (errors.size() != 0) {
System.err.println("Test FAILED");
} else {
System.err.println("Test PASSED");
return true;
}
ListIterator iter = errors.listIterator();
while (iter.hasNext()) {
System.err.println(iter.next());
}
return false;
}
public GlobalListener() {
}
Window getWindowParent(Component comp) {
while (comp != null && !(comp instanceof Window)) {
comp = comp.getParent();
}
return (Window)comp;
}
void reportError(AWTEvent e, String message) {
String error = "ERROR: " + message + " : " + e;
errors.add(error);
System.err.println(error);
}
public void eventDispatched(AWTEvent e) {
Component comp = (Component)e.getSource();
Window parent = getWindowParent(comp);
if (!(e instanceof WindowEvent || e instanceof FocusEvent)) {
System.err.println("Strange event " + e);
}
// Skip WINDOW_OPENED
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.err.println(e);
}
switch (e.getID()) {
case WindowEvent.WINDOW_OPENED:
case WindowEvent.WINDOW_CLOSING:
case WindowEvent.WINDOW_CLOSED:
case WindowEvent.WINDOW_ICONIFIED:
case WindowEvent.WINDOW_DEICONIFIED:
case WindowEvent.WINDOW_STATE_CHANGED:
return;
case WindowEvent.WINDOW_LOST_FOCUS: {
WindowEvent we = (WindowEvent)e;
if (we.getOppositeWindow() != null && !we.getOppositeWindow().getFocusableWindowState()) {
reportError(e, "frame lost focus because of non-focusable window");
}
break;
}
}
// Check that Window owner is focusable
if (!parent.getFocusableWindowState()) {
reportError(e, "focus event for component in non-focusable window " + parent.getName());
}
if (!comp.isFocusable()) {
reportError(e, "focus event for non-focusable component");
}
// if (e instanceof WindowEvent || e instanceof FocusEvent) {
// // System.err.println(e);
// }
}
}

View File

@ -0,0 +1,159 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 6182359
@summary Tests that Window having non-focusable owner can't be a focus owner.
@author Anton.Tarasov: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main NonfocusableOwnerTest
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.lang.reflect.*;
import java.io.*;
import test.java.awt.regtesthelpers.Util;
public class NonfocusableOwnerTest extends Applet {
Robot robot = Util.createRobot();
Frame frame;
Dialog dialog;
Window window1;
Window window2;
Button button = new Button("button");
public static void main(String[] args) {
NonfocusableOwnerTest test = new NonfocusableOwnerTest();
test.start();
}
public void start() {
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e) {
System.out.println(e.toString());
}
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK);
frame = new Frame("Frame");
frame.setName("Frame-owner");
frame.setBounds(100, 0, 100, 100);
dialog = new Dialog(frame, "Dialog");
dialog.setName("Dialog-owner");
dialog.setBounds(100, 0, 100, 100);
window1 = new Window(frame);
window1.setName("1st child");
window1.setBounds(100, 300, 100, 100);
window2 = new Window(window1);
window2.setName("2nd child");
window2.setBounds(100, 500, 100, 100);
test1(frame, window1);
test2(frame, window1, window2);
test3(frame, window1, window2);
window1 = new Window(dialog);
window1.setBounds(100, 300, 100, 100);
window1.setName("1st child");
window2 = new Window(window1);
window2.setName("2nd child");
window2.setBounds(100, 500, 100, 100);
test1(dialog, window1);
test2(dialog, window1, window2);
test3(dialog, window1, window2);
System.out.println("Test passed.");
}
void test1(Window owner, Window child) {
System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);
owner.setFocusableWindowState(false);
owner.setVisible(true);
child.add(button);
child.setVisible(true);
Util.waitTillShown(child);
Util.clickOnComp(button, robot);
if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
throw new RuntimeException("Test Failed.");
}
child.dispose();
owner.dispose();
}
void test2(Window owner, Window child1, Window child2) {
System.out.println("* * * STAGE 2 * * *\nWindow nowner: " + owner);
owner.setFocusableWindowState(false);
owner.setVisible(true);
child1.setFocusableWindowState(true);
child1.setVisible(true);
child2.add(button);
child2.setVisible(true);
Util.waitTillShown(child2);
Util.clickOnComp(button, robot);
if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
throw new RuntimeException("Test failed.");
}
child2.dispose();
child1.dispose();
owner.dispose();
}
void test3(Window owner, Window child1, Window child2) {
System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);
owner.setFocusableWindowState(true);
owner.setVisible(true);
child1.setFocusableWindowState(false);
child1.setVisible(true);
child2.setFocusableWindowState(true);
child2.add(button);
child2.setVisible(true);
Util.waitTillShown(child2);
Util.clickOnComp(button, robot);
System.err.println("focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());
if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {
throw new RuntimeException("Test failed.");
}
child1.dispose();
child2.dispose();
owner.dispose();
}
}

View File

@ -0,0 +1,139 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 6183877 6216005 6225560
@library ../../regtesthelpers
@build Util
@summary Tests that keyboard input doesn't freeze due to type-ahead problems
@author Denis.Mikhalkin, Anton.Tarasov: area=awt.focus
@run main TestFocusFreeze
*/
import java.awt.Component;
import java.awt.DefaultKeyboardFocusManager;
import java.awt.KeyboardFocusManager;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import test.java.awt.regtesthelpers.Util;
public class TestFocusFreeze {
private static JFrame frame;
private static JDialog dialog;
private static JButton dlgButton;
private static JButton frameButton;
private static AtomicBoolean lock = new AtomicBoolean(false);
private static Robot robot = Util.createRobot();
public static void main(String[] args) {
boolean all_passed = true;
KeyboardFocusManager testKFM = new TestKFM(robot);
KeyboardFocusManager defKFM = KeyboardFocusManager.getCurrentKeyboardFocusManager();
for (int i = 0; i < 10; i++) {
test(testKFM, defKFM);
Util.waitForIdle(robot);
System.out.println("Iter " + i + ": " + (lock.get() ? "passed." : "failed!"));
if (!lock.get()) {
all_passed = false;
}
}
if (!all_passed) {
throw new RuntimeException("Test failed: not all iterations passed!");
}
System.out.println("Test passed.");
}
public static void test(final KeyboardFocusManager testKFM, final KeyboardFocusManager defKFM) {
frame = new JFrame("Frame");
dialog = new JDialog(frame, "Dialog", true);
dlgButton = new JButton("Dialog_Button");
frameButton = new JButton("Frame_Button");
lock.set(false);
dialog.add(dlgButton);
dialog.setLocation(200, 0);
dialog.pack();
frame.add(frameButton);
frame.pack();
dlgButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
frame.dispose();
synchronized (lock) {
lock.set(true);
lock.notifyAll();
}
}
});
frameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Right before the dialog will be shown, there will be called
// enqueuKeyEvents() method. We are to catch it.
KeyboardFocusManager.setCurrentKeyboardFocusManager(testKFM);
dialog.setVisible(true);
KeyboardFocusManager.setCurrentKeyboardFocusManager(defKFM);
}
});
Runnable showAction = new Runnable() {
public void run() {
frame.setVisible(true);
}
};
if (!Util.trackFocusGained(frameButton, showAction, 2000, false)) {
System.out.println("Test error: wrong initial focus!");
return;
}
robot.keyPress(KeyEvent.VK_SPACE);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_SPACE);
Util.waitForCondition(lock, 2000);
Util.waitForIdle(robot);
}
}
class TestKFM extends DefaultKeyboardFocusManager {
Robot robot;
public TestKFM(Robot robot) {
this.robot = robot;
}
protected synchronized void enqueueKeyEvents(long after, Component untilFocused) {
super.enqueueKeyEvents(after, untilFocused);
robot.keyPress(KeyEvent.VK_SPACE);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_SPACE);
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright 2008 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
@test
@bug 4782886
@summary FocusManager consumes wrong KEY_TYPED events
@author Oleg.Sukhodolsky: area=awt.focus
@library ../../regtesthelpers
@build Util
@run main WrongKeyTypedConsumedTest
*/
import java.applet.Applet;
import java.awt.AWTException;
import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.Robot;
import java.awt.TextArea;
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import test.java.awt.regtesthelpers.Util;
public class WrongKeyTypedConsumedTest extends Applet
{
Robot robot = Util.createRobot();
public static void main(String[] args) {
WrongKeyTypedConsumedTest test = new WrongKeyTypedConsumedTest();
test.start();
}
public void start ()
{
setSize (200,200);
setVisible(true);
validate();
JFrame frame = new JFrame("The Frame");
Set ftk = new HashSet();
ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
frame.getContentPane().
setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
ftk);
JCheckBox checkbox = new JCheckBox("test");
frame.getContentPane().add(checkbox, BorderLayout.NORTH);
JTextArea textarea = new JTextArea(40, 10);
frame.getContentPane().add(textarea);
frame.pack();
frame.setVisible(true);
Util.waitForIdle(robot);
if (!frame.isActive()) {
throw new RuntimeException("Test Fialed: frame isn't active");
}
// verify if checkbox has focus
if (!checkbox.isFocusOwner()) {
checkbox.requestFocusInWindow();
Util.waitForIdle(robot);
if (!checkbox.isFocusOwner()) {
throw new RuntimeException("Test Failed: checkbox doesn't have focus");
}
}
// press VK_DOWN
robot.keyPress(KeyEvent.VK_DOWN);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.delay(50);
Util.waitForIdle(robot);
// verify if text area has focus
if (!textarea.isFocusOwner()) {
throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
}
// press '1'
robot.keyPress(KeyEvent.VK_1);
robot.delay(50);
robot.keyRelease(KeyEvent.VK_1);
robot.delay(50);
Util.waitForIdle(robot);
// verify if KEY_TYPED arrived
if (!"1".equals(textarea.getText())) {
throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
}
System.out.println("Test Passed");
}
}