Hi Roman,
Back to your patch.
I'll have to get it though some formal procedures and then, if
we have an approval, I'll integrate it into the workspace.
But before, let's correct some imperfections in the patch I've
just found. Please see my inline comments.
Roman Kennke wrote:
Hi,
Sounds very reasonable to me. I attached a revised patch.
Ok, I didn't ;-) But now!
/Roman
------------------------------------------------------------------------
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 (Arbeitskopie)
@@ -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;
There's no longer such class.
import sun.awt.HeadlessToolkit;
+import sun.awt.KeyboardFocusManagerPeerProvider;
import sun.awt.SunToolkit;
import sun.awt.CausedFocusEvent;
@@ -413,12 +416,10 @@
}
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);
- }
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ KeyboardFocusManagerPeerProvider kfmp =
+ (KeyboardFocusManagerPeerProvider) tk;
+ peer = kfmp.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 (Arbeitskopie)
@@ -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 (Arbeitskopie)
@@ -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 [EMAIL PROTECTED] KeyboardFocusManagerPeer}. This has to be
implemented by
+ * [EMAIL PROTECTED] java.awt.Toolkit}s that provide a
KeyboardFocusManagerPeer.
+ * The method [EMAIL PROTECTED] KeyboardFocusManager#initPeer()} checks the
current
+ * toolkit if it implements this interface. If not, a dummy
+ * ([EMAIL PROTECTED] DummyKeyboardFocusManagerPeer} is used, which does
nothing.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ */
1. There's no DummyKeyboardFocusManagerPeer.
2. I think we shouldn't be attached to any method. The
KeyboardFocusManager.initPeer
is a private one that can be changed. Anyway, this doesn't matter where AWT
retrieves the KFM peer.
3. We'd be better to mention somehow that AWT expects the toolkit to implement
the interface.
For instance, it could be something like the following:
* Provides a [EMAIL PROTECTED] KeyboardFocusManagerPeer}. The [EMAIL
PROTECTED] KeyboardFocusManager},
* during its initialization, assumes that the current [EMAIL PROTECTED]
java.awt.Toolkit}
* implements this interface that the [EMAIL PROTECTED] KeyboardFocusManager}
uses to
* retrieve a [EMAIL PROTECTED] KeyboardFocusManagerPeer}.
Give me your opinion, please.
Thanks,
Anton.
+public interface KeyboardFocusManagerPeerProvider {
+
+ /**
+ * Creates a KeyboardFocusManagerPeer for the specified
+ * KeyboardFocusManager.
+ */
+ KeyboardFocusManagerPeer
+ createKeyboardFocusManagerPeer(KeyboardFocusManager m);
+}