提交 a60768a9 编写于 作者: A ant

7125044: [macosx] Test failure because Component.transferFocus() works...

7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
Summary: forward port from 7u4
Reviewed-by: art
上级 8f537f5e
......@@ -670,7 +670,7 @@ public class Dialog extends Window {
this.title = title;
setModalityType(modalityType);
SunToolkit.checkAndSetPolicy(this, false);
SunToolkit.checkAndSetPolicy(this);
}
/**
......@@ -721,7 +721,7 @@ public class Dialog extends Window {
this.title = title;
setModalityType(modalityType);
SunToolkit.checkAndSetPolicy(this, false);
SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -449,7 +449,7 @@ public class Frame extends Window implements MenuContainer {
private void init(String title, GraphicsConfiguration gc) {
this.title = title;
SunToolkit.checkAndSetPolicy(this, false);
SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -506,7 +506,7 @@ public class Window extends Container implements Accessible {
modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE;
SunToolkit.checkAndSetPolicy(this, false);
SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -149,7 +149,7 @@ public class JApplet extends Applet implements Accessible,
setRootPaneCheckingEnabled(true);
setFocusTraversalPolicyProvider(true);
sun.awt.SunToolkit.checkAndSetPolicy(this, true);
sun.awt.SunToolkit.checkAndSetPolicy(this);
enableEvents(AWTEvent.KEY_EVENT_MASK);
}
......
......@@ -654,7 +654,7 @@ public class JDialog extends Dialog implements WindowConstants,
getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
}
}
sun.awt.SunToolkit.checkAndSetPolicy(this, true);
sun.awt.SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -266,7 +266,7 @@ public class JFrame extends Frame implements WindowConstants,
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
}
}
sun.awt.SunToolkit.checkAndSetPolicy(this, true);
sun.awt.SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -349,7 +349,7 @@ public class JInternalFrame extends JComponent implements
setRootPaneCheckingEnabled(true);
desktopIcon = new JDesktopIcon(this);
updateUI();
sun.awt.SunToolkit.checkAndSetPolicy(this, true);
sun.awt.SunToolkit.checkAndSetPolicy(this);
addPropertyChangeListenerIfNecessary();
}
......
......@@ -264,7 +264,7 @@ public class JWindow extends Window implements Accessible,
setLocale( JComponent.getDefaultLocale() );
setRootPane(createRootPane());
setRootPaneCheckingEnabled(true);
sun.awt.SunToolkit.checkAndSetPolicy(this, true);
sun.awt.SunToolkit.checkAndSetPolicy(this);
}
/**
......
......@@ -191,6 +191,7 @@ public class UIManager implements Serializable
private UIDefaults[] tables = new UIDefaults[2];
boolean initialized = false;
boolean focusPolicyInitialized = false;
MultiUIDefaults multiUIDefaults = new MultiUIDefaults(tables);
LookAndFeel lookAndFeel;
LookAndFeel multiLookAndFeel = null;
......@@ -1000,6 +1001,7 @@ public class UIManager implements Serializable
*/
public static ComponentUI getUI(JComponent target) {
maybeInitialize();
maybeInitializeFocusPolicy(target);
ComponentUI ui = null;
LookAndFeel multiLAF = getLAFState().multiLookAndFeel;
if (multiLAF != null) {
......@@ -1422,6 +1424,27 @@ public class UIManager implements Serializable
}
}
/*
* Sets default swing focus traversal policy.
*/
private static void maybeInitializeFocusPolicy(JComponent comp) {
// Check for JRootPane which indicates that a swing toplevel
// is coming, in which case a swing default focus policy
// should be instatiated. See 7125044.
if (comp instanceof JRootPane) {
synchronized (classLock) {
if (!getLAFState().focusPolicyInitialized) {
getLAFState().focusPolicyInitialized = true;
if (FocusManager.isFocusManagerEnabled()) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setDefaultFocusTraversalPolicy(
new LayoutFocusTraversalPolicy());
}
}
}
}
}
/*
* Only called by maybeInitialize().
......@@ -1433,17 +1456,6 @@ public class UIManager implements Serializable
initializeAuxiliaryLAFs(swingProps);
initializeInstalledLAFs(swingProps);
// Enable the Swing default LayoutManager.
String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
// don't set default policy if this is XAWT.
if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
if (FocusManager.isFocusManagerEnabled()) {
KeyboardFocusManager.getCurrentKeyboardFocusManager().
setDefaultFocusTraversalPolicy(
new LayoutFocusTraversalPolicy());
}
}
// Install Swing's PaintEventDispatcher
if (RepaintManager.HANDLE_TOP_LEVEL_PAINT) {
sun.awt.PaintEventDispatcher.setPaintEventDispatcher(
......
......@@ -461,48 +461,11 @@ public abstract class SunToolkit extends Toolkit
AWTAccessor.getWindowAccessor().setLWRequestStatus(changed, status);
};
public static void checkAndSetPolicy(Container cont, boolean isSwingCont)
{
FocusTraversalPolicy defaultPolicy = KeyboardFocusManager
.getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy();
String toolkitName = Toolkit.getDefaultToolkit().getClass().getName();
// if this is not XAWT then use default policy
// because Swing change it
if (!"sun.awt.X11.XToolkit".equals(toolkitName)) {
cont.setFocusTraversalPolicy(defaultPolicy);
return;
}
String policyName = defaultPolicy.getClass().getName();
if (DefaultFocusTraversalPolicy.class != defaultPolicy.getClass()) {
// Policy was changed
// Check if it is awt policy or swing policy
// If it is Swing policy we shouldn't use it in AWT frames
// If it is AWT policy we shouldn't use it in Swing frames
// Otherwise we should use this policy
if (policyName.startsWith("java.awt.")) {
// AWT
if (isSwingCont) {
// Can't use AWT policy in Swing windows - should use Swing's one.
defaultPolicy = createLayoutPolicy();
} else {
// New awt policy.
}
} else if (policyName.startsWith("javax.swing.")) {
if (isSwingCont) {
// New Swing's policy
} else {
defaultPolicy = new DefaultFocusTraversalPolicy();
}
}
} else {
// Policy is default, use different default policy for swing
if (isSwingCont) {
defaultPolicy = createLayoutPolicy();
}
}
public static void checkAndSetPolicy(Container cont) {
FocusTraversalPolicy defaultPolicy = KeyboardFocusManager.
getCurrentKeyboardFocusManager().
getDefaultFocusTraversalPolicy();
cont.setFocusTraversalPolicy(defaultPolicy);
}
......
/*
@test
@bug 7125044
@summary Tests defaut focus traversal policy in AWT & Swing toplevel windows.
@author anton.tarasov@sun.com: area=awt.focus
@run main InitialFTP_AWT
@run main InitialFTP_Swing
*/
import java.awt.FocusTraversalPolicy;
import java.awt.Window;
public class InitialFTP {
public static void test(Window win, Class<? extends FocusTraversalPolicy> expectedPolicy) {
FocusTraversalPolicy ftp = win.getFocusTraversalPolicy();
System.out.println("==============" + "\n" +
"Tested window: " + win + "\n" +
"Expected policy: " + expectedPolicy + "\n" +
"Effective policy: " + ftp.getClass());
if (!expectedPolicy.equals(ftp.getClass())) {
throw new RuntimeException("Test failed: wrong effective focus policy");
}
}
}
/*
@bug 7125044
@summary Tests default focus traversal policy in AWT toplevel windows.
@author anton.tarasov@sun.com: area=awt.focus
*/
import java.awt.Button;
import java.awt.DefaultFocusTraversalPolicy;
import java.awt.FlowLayout;
import java.awt.FocusTraversalPolicy;
import java.awt.Frame;
import java.awt.List;
import java.awt.TextArea;
import java.awt.Window;
public class InitialFTP_AWT {
public static void main(String[] args) {
AWTFrame f0 = new AWTFrame("frame0");
f0.setVisible(true);
InitialFTP.test(f0, DefaultFocusTraversalPolicy.class);
AWTFrame f1 = new AWTFrame("frame1");
f1.setVisible(true);
InitialFTP.test(f1, DefaultFocusTraversalPolicy.class);
System.out.println("Test passed.");
}
}
class AWTFrame extends Frame {
Button button = new Button("button");
TextArea text = new TextArea("qwerty");
List list = new List();
public AWTFrame(String title) {
super(title);
list.add("one");
list.add("two");
list.add("three");
this.setLayout(new FlowLayout());
this.add(button);
this.add(text);
this.add(list);
this.pack();
}
}
/*
@bug 7125044
@summary Tests default focus traversal policy in Swing toplevel windows.
@author anton.tarasov@sun.com: area=awt.focus
*/
import java.awt.FlowLayout;
import java.awt.FocusTraversalPolicy;
import java.awt.Window;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.LayoutFocusTraversalPolicy;
public class InitialFTP_Swing {
public static void main(String[] args) {
SwingFrame f0 = new SwingFrame("frame0");
f0.setVisible(true);
InitialFTP.test(f0, LayoutFocusTraversalPolicy.class);
SwingFrame f1 = new SwingFrame("frame1");
f1.setVisible(true);
InitialFTP.test(f1, LayoutFocusTraversalPolicy.class);
System.out.println("Test passed.");
}
}
class SwingFrame extends JFrame {
JButton button = new JButton("button");
JTextArea text = new JTextArea("qwerty");
JList list = new JList(new String[] {"one", "two", "three"});
public SwingFrame(String title) {
super(title);
this.setLayout(new FlowLayout());
this.add(button);
this.add(text);
this.add(list);
this.pack();
}
}
/*
* Copyright (c) 2012, 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 7154072
@summary Tests that key events with modifiers are not swallowed.
@author anton.tarasov: area=awt.focus
@library ../../../regtesthelpers
@build Util
@run main SwallowKeyEvents
*/
import java.awt.AWTException;
import java.awt.Frame;
import java.awt.Robot;
import java.awt.TextField;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import test.java.awt.regtesthelpers.Util;
public class SwallowKeyEvents {
static final int PRESS_COUNT = 10;
static int keyPressedCount = 0;
static Frame f = new Frame("Frame");
static TextField t = new TextField("text");
static Robot r;
public static void main(String[] args) {
f.add(t);
f.pack();
f.setVisible(true);
t.requestFocus();
try {
r = new Robot();
} catch (AWTException ex) {
throw new RuntimeException(ex);
}
Util.waitForIdle(r);
t.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ke) {
System.out.println(ke);
if (ke.getKeyCode() == KeyEvent.VK_M) {
keyPressedCount++;
}
}
});
test();
System.out.println("key_pressed count: " + keyPressedCount);
if (keyPressedCount != PRESS_COUNT) {
throw new RuntimeException("Test failed!");
} else {
System.out.println("Test passed.");
}
}
public static void test() {
r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(KeyEvent.VK_META);
for (int i=0; i<PRESS_COUNT; i++) {
r.delay(100);
r.keyPress(KeyEvent.VK_M);
r.delay(100);
r.keyRelease(KeyEvent.VK_M);
}
r.keyRelease(KeyEvent.VK_META);
r.keyRelease(KeyEvent.VK_SHIFT);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册