JDK-6580829 : provide a plugin toolkit developer with new sun.awt.KeyboardFocusManagerPeerProvider iface
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-07-16
  • Updated: 2017-05-16
  • Resolved: 2011-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b21Fixed
Description
Defacto, AWT doesn't support plugin toolkits. There're quite a few hidden dependencies
b/w public and private code in AWT. However, it's probably worth making a few
steps towards the developers community showing interest in this question.

This CR requests AWT to make some change in its private code that would allow
to overcome one of the barriers on the way of plugging in a custom toolkit.
Namely, AWT should consider providing a new sun.awt.KeyboardFocusManagerPeerProvider
interface that would determine a KeyboardFocusManagerPeer getter for the toolkit.
As it can be seen from the following code in the java.awt.KeyboardFocusManager:

private void initPeer() {
    if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit){
        peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).
                                         createKeyboardFocusManagerPeer(this);
    }
    if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
        peer = ((SunToolkit)Toolkit.getDefaultToolkit()).
                                    createKeyboardFocusManagerPeer(this);      
    }
}

the KFM peer entry point is strictly tied to the SunToolkit - AWT private
implementation. In the Suggested Fix area there have been put a prototype of
the fix allowing to break this dependency.

Comments
EVALUATION We are to submit a ccc-request for such a change.
16-07-2007

SUGGESTED FIX Author: Roman Kennke. Discussed at ###@###.### ------- KeyboardFocusManager.java ------- *** /tmp/sccs.IxAvhA Thu Jul 19 17:51:58 2007 --- KeyboardFocusManager.java Thu Jul 19 17:14:08 2007 *************** *** 58,67 **** --- 58,68 ---- import sun.awt.AppContext; import sun.awt.DebugHelper; import sun.awt.HeadlessToolkit; import sun.awt.SunToolkit; + import sun.awt.KeyboardFocusManagerPeerProvider; import sun.awt.CausedFocusEvent; /** * The KeyboardFocusManager is responsible for managing the active and focused * Windows, and the current focus owner. The focus owner is defined as the *************** *** 422,437 **** } initPeer(); } private void initPeer() { ! if (Toolkit.getDefaultToolkit() instanceof HeadlessToolkit){ ! peer = ((HeadlessToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this); ! } ! if (Toolkit.getDefaultToolkit() instanceof SunToolkit){ ! peer = ((SunToolkit)Toolkit.getDefaultToolkit()).createKeyboardFocusManagerPeer(this); ! } } /** * Returns the focus owner, if the focus owner is in the same context as * the calling thread. The focus owner is defined as the Component in an --- 423,435 ---- } initPeer(); } private void initPeer() { ! Toolkit tk = Toolkit.getDefaultToolkit(); ! KeyboardFocusManagerPeerProvider peerProvider = (KeyboardFocusManagerPeerProvider)tk; ! peer = peerProvider.createKeyboardFocusManagerPeer(this); } /** * Returns the focus owner, if the focus owner is in the same context as * the calling thread. The focus owner is defined as the Component in an ------- SunToolkit.java ------- *** /tmp/sccs.bhtgQv Thu Jul 19 17:51:58 2007 --- SunToolkit.java Thu Jul 19 15:51:51 2007 *************** *** 62,72 **** import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; public abstract class SunToolkit extends Toolkit implements WindowClosingSupport, WindowClosingListener, ! ComponentFactory, InputMethodSupport { private static final Logger log = Logger.getLogger("sun.awt.SunToolkit"); /* Force the debug helper classes to initialize */ { --- 62,72 ---- import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; public abstract class SunToolkit extends Toolkit implements WindowClosingSupport, WindowClosingListener, ! ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider { private static final Logger log = Logger.getLogger("sun.awt.SunToolkit"); /* Force the debug helper classes to initialize */ { ------- HeadlessToolkit.java ------- *** /tmp/sccs.Xdlz2q Thu Jul 19 17:51:58 2007 --- HeadlessToolkit.java Thu Jul 19 15:52:02 2007 *************** *** 42,52 **** import java.util.Properties; import sun.awt.im.InputContext; import sun.awt.image.ImageRepresentation; public class HeadlessToolkit extends Toolkit ! implements ComponentFactory { private Toolkit tk; private ComponentFactory componentFactory; public HeadlessToolkit(Toolkit tk) { --- 42,52 ---- import java.util.Properties; import sun.awt.im.InputContext; import sun.awt.image.ImageRepresentation; public class HeadlessToolkit extends Toolkit ! implements ComponentFactory, KeyboardFocusManagerPeerProvider { private Toolkit tk; private ComponentFactory componentFactory; public HeadlessToolkit(Toolkit tk) { /src/share/classes/sun/awt/KeyboardFocusManagerPeerProvider.java 1 /* 2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Sun designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Sun in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 22 * CA 95054 USA or visit www.sun.com if you need additional information or 23 * have any questions. 24 */ 25 26 package sun.awt; 27 28 import java.awt.KeyboardFocusManager; 29 import java.awt.peer.KeyboardFocusManagerPeer; 30 31 /** 32 * {@link KeyboardFocusManagerPeerProvider} is required to be implemented by 33 * the currently used {@link java.awt.Toolkit} instance. In order to initialize 34 * {@link java.awt.KeyboardFocusManager}, an instance of {@link KeyboardFocusManagerPeer} 35 * is needed. To create that instance, the {@link #createKeyboardFocusManagerPeer} 36 * method of the current toolkit is called. 37 */ 38 public interface KeyboardFocusManagerPeerProvider { 39 40 /** 41 * Creates a KeyboardFocusManagerPeer for the specified KeyboardFocusManager. 42 */ 43 KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager); 44 }
16-07-2007