From 70bf3a4ec44504b86294a332255aaae8d2e86bf4 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sun, 23 Jun 2013 18:55:21 +0200 Subject: Fix NewtCanvasAWT focus traversal for Java7: All unit tests fail w/ Java7, i.e. AWT Component's transferFocus() does nothing if component does not hold the focus. .. this seems to be violating the AWT 'spec' .. however. Workaround: Request focus before transfering it to the next/previous element. --- src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/newt/classes') diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index 65b44b141..e5db8fd14 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -223,16 +223,24 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto final Set bwdKeys = keyboardFocusManager.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); if(fwdKeys.contains(ks)) { if(DEBUG) { - System.err.println("NewtCanvasAWT.focusKey (fwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()); + System.err.println("NewtCanvasAWT.focusKey (fwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()+", hasFocus: "+hasFocus()); } // Newt-EDT -> AWT-EDT may freeze Window's native peer requestFocus. + if(!hasFocus()) { + // Acquire the AWT focus 1st for proper AWT traversal + NewtCanvasAWT.super.requestFocus(); + } NewtCanvasAWT.this.transferFocus(); suppress = true; } else if(bwdKeys.contains(ks)) { if(DEBUG) { - System.err.println("NewtCanvasAWT.focusKey (bwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()); + System.err.println("NewtCanvasAWT.focusKey (bwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()+", hasFocus: "+hasFocus()); } // Newt-EDT -> AWT-EDT may freeze Window's native peer requestFocus. + if(!hasFocus()) { + // Acquire the AWT focus 1st for proper AWT traversal + NewtCanvasAWT.super.requestFocus(); + } NewtCanvasAWT.this.transferFocusBackward(); suppress = true; } -- cgit v1.2.3