diff options
author | Sven Gothel <[email protected]> | 2015-02-17 05:43:52 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2015-02-17 05:43:52 +0100 |
commit | a28e1610e1c29279847bce80e1aa80a947ff799e (patch) | |
tree | d1d796bc668a27b4c8441905e2f8008f4b803f7a /src/nativewindow/classes/jogamp | |
parent | 3ec3d5cedd7902b2fe14dc56a3f845cfe0752905 (diff) |
NativeWindow: Refactor getLocationOnScreenSafe(..) and getLocationOnScreenNonBlocking(..) from JAWTWindow -> AWTMisc (to be reused)
Diffstat (limited to 'src/nativewindow/classes/jogamp')
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java | 55 | ||||
-rw-r--r-- | src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java | 6 |
2 files changed, 58 insertions, 3 deletions
diff --git a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java index 0c072d05b..3900f03db 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java +++ b/src/nativewindow/classes/jogamp/nativewindow/awt/AWTMisc.java @@ -44,11 +44,13 @@ import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JRootPane; import javax.swing.WindowConstants; + import com.jogamp.nativewindow.NativeWindowException; import com.jogamp.nativewindow.WindowClosingProtocol; import com.jogamp.nativewindow.util.PixelRectangle; import com.jogamp.nativewindow.util.PixelFormat; import com.jogamp.nativewindow.util.PixelFormatUtil; + import javax.swing.MenuSelectionManager; import com.jogamp.nativewindow.awt.DirectDataBufferInt; @@ -115,6 +117,59 @@ public class AWTMisc { return null; } + public static com.jogamp.nativewindow.util.Point getLocationOnScreenSafe(com.jogamp.nativewindow.util.Point storage, + final Component component, + final boolean verbose) + { + if(!Thread.holdsLock(component.getTreeLock())) { + // avoid deadlock .. + if( null == storage ) { + storage = new com.jogamp.nativewindow.util.Point(); + } + getLocationOnScreenNonBlocking(storage, component, verbose); + return storage; + } + final java.awt.Point awtLOS = component.getLocationOnScreen(); + com.jogamp.nativewindow.util.Point los; + if(null!=storage) { + los = storage.translate(awtLOS.x, awtLOS.y); + } else { + los = new com.jogamp.nativewindow.util.Point(awtLOS.x, awtLOS.y); + } + return los; + } + public static Component getLocationOnScreenNonBlocking(final com.jogamp.nativewindow.util.Point storage, + Component comp, + final boolean verbose) + { + final java.awt.Insets insets = new java.awt.Insets(0, 0, 0, 0); // DEBUG + Component last = null; + while(null != comp) { + final int dx = comp.getX(); + final int dy = comp.getY(); + if( verbose ) { + final java.awt.Insets ins = getInsets(comp, false); + if( null != ins ) { + insets.bottom += ins.bottom; + insets.top += ins.top; + insets.left += ins.left; + insets.right += ins.right; + } + System.err.print("LOS: "+storage+" + "+comp.getClass().getName()+"["+dx+"/"+dy+", vis "+comp.isVisible()+", ins "+ins+" -> "+insets+"] -> "); + } + storage.translate(dx, dy); + if( verbose ) { + System.err.println(storage); + } + last = comp; + if( comp instanceof Window ) { // top-level heavy-weight ? + break; + } + comp = comp.getParent(); + } + return last; + } + public static interface ComponentAction { /** * @param c the component to perform the action on diff --git a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java index 6ac480120..6f3f1ed6b 100644 --- a/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java +++ b/src/nativewindow/classes/jogamp/nativewindow/jawt/macosx/MacOSXJAWTWindow.java @@ -145,7 +145,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // CALayer position will be determined in native code. // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); - final Component outterComp = getLocationOnScreenNonBlocking(p0, component); + final Component outterComp = AWTMisc.getLocationOnScreenNonBlocking(p0, component, DEBUG); final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true); final Point p1 = (Point)p0.cloneMutable(); p1.translate(-outterComp.getX(), -outterComp.getY()); @@ -178,7 +178,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { // CALayer position will be determined in native code. // See detailed description in {@link JAWTUtil#JAWT_OSX_CALAYER_QUIRK_LAYOUT} final Point p0 = new Point(); - final Component outterComp = getLocationOnScreenNonBlocking(p0, component); + final Component outterComp = AWTMisc.getLocationOnScreenNonBlocking(p0, component, DEBUG); final java.awt.Insets outterInsets = AWTMisc.getInsets(outterComp, true); final Point p1 = (Point)p0.cloneMutable(); p1.translate(-outterComp.getX(), -outterComp.getY()); @@ -405,7 +405,7 @@ public class MacOSXJAWTWindow extends JAWTWindow implements MutableSurface { if( null == storage ) { storage = new Point(); } - getLocationOnScreenNonBlocking(storage, component); + AWTMisc.getLocationOnScreenNonBlocking(storage, component, DEBUG); return storage; } @Override |