diff options
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java | 31 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java | 4 |
2 files changed, 12 insertions, 23 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java index 2524f107a..66be82a44 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -69,7 +69,15 @@ public class AWTMisc { return (Container) c; } - public static Component getNextFocus(Component comp) { + /** + * Traverse to the next forward or backward component using the + * container's FocusTraversalPolicy. + * + * @param comp the assumed current focuse component + * @param forward if true, returns the next focus component, otherwise the previous one. + * @return + */ + public static Component getNextFocus(Component comp, boolean forward) { Container focusContainer = comp.getFocusCycleRootAncestor(); while ( focusContainer != null && ( !focusContainer.isShowing() || !focusContainer.isFocusable() || !focusContainer.isEnabled() ) ) @@ -80,7 +88,7 @@ public class AWTMisc { Component next = null; if (focusContainer != null) { final FocusTraversalPolicy policy = focusContainer.getFocusTraversalPolicy(); - next = policy.getComponentAfter(focusContainer, comp); + next = forward ? policy.getComponentAfter(focusContainer, comp) : policy.getComponentBefore(focusContainer, comp); if (next == null) { next = policy.getDefaultComponent(focusContainer); } @@ -88,25 +96,6 @@ public class AWTMisc { return next; } - public static Component getPrevFocus(Component comp) { - Container focusContainer = comp.getFocusCycleRootAncestor(); - while ( focusContainer != null && - ( !focusContainer.isShowing() || !focusContainer.isFocusable() || !focusContainer.isEnabled() ) ) - { - comp = focusContainer; - focusContainer = comp.getFocusCycleRootAncestor(); - } - Component prev = null; - if (focusContainer != null) { - final FocusTraversalPolicy policy = focusContainer.getFocusTraversalPolicy(); - prev = policy.getComponentBefore(focusContainer, comp); - if (prev == null) { - prev = policy.getDefaultComponent(focusContainer); - } - } - return prev; - } - /** * Issue this when your non AWT toolkit gains focus to clear AWT menu path */ diff --git a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java index dd8939e43..6ba7a1a61 100644 --- a/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java +++ b/src/newt/classes/com/jogamp/newt/awt/NewtCanvasAWT.java @@ -223,7 +223,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto final Set<AWTKeyStroke> fwdKeys = keyboardFocusManager.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); final Set<AWTKeyStroke> bwdKeys = keyboardFocusManager.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); if(fwdKeys.contains(ks)) { - final Component nextFocus = AWTMisc.getNextFocus(NewtCanvasAWT.this); + final Component nextFocus = AWTMisc.getNextFocus(NewtCanvasAWT.this, true /* forward */); if(DEBUG) { System.err.println("NewtCanvasAWT.focusKey (fwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()+", hasFocus: "+hasFocus()+", nextFocus "+nextFocus); } @@ -231,7 +231,7 @@ public class NewtCanvasAWT extends java.awt.Canvas implements WindowClosingProto nextFocus.requestFocus(); suppress = true; } else if(bwdKeys.contains(ks)) { - final Component prevFocus = AWTMisc.getPrevFocus(NewtCanvasAWT.this); + final Component prevFocus = AWTMisc.getNextFocus(NewtCanvasAWT.this, false /* forward */); if(DEBUG) { System.err.println("NewtCanvasAWT.focusKey (bwd): "+ks+", current focusOwner "+keyboardFocusManager.getFocusOwner()+", hasFocus: "+hasFocus()+", prevFocus "+prevFocus); } |