<AWT Dev> RFC: KeyboardFocusManager patch
Konstantin Voloshin
Konstantin.Voloshin at Sun.COM
Sat Jun 23 08:37:31 PDT 2007
The patch is fine, because is brief and natural. But it gives me a
strange feeling I want to outline.
1. You seem willig to give the user a help (that he'd better imlpement
the interface). But instead, we give a mandatory obligation. In other
words, a logical dependency link is established, which is artificial
(not indeed required) and easily avoidable. That is, we're giving
flexibility in a non-flexible way. Strange feeling.
2. If we're still determined to establish that link, this patch does it
in a lest transparent way I can imagine. I mean, implicitly throwing an
exception from code, somewhat deeply nested in a call chain, in the
middle of running a program. It doesn't seem the best choise ever.
So again, the patch is fine, but also we better realize it's underlying
questionable concepts.
Anton V. Tarasov wrote:
> Hi Roman,
>
> The fix looks Ok (for me).
> Now what we need is to achieve unity in the question of integration =)
>
> Thanks,
> Anton.
>
> 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;
>> 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 {@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 at aicas.com)
>> + */
>> +public interface KeyboardFocusManagerPeerProvider {
>> +
>> + /**
>> + * Creates a KeyboardFocusManagerPeer for the specified
>> + * KeyboardFocusManager.
>> + */
>> + KeyboardFocusManagerPeer
>> + createKeyboardFocusManagerPeer(KeyboardFocusManager m);
>> +}
More information about the awt-dev
mailing list