<AWT Dev> Proposal for consolidation of KeyboardFocusManagerPeer

Oleg Sukhodolsky son.two at gmail.com
Mon Nov 14 22:17:23 PST 2011


Hi Roman,

> I think this can be consolidated by doing the above directly in the
> KeyboardFocusManager, before calling the peer requestFocus(), and have
> the peer's requestFocus() only do the requestFocusImpl() handling. This
> way we could avoid duplicate code and avoid reflection/JNI altogether.

Perhaps I've missed something but which method of KFM will consolidate
this code?

Regards, Oleg.

On Tue, Nov 15, 2011 at 1:35 AM, Roman Kennke <roman at kennke.org> wrote:
> Hi there,
>
> One thing that's bugging me for a while is how the ComponentPeer's
> requestFocus() method is supposed to work. As far as I could figure out,
> it's basically always like this (I use KFMHelper to call the
> corresponding KeyboardFocusManager's private methods by reflection):
>
>    public boolean requestFocus(Component lightweightChild, boolean
> temporary,
>            boolean focusedWindowChangeAllowed, long time, Cause cause)
> {
>        if (KFMHelper.processSynchronousLightweightTransfer(window,
>                lightweightChild, temporary, focusedWindowChangeAllowed,
> time)) {
>            return true;
>        }
>
>        int result = KFMHelper.shouldNativelyFocusHeavyweight(window,
>                lightweightChild, temporary, focusedWindowChangeAllowed,
> time,
>                cause);
>
>        switch (result) {
>        case KFMHelper.SNFH_FAILURE:
>            return false;
>        case KFMHelper.SNFH_SUCCESS_PROCEED:
>                    requestFocusImpl(window, lightweightChild,
> temporary,
>                                 focusedWindowChangeAllowed, time,
> cause);
>        case KFMHelper.SNFH_SUCCESS_HANDLED:
>            // Either lightweight or excessive request - all events are
>            // generated.
>            return true;
>        default:
>            return false;
>        }
>    }
>
> The only thing that really differs between implementations would be the
> requestFocusImpl() method call in the SNFH_SUCCESS_PROCEED case. The
> rest seems to be the same in all implementations, except that in one
> case (Windows I believe) it is done in JNI while in others (X11) it's
> done by reflection.
>
> I think this can be consolidated by doing the above directly in the
> KeyboardFocusManager, before calling the peer requestFocus(), and have
> the peer's requestFocus() only do the requestFocusImpl() handling. This
> way we could avoid duplicate code and avoid reflection/JNI altogether.
>
> Maybe I am missing something?
>
> If not, I would work on a patch to move the above KeyboardFocusManager
> calls into the KFM and have the peer only bothers with the part that is
> requestFocusImpl() in the above example. Does that sound reasonable? It
> would certainly make some things simpler in OpenJDK as well as Cacio and
> the JavaFX SwingView that I am working on.
>
> Best regards, Roman
>
>
>



More information about the awt-dev mailing list