From 9997ce1f19accc2ef6b8568b5e3ba877710bef01 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 9 Oct 2013 05:29:08 +0200 Subject: NewtCanvasAWT Focus Traversal: Remove AWT's requestFocus*() overrides in favor of FocusPropertyChangeListener requestFocusNEWTChild() The AWT's requestFocus*() overrides were intended to receive the AWT focus (default) and clear it afterwards to forward the focus to the NEWT component -> requestFocusNEWTChild(). This can be achieved simply by using our FocusPropertyChangeListener and invoking requestFocusNEWTChild() when receiving the focus on the NewtCanvasAWT component. --- .../classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 64 ++++++---------------- 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'src/newt/classes/com/jogamp') diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 55f5f0533..86faea35f 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -272,10 +272,15 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto System.err.println("NewtCanvasAWT.FocusProperty: "+evt.getPropertyName()+", src "+evt.getSource()+", "+oldF+" -> "+newF+", isParent "+isParent+", isFS "+isFullscreen); } if(isParent && !isFullscreen) { - if(oldF == NewtCanvasAWT.this && newF == null) { + if(newF == NewtCanvasAWT.this) { + if(DEBUG) { + System.err.println("NewtCanvasAWT.FocusProperty: AWT focus -> NEWT focus traversal"); + } + requestFocusNEWTChild(); + } else if(oldF == NewtCanvasAWT.this && newF == null) { // focus traversal to NEWT - NOP if(DEBUG) { - System.err.println("NewtCanvasAWT.FocusProperty: NEWT focus traversal"); + System.err.println("NewtCanvasAWT.FocusProperty: NEWT focus"); } } else if(null != newF && newF != NewtCanvasAWT.this) { // focus traversal to another AWT component @@ -292,6 +297,17 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto private final FocusPropertyChangeListener focusPropertyChangeListener = new FocusPropertyChangeListener(); private volatile KeyboardFocusManager keyboardFocusManager = null; + private final void requestFocusNEWTChild() { + if(null!=newtChild) { + newtChild.setFocusAction(null); + if(isOnscreen) { + KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); + } + newtChild.requestFocus(); + newtChild.setFocusAction(focusAction); + } + } + /** * Sets a new NEWT child, provoking reparenting. *

@@ -602,50 +618,6 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto } } - private final void requestFocusNEWTChild() { - if(null!=newtChild) { - newtChild.setFocusAction(null); - if(isOnscreen) { - KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner(); - } - newtChild.requestFocus(); - newtChild.setFocusAction(focusAction); - } - } - - @Override - public void requestFocus() { - super.requestFocus(); - requestFocusNEWTChild(); - } - - @Override - public boolean requestFocus(boolean temporary) { - final boolean res = super.requestFocus(temporary); - if(res) { - requestFocusNEWTChild(); - } - return res; - } - - @Override - public boolean requestFocusInWindow() { - final boolean res = super.requestFocusInWindow(); - if(res) { - requestFocusNEWTChild(); - } - return res; - } - - @Override - public boolean requestFocusInWindow(boolean temporary) { - final boolean res = super.requestFocusInWindow(temporary); - if(res) { - requestFocusNEWTChild(); - } - return res; - } - private final boolean validateComponent(boolean attachNewtChild) { if( Beans.isDesignTime() || !isDisplayable() ) { return false; -- cgit v1.2.3