summaryrefslogtreecommitdiffstats
path: root/src/nativewindow/classes/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-23 20:15:38 +0200
committerSven Gothel <[email protected]>2013-06-23 20:15:38 +0200
commitcb7118fc875b6722803e4b11d5681671962a8d3a (patch)
treebb6676809c60c78b5d40030ef062196d83e0dae9 /src/nativewindow/classes/jogamp
parent70bf3a4ec44504b86294a332255aaae8d2e86bf4 (diff)
Fix NewtCanvasAWT focus traversal for Java7 (Take 2): Commit 70bf3a4ec44504b86294a332255aaae8d2e86bf4 was not sufficient.
Commit 70bf3a4ec44504b86294a332255aaae8d2e86bf4 did not work out on Windows. Solution now gathers the next or previous 'to be focused' component, using the FocusTraversalPolicy of the visible/focusable/enabled container. Then we simply request it's focus. Works w/ Java7 on Linux and Windows.
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r--src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
index d77cd75ef..2524f107a 100644
--- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
+++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java
@@ -27,6 +27,7 @@
*/
package jogamp.nativewindow.awt;
+import java.awt.FocusTraversalPolicy;
import java.awt.Window;
import java.awt.Component;
import java.awt.Container;
@@ -68,6 +69,44 @@ public class AWTMisc {
return (Container) c;
}
+ public static Component getNextFocus(Component comp) {
+ Container focusContainer = comp.getFocusCycleRootAncestor();
+ while ( focusContainer != null &&
+ ( !focusContainer.isShowing() || !focusContainer.isFocusable() || !focusContainer.isEnabled() ) )
+ {
+ comp = focusContainer;
+ focusContainer = comp.getFocusCycleRootAncestor();
+ }
+ Component next = null;
+ if (focusContainer != null) {
+ final FocusTraversalPolicy policy = focusContainer.getFocusTraversalPolicy();
+ next = policy.getComponentAfter(focusContainer, comp);
+ if (next == null) {
+ next = policy.getDefaultComponent(focusContainer);
+ }
+ }
+ 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
*/