diff options
Diffstat (limited to 'src')
3 files changed, 60 insertions, 51 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index f1442abee..d315e1876 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -805,27 +805,10 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, * </p> */ @Override - public Point getLocationOnScreen(Point storage) { + public Point getLocationOnScreen(final Point storage) { Point los = getLocationOnScreenNative(storage); if(null == los) { - if(!Thread.holdsLock(component.getTreeLock())) { - // avoid deadlock .. - if(DEBUG) { - System.err.println("Warning: JAWT Lock hold, but not the AWT tree lock: "+this); - ExceptionUtils.dumpStack(System.err); - } - if( null == storage ) { - storage = new Point(); - } - getLocationOnScreenNonBlocking(storage, component); - return storage; - } - final java.awt.Point awtLOS = component.getLocationOnScreen(); - if(null!=storage) { - los = storage.translate(awtLOS.x, awtLOS.y); - } else { - los = new Point(awtLOS.x, awtLOS.y); - } + los = AWTMisc.getLocationOnScreenSafe(storage, component, DEBUG); } return los; } @@ -854,35 +837,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, } protected abstract Point getLocationOnScreenNativeImpl(int x, int y); - protected static Component getLocationOnScreenNonBlocking(final Point storage, Component comp) { - 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( DEBUG ) { - final java.awt.Insets ins = AWTMisc.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( DEBUG ) { - System.err.println(storage); - } - last = comp; - if( comp instanceof Window ) { // top-level heavy-weight ? - break; - } - comp = comp.getParent(); - } - return last; - } - @Override public boolean hasFocus() { return component.hasFocus(); 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 |