Index: j2se/src/share/classes/java/awt/KeyboardFocusManager.java =================================================================== --- j2se/src/share/classes/java/awt/KeyboardFocusManager.java (revision 237) +++ j2se/src/share/classes/java/awt/KeyboardFocusManager.java (working copy) @@ -45,9 +45,12 @@ import java.util.StringTokenizer; import java.util.WeakHashMap; import java.util.logging.*; + import sun.awt.AppContext; import sun.awt.DebugHelper; +import sun.awt.DummyKeyboardFocusManagerPeer; import sun.awt.HeadlessToolkit; +import sun.awt.KeyboardFocusManagerPeerProvider; import sun.awt.SunToolkit; import sun.awt.CausedFocusEvent; @@ -413,12 +416,14 @@ } private void initPeer() { - if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit){ - peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this); + Toolkit tk = Toolkit.getDefaultToolkit(); + if (tk instanceof KeyboardFocusManagerPeerProvider) { + KeyboardFocusManagerPeerProvider kfmp = + (KeyboardFocusManagerPeerProvider) tk; + peer = kfmp.createKeyboardFocusManagerPeer(this); + } else { + peer = new DummyKeyboardFocusManagerPeer(); } - if (Toolkit.getDefaultToolkit() instanceof SunToolkit){ - peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this); - } } /** Index: j2se/src/share/classes/sun/awt/SunToolkit.java =================================================================== --- j2se/src/share/classes/sun/awt/SunToolkit.java (revision 237) +++ j2se/src/share/classes/sun/awt/SunToolkit.java (working copy) @@ -64,7 +64,7 @@ public abstract class SunToolkit extends Toolkit implements WindowClosingSupport, WindowClosingListener, - ComponentFactory, InputMethodSupport { + ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider { private static final Logger log = Logger.getLogger("sun.awt.SunToolkit"); Index: j2se/src/share/classes/sun/awt/HeadlessToolkit.java =================================================================== --- j2se/src/share/classes/sun/awt/HeadlessToolkit.java (revision 237) +++ j2se/src/share/classes/sun/awt/HeadlessToolkit.java (working copy) @@ -44,7 +44,7 @@ import sun.awt.image.ImageRepresentation; public class HeadlessToolkit extends Toolkit - implements ComponentFactory { + implements ComponentFactory, KeyboardFocusManagerPeerProvider { private Toolkit tk; private ComponentFactory componentFactory; Index: j2se/src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java =================================================================== --- j2se/src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java (revision 0) +++ j2se/src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java (revision 0) @@ -0,0 +1,48 @@ +/* + * Copyright 2007 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.awt; + +import java.awt.KeyboardFocusManager; +import java.awt.peer.KeyboardFocusManagerPeer; + +/** + * Provides a {@link KeyboardFocusManagerPeer}. This has to be implemented by + * {@link java.awt.Toolkit}s that provide a KeyboardFocusManagerPeer. + * The method {@link KeyboardFocusManager#initPeer()} checks the current + * toolkit if it implements this interface. If not, a dummy + * ({@link DummyKeyboardFocusManagerPeer} is used, which does nothing. + * + * @author Roman Kennke (roman.kennke@aicas.com) + */ +public interface KeyboardFocusManagerPeerProvider { + + /** + * Creates a KeyboardFocusManagerPeer for the specified + * KeyboardFocusManager. + */ + KeyboardFocusManagerPeer + createKeyboardFocusManagerPeer(KeyboardFocusManager m); +} Index: j2se/src/share/classes/sun/awt/DummyKeyboardFocusManagerPeer.java =================================================================== --- j2se/src/share/classes/sun/awt/DummyKeyboardFocusManagerPeer.java (revision 0) +++ j2se/src/share/classes/sun/awt/DummyKeyboardFocusManagerPeer.java (revision 0) @@ -0,0 +1,67 @@ +/* + * Copyright 2007 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. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the LICENSE file that accompanied this code. + * + * 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. + */ + +package sun.awt; + +import java.awt.Component; +import java.awt.Window; +import java.awt.peer.KeyboardFocusManagerPeer; + +/** + * A dummy implementation for {@link KeyboardFocusManagerPeer} that is used + * when the current toolkit can't provide a KeyboardFocusManagerPeer. This + * is basically a no-op implementation. + * + * @author Roman Kennke (roman.kennke@aicas.com) + */ +public class DummyKeyboardFocusManagerPeer + implements KeyboardFocusManagerPeer { + + public DummyKeyboardFocusManagerPeer() { + } + + public void setCurrentFocusedWindow(Window win) { + // We do nothing here. + } + + public Window getCurrentFocusedWindow() { + // We do nothing here. + return null; + } + + public void setCurrentFocusOwner(Component comp) { + // We do nothing here. + } + + public Component getCurrentFocusOwner() { + // We do nothing here. + return null; + } + + public void clearGlobalFocusOwner(Window activeWindow) { + // We do nothing here. + } + +}