diff options
Diffstat (limited to 'src/nativewindow/classes/com')
-rw-r--r-- | src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java | 143 |
1 files changed, 112 insertions, 31 deletions
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java index 5b5df7f68..6e198d961 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java @@ -37,14 +37,18 @@ package com.jogamp.nativewindow.awt; +import com.jogamp.common.os.Platform; import com.jogamp.common.util.locks.LockFactory; import com.jogamp.common.util.locks.RecursiveLock; import com.jogamp.nativewindow.MutableGraphicsConfiguration; import java.awt.Component; import java.awt.Container; +import java.awt.Window; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; import java.applet.Applet; import javax.media.nativewindow.AbstractGraphicsConfiguration; @@ -61,7 +65,6 @@ import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.Rectangle; import javax.media.nativewindow.util.RectangleImmutable; -import javax.swing.JRootPane; import jogamp.nativewindow.SurfaceUpdatedHelper; import jogamp.nativewindow.awt.AWTMisc; @@ -76,10 +79,11 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected boolean shallUseOffscreenLayer = false; // lifetime: forever - protected Component component; - private AWTGraphicsConfiguration config; // control access due to delegation - private SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper(); - private RecursiveLock surfaceLock = LockFactory.createRecursiveLock(); + protected final Component component; + private final AWTGraphicsConfiguration config; // control access due to delegation + private final SurfaceUpdatedHelper surfaceUpdatedHelper = new SurfaceUpdatedHelper(); + private final RecursiveLock surfaceLock = LockFactory.createRecursiveLock(); + private final JAWTComponentListener jawtComponentListener; // lifetime: valid after lock but may change with each 1st lock, purges after invalidate private boolean isApplet; @@ -106,34 +110,110 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, if(! ( config instanceof AWTGraphicsConfiguration ) ) { throw new NativeWindowException("Error: AbstractGraphicsConfiguration is not an AWTGraphicsConfiguration: "+config); } + this.component = (Component)comp; this.config = (AWTGraphicsConfiguration) config; - init((Component)comp); - } - - private void init(Component windowObject) throws NativeWindowException { + this.jawtComponentListener = new JAWTComponentListener(); + this.component.addComponentListener(jawtComponentListener); + this.component.addHierarchyListener(jawtComponentListener); invalidate(); - this.component = windowObject; this.isApplet = false; this.offscreenSurfaceLayer = 0; - this.component.addComponentListener(new ComponentListener() { + } + private class JAWTComponentListener implements ComponentListener, HierarchyListener { + private boolean localVisibility = component.isVisible(); + private boolean globalVisibility = localVisibility; + private boolean visibilityPropagation = false; + + private String s(ComponentEvent e) { + return "visible[local "+localVisibility+", global "+globalVisibility+", propag. "+visibilityPropagation+"],"+Platform.getNewline()+ + " ** COMP "+e.getComponent()+Platform.getNewline()+ + " ** SOURCE "+e.getSource()+Platform.getNewline()+ + " ** THIS "+component; + } + private String s(HierarchyEvent e) { + return "visible[local "+localVisibility+", global "+globalVisibility+", propag. "+visibilityPropagation+"], changeBits 0x"+Long.toHexString(e.getChangeFlags())+Platform.getNewline()+ + " ** COMP "+e.getComponent()+Platform.getNewline()+ + " ** SOURCE "+e.getSource()+Platform.getNewline()+ + " ** CHANGED "+e.getChanged()+Platform.getNewline()+ + " ** CHANGEDPARENT "+e.getChangedParent()+Platform.getNewline()+ + " ** THIS "+component; + } + @Override public void componentResized(ComponentEvent e) { - layoutSurfaceLayerIfEnabled(); + if(DEBUG) { + System.err.println("JAWTWindow.componentResized: "+s(e)); + } + layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility); } @Override public void componentMoved(ComponentEvent e) { - layoutSurfaceLayerIfEnabled(); + if(DEBUG) { + System.err.println("JAWTWindow.componentMoved: "+s(e)); + } + layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility); } @Override public void componentShown(ComponentEvent e) { - layoutSurfaceLayerIfEnabled(); + if(DEBUG) { + System.err.println("JAWTWindow.componentShown: "+s(e)); + } + layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility); } @Override - public void componentHidden(ComponentEvent e) { } - }); + public void componentHidden(ComponentEvent e) { + if(DEBUG) { + System.err.println("JAWTWindow.componentHidden: "+s(e)); + } + layoutSurfaceLayerIfEnabled(globalVisibility && localVisibility); + } + + @Override + public void hierarchyChanged(HierarchyEvent e) { + final long bits = e.getChangeFlags(); + final java.awt.Component changed = e.getChanged(); + if( 0 != ( java.awt.event.HierarchyEvent.DISPLAYABILITY_CHANGED & bits ) ) { + final boolean displayable = changed.isDisplayable(); + final boolean resetLocalVisibility = changed == component && !displayable && localVisibility != component.isVisible(); + if( resetLocalVisibility ) { + // Reset components local state if detached from parent, i.e. 'removeNotify()' + visibilityPropagation = true; + if(DEBUG) { + System.err.println("JAWTWindow.hierarchyChanged DISPLAYABILITY_CHANGED (1): displayable "+displayable+", "+s(e)); + } + component.setVisible(localVisibility); + } else if(DEBUG) { + System.err.println("JAWTWindow.hierarchyChanged DISPLAYABILITY_CHANGED (x): displayable "+displayable+", "+s(e)); + } + } else if( 0 != ( java.awt.event.HierarchyEvent.SHOWING_CHANGED & bits ) ) { + final boolean showing = changed.isShowing(); + final boolean propagateVisibility = changed != component && ( showing && localVisibility ) != component.isVisible(); + if( propagateVisibility ) { + // Propagate parent's visibility + final boolean _visible = showing && localVisibility; + visibilityPropagation = true; + globalVisibility = showing; + if(DEBUG) { + System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (1): showing "+showing+" -> visible "+_visible+", "+s(e)); + } + component.setVisible(_visible); + } else if( changed == component ) { + // Update component's local visibility state + if(!visibilityPropagation) { + localVisibility = showing; + } + visibilityPropagation = false; + if(DEBUG) { + System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (0): showing "+showing+" -> visible "+(showing && localVisibility)+", "+s(e)); + } + } else if(DEBUG) { + System.err.println("JAWTWindow.hierarchyChanged SHOWING_CHANGED (x): showing "+showing+" -> visible "+(showing && localVisibility)+", "+s(e)); + } + } + } } protected synchronized void invalidate() { @@ -248,14 +328,14 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, * Call this method if any parent or ancestor's layout has been changed, * which could affects the layout of this surface. * </p> - * @see #isOffscreenLayerSurfaceEnabled() + * @see #isOffscreenLayerSurfaceEnabled() * @throws NativeWindowException if {@link #isOffscreenLayerSurfaceEnabled()} == false */ - protected void layoutSurfaceLayerImpl(long layerHandle) {} + protected void layoutSurfaceLayerImpl(long layerHandle, boolean visible) {} - private final void layoutSurfaceLayerIfEnabled() throws NativeWindowException { + private final void layoutSurfaceLayerIfEnabled(boolean visible) throws NativeWindowException { if( isOffscreenLayerSurfaceEnabled() && 0 != offscreenSurfaceLayer ) { - layoutSurfaceLayerImpl(offscreenSurfaceLayer); + layoutSurfaceLayerImpl(offscreenSurfaceLayer, visible); } } @@ -483,7 +563,6 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, surfaceLock.lock(); try { invalidate(); - component = null; // don't dispose the AWT component, since we are merely an immutable uplink } finally { surfaceLock.unlock(); } @@ -574,21 +653,27 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, protected abstract Point getLocationOnScreenNativeImpl(int x, int y); protected static Component getLocationOnScreenNonBlocking(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); - System.err.print("LOS: "+storage+" + "+comp.getClass().getName()+"["+dx+"/"+dy+", vis "+comp.isVisible()+", ins "+ins+"] -> "); + 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 JRootPane ) { - // LW JRootPane is considered a top-level component! + if( comp instanceof Window ) { // top-level heavy-weight ? break; } comp = comp.getParent(); @@ -627,12 +712,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface, ", surfaceHandle "+toHexString(getSurfaceHandle())+ ", bounds "+bounds+", insets "+insets ); - if(null!=component) { - sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ - ", visible "+component.isVisible()); - } else { - sb.append(", component NULL"); - } + sb.append(", pos "+getX()+"/"+getY()+", size "+getWidth()+"x"+getHeight()+ + ", visible "+component.isVisible()); sb.append(", lockedExt "+isSurfaceLockedByOtherThread()+ ",\n\tconfig "+getPrivateGraphicsConfiguration()+ ",\n\tawtComponent "+getAWTComponent()+ |