30package com.jogamp.newt.awt;
32import java.awt.AWTKeyStroke;
33import java.awt.Component;
34import java.awt.EventQueue;
35import java.awt.Graphics;
36import java.awt.Graphics2D;
37import java.awt.GraphicsConfiguration;
38import java.awt.GraphicsDevice;
39import java.awt.KeyboardFocusManager;
40import java.awt.geom.NoninvertibleTransformException;
41import java.beans.Beans;
42import java.beans.PropertyChangeEvent;
43import java.beans.PropertyChangeListener;
46import com.jogamp.nativewindow.CapabilitiesImmutable;
47import com.jogamp.nativewindow.NativeSurface;
48import com.jogamp.nativewindow.NativeWindow;
49import com.jogamp.nativewindow.NativeWindowHolder;
50import com.jogamp.nativewindow.OffscreenLayerOption;
51import com.jogamp.nativewindow.WindowClosingProtocol;
52import com.jogamp.opengl.GLAnimatorControl;
53import com.jogamp.opengl.GLAutoDrawable;
54import com.jogamp.opengl.GLCapabilities;
55import com.jogamp.opengl.GLCapabilitiesImmutable;
56import com.jogamp.opengl.GLDrawable;
57import com.jogamp.opengl.GLDrawableFactory;
58import com.jogamp.opengl.GLException;
59import com.jogamp.opengl.GLOffscreenAutoDrawable;
60import javax.swing.MenuSelectionManager;
62import jogamp.nativewindow.awt.AWTMisc;
63import jogamp.nativewindow.jawt.JAWTUtil;
64import jogamp.newt.Debug;
65import jogamp.newt.WindowImpl;
66import jogamp.newt.awt.NewtFactoryAWT;
67import jogamp.newt.awt.event.AWTParentWindowAdapter;
68import jogamp.newt.driver.DriverClearFocus;
69import jogamp.opengl.awt.AWTTilePainter;
71import com.jogamp.common.ExceptionUtils;
72import com.jogamp.common.os.Platform;
73import com.jogamp.common.os.Platform.OSType;
74import com.jogamp.common.util.awt.AWTEDTExecutor;
75import com.jogamp.nativewindow.awt.AWTGraphicsConfiguration;
76import com.jogamp.nativewindow.awt.AWTPrintLifecycle;
77import com.jogamp.nativewindow.awt.AWTWindowClosingProtocol;
78import com.jogamp.nativewindow.awt.JAWTWindow;
79import com.jogamp.newt.Display;
80import com.jogamp.newt.Window;
81import com.jogamp.newt.event.KeyEvent;
82import com.jogamp.newt.event.KeyListener;
83import com.jogamp.newt.event.WindowAdapter;
84import com.jogamp.newt.event.WindowEvent;
85import com.jogamp.newt.event.WindowListener;
86import com.jogamp.newt.event.awt.AWTAdapter;
87import com.jogamp.newt.event.awt.AWTKeyAdapter;
88import com.jogamp.newt.event.awt.AWTMouseAdapter;
89import com.jogamp.opengl.util.GLDrawableUtil;
90import com.jogamp.opengl.util.TileRenderer;
101@SuppressWarnings(
"serial")
103 public static final boolean DEBUG = Debug.debug(
"Window");
105 private static JAWTUtil.BackgroundEraseControl backgroundEraseControl =
new JAWTUtil.BackgroundEraseControl();
107 private final Object sync =
new Object();
108 private volatile JAWTWindow jawtWindow =
null;
109 private boolean isApplet =
false;
110 private boolean shallUseOffscreenLayer =
false;
111 private Window newtChild =
null;
112 private boolean newtChildAttached =
false;
113 private boolean isOnscreen =
true;
115 private final AWTParentWindowAdapter awtWinAdapter;
122 private boolean destroyJAWTPending =
false;
124 private boolean skipJAWTDestroy =
false;
127 private volatile boolean componentAdded =
false;
133 if( componentAdded ) {
140 if( componentAdded && newtChild !=
null ) {
153 awtWinAdapter = (AWTParentWindowAdapter)
new AWTParentWindowAdapter().
addTo(
this);
154 awtWinAdapter.removeWindowClosingFrom(
this);
164 awtWinAdapter = (AWTParentWindowAdapter)
new AWTParentWindowAdapter().
addTo(
this);
165 awtWinAdapter.removeWindowClosingFrom(
this);
175 awtWinAdapter = (AWTParentWindowAdapter)
new AWTParentWindowAdapter().
addTo(
this);
176 awtWinAdapter.removeWindowClosingFrom(
this);
187 awtWinAdapter = (AWTParentWindowAdapter)
new AWTParentWindowAdapter().
addTo(
this);
188 awtWinAdapter.removeWindowClosingFrom(
this);
194 shallUseOffscreenLayer = v;
199 return shallUseOffscreenLayer;
216 private final boolean isParent() {
217 final Window nw = newtChild;
218 return null!=nw && jawtWindow == nw.
getParent();
221 private final boolean isFullscreen() {
222 final Window nw = newtChild;
226 class FocusAction
implements Window.FocusRunnable {
228 public boolean run() {
229 final boolean isParent = isParent();
230 final boolean isFullscreen = isFullscreen();
232 System.err.println(
"NewtCanvasAWT.FocusAction: "+Display.getThreadName()+
", isOnscreen "+isOnscreen+
", hasFocus "+hasFocus()+
", isParent "+isParent+
", isFS "+isFullscreen);
234 if( isParent && !isFullscreen ) {
237 AWTEDTExecutor.singleton.invoke(
false, awtClearGlobalFocusOwner);
238 }
else if( !hasFocus() ) {
241 NewtCanvasAWT.super.requestFocus();
247 private final FocusAction focusAction =
new FocusAction();
249 private static class ClearFocusOwner
implements Runnable {
252 KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
255 private static final Runnable awtClearGlobalFocusOwner =
new ClearFocusOwner();
258 private final Runnable awtClearSelectedMenuPath =
new Runnable() {
261 MenuSelectionManager.defaultManager().clearSelectedPath();
264 private final WindowListener clearAWTMenusOnNewtFocus =
new WindowAdapter() {
266 public void windowResized(
final WindowEvent e) {
270 public void windowGainedFocus(
final WindowEvent arg0) {
271 if( isParent() && !isFullscreen() ) {
272 AWTEDTExecutor.singleton.invoke(
false, awtClearSelectedMenuPath);
277 class FocusTraversalKeyListener
implements KeyListener {
279 public void keyPressed(
final KeyEvent e) {
280 if( isParent() && !isFullscreen() ) {
285 public void keyReleased(
final KeyEvent e) {
286 if( isParent() && !isFullscreen() ) {
291 void handleKey(
final KeyEvent evt,
final boolean onRelease) {
292 if(
null == keyboardFocusManager) {
293 throw new InternalError(
"XXX");
295 final AWTKeyStroke ks = AWTKeyStroke.getAWTKeyStroke(evt.getKeyCode(), evt.getModifiers(), onRelease);
296 boolean suppress =
false;
298 final Set<AWTKeyStroke> fwdKeys = keyboardFocusManager.getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
299 final Set<AWTKeyStroke> bwdKeys = keyboardFocusManager.getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
300 if(fwdKeys.contains(ks)) {
301 final Component nextFocus = AWTMisc.getNextFocus(NewtCanvasAWT.this,
true );
303 System.err.println(
"NewtCanvasAWT.focusKey (fwd): "+ks+
", current focusOwner "+keyboardFocusManager.getFocusOwner()+
", hasFocus: "+hasFocus()+
", nextFocus "+nextFocus);
306 nextFocus.requestFocus();
308 }
else if(bwdKeys.contains(ks)) {
309 final Component prevFocus = AWTMisc.getNextFocus(NewtCanvasAWT.this,
false );
311 System.err.println(
"NewtCanvasAWT.focusKey (bwd): "+ks+
", current focusOwner "+keyboardFocusManager.getFocusOwner()+
", hasFocus: "+hasFocus()+
", prevFocus "+prevFocus);
314 prevFocus.requestFocus();
319 evt.setConsumed(
true);
322 System.err.println(
"NewtCanvasAWT.focusKey: XXX: "+ks);
326 private final FocusTraversalKeyListener newtFocusTraversalKeyListener =
new FocusTraversalKeyListener();
328 class FocusPropertyChangeListener
implements PropertyChangeListener {
330 public void propertyChange(
final PropertyChangeEvent evt) {
331 final Object oldF = evt.getOldValue();
332 final Object newF = evt.getNewValue();
333 final boolean isParent = isParent();
334 final boolean isFullscreen = isFullscreen();
336 System.err.println(
"NewtCanvasAWT.FocusProperty: "+evt.getPropertyName()+
", src "+evt.getSource()+
", "+oldF+
" -> "+newF+
", isParent "+isParent+
", isFS "+isFullscreen);
338 if(isParent && !isFullscreen) {
339 if(newF == NewtCanvasAWT.this) {
341 System.err.println(
"NewtCanvasAWT.FocusProperty: AWT focus -> NEWT focus traversal");
343 requestFocusNEWTChild();
344 }
else if(oldF == NewtCanvasAWT.this && newF ==
null) {
347 System.err.println(
"NewtCanvasAWT.FocusProperty: NEWT focus");
349 }
else if(
null != newF && newF != NewtCanvasAWT.this) {
352 System.err.println(
"NewtCanvasAWT.FocusProperty: lost focus - clear focus");
361 private final FocusPropertyChangeListener focusPropertyChangeListener =
new FocusPropertyChangeListener();
362 private volatile KeyboardFocusManager keyboardFocusManager =
null;
364 private final void requestFocusNEWTChild() {
365 if(
null!=newtChild) {
368 AWTEDTExecutor.singleton.invoke(
false, awtClearGlobalFocusOwner);
389 final Window prevChild = newtChild;
391 System.err.println(
"NewtCanvasAWT.setNEWTChild.0: win "+newtWinHandleToHexString(prevChild)+
" -> "+newtWinHandleToHexString(newChild));
393 final java.awt.Container cont = AWTMisc.getContainer(
this);
395 if(
null != newtChild) {
396 detachNewtChild( cont );
400 newtChild = newChild;
409 private final void updateLayoutSize() {
410 final Window w = newtChild;
413 final java.awt.Dimension minSize =
new java.awt.Dimension(w.
getWidth(), w.
getHeight());
414 setMinimumSize(minSize);
415 setPreferredSize(minSize);
464 @SuppressWarnings(
"removal")
465 private final
void determineIfApplet() {
468 while(!isApplet &&
null != c) {
469 isApplet = c instanceof java.applet.Applet;
474 private void setAWTGraphicsConfiguration(
final AWTGraphicsConfiguration config) {
477 if(
null != jawtWindow ) {
479 jawtWindow.setAWTGraphicsConfiguration(config);
506 final GraphicsConfiguration parentGC = super.getGraphicsConfiguration();
508 if( Beans.isDesignTime() ) {
513 if (
null != parentGC &&
null != oldGC && !oldGC.equals(parentGC) ) {
516 if ( !oldGC.getDevice().getIDstring().equals(parentGC.getDevice().getIDstring()) ) {
530 System.err.println(getThreadName()+
": getGraphicsConfiguration() Info: Changed GC and GD");
531 System.err.println(
"Created Config (n): Old GC "+oldGC);
532 System.err.println(
"Created Config (n): Old GD "+oldGC.getDevice().getIDstring());
533 System.err.println(
"Created Config (n): Parent GC "+parentGC);
534 System.err.println(
"Created Config (n): Parent GD "+parentGC.getDevice().getIDstring());
535 System.err.println(
"Created Config (n): New GC "+newGC);
536 System.err.println(
"Created Config (n): Old CF "+awtConfig);
537 System.err.println(
"Created Config (n): New CF "+newConfig);
538 System.err.println(
"Created Config (n): EQUALS CAPS "+equalCaps);
541 if (
null != newGC ) {
542 setAWTGraphicsConfiguration(newConfig);
548 System.err.println(getThreadName()+
": Info: getGraphicsConfiguration - end.01: newGC "+newGC);
553 System.err.println(getThreadName()+
": Info: getGraphicsConfiguration - end.00: oldGC "+oldGC);
564 }
else if (
null == parentGC) {
580 private static String getThreadName() {
return Thread.currentThread().getName(); }
584 if( Beans.isDesignTime() ) {
596 if( OSType.WINDOWS != Platform.getOSType() ) {
597 backgroundEraseControl.disable(
this);
601 final GraphicsConfiguration gc = super.getGraphicsConfiguration();
603 throw new GLException(
"Error: NULL AWT GraphicsConfiguration");
607 if(
null==awtConfig) {
608 throw new GLException(
"Error: NULL AWTGraphicsConfiguration");
610 setAWTGraphicsConfiguration(awtConfig);
616 if( OSType.WINDOWS == Platform.getOSType() ) {
617 backgroundEraseControl.disable(
this);
623 System.err.println(
"NewtCanvasAWT.addNotify.0 - isApplet "+isApplet+
", addedOnAWTEDT "+EventQueue.isDispatchThread()+
" @ "+currentThreadName());
624 ExceptionUtils.dumpStack(System.err);
626 jawtWindow = NewtFactoryAWT.getNativeWindow(
NewtCanvasAWT.this, awtConfig);
627 jawtWindow.setShallUseOffscreenLayer(shallUseOffscreenLayer);
629 jawtWindow.lockSurface();
633 jawtWindow.unlockSurface();
636 componentAdded =
true;
640 System.err.println(
"NewtCanvasAWT.addNotify.X: twin "+newtWinHandleToHexString(newtChild)+
641 ", comp "+
this+
", visible "+isVisible()+
", showing "+isShowing()+
642 ", displayable "+isDisplayable()+
", cont "+AWTMisc.getContainer(
this));
649 private final boolean updatePixelScale(
final GraphicsConfiguration gc,
final boolean force) {
650 if( jawtWindow.updatePixelScale(gc,
false) || jawtWindow.hasPixelScaleChanged() || force ) {
651 jawtWindow.hasPixelScaleChanged();
652 final float[] hasPixelScale = jawtWindow.getCurrentSurfaceScale(
new float[2]);
653 final Window cWin = newtChild;
655 if( dWin instanceof WindowImpl ) {
665 if( Beans.isDesignTime() ) {
666 super.removeNotify();
669 System.err.println(
"NewtCanvasAWT.removeNotify.0 - isApplet "+isApplet+
" @ "+currentThreadName());
670 ExceptionUtils.dumpStack(System.err);
672 componentAdded =
false;
674 destroyImpl(
true ,
false );
675 super.removeNotify();
677 System.err.println(
"NewtCanvasAWT.removeNotify.X @ "+currentThreadName());
694 System.err.println(
"NewtCanvasAWT.destroy() @ "+currentThreadName());
695 ExceptionUtils.dumpStack(System.err);
697 AWTEDTExecutor.singleton.invoke(
true,
new Runnable() {
700 destroyImpl(
false ,
false );
704 private final void destroyImpl(
final boolean removeNotify,
final boolean windowClosing) {
706 final java.awt.Container cont = AWTMisc.getContainer(
this);
708 System.err.println(
"NewtCanvasAWT.destroyImpl @ "+currentThreadName());
709 System.err.println(
"NewtCanvasAWT.destroyImpl.0 - isApplet "+isApplet+
", isOnAWTEDT "+EventQueue.isDispatchThread()+
", skipJAWTDestroy "+skipJAWTDestroy+
710 "; removeNotify "+removeNotify+
", windowClosing "+windowClosing+
", destroyJAWTPending "+destroyJAWTPending+
711 ", hasJAWT "+(
null!=jawtWindow)+
", hasNEWT "+(
null!=newtChild)+
712 "): nw "+newtWinHandleToHexString(newtChild)+
", from "+cont);
714 if(
null !=newtChild ) {
715 detachNewtChild(cont);
717 if( !removeNotify ) {
718 final Window cWin = newtChild;
721 if( windowClosing && dWin instanceof WindowImpl ) {
722 ((WindowImpl)dWin).windowDestroyNotify(
true);
728 if( ( destroyJAWTPending || removeNotify || windowClosing ) &&
null!=jawtWindow ) {
729 if( skipJAWTDestroy ) {
731 destroyJAWTPending =
true;
733 NewtFactoryAWT.destroyNativeWindow(jawtWindow);
736 destroyJAWTPending =
false;
743 public void paint(
final Graphics g) {
745 if( validateComponent(
true) && !printActive ) {
755 @SuppressWarnings(
"deprecation")
757 public void reshape(
final int x,
final int y,
final int width,
final int height) {
758 synchronized (getTreeLock()) {
760 super.reshape(x, y, width, height);
762 System.err.println(
"NewtCanvasAWT.reshape: "+x+
"/"+y+
" "+width+
"x"+height);
764 if( validateComponent(
true) ) {
765 if( !printActive && updatePixelScale(getGraphicsConfiguration(),
false ) ) {
775 private volatile boolean printActive =
false;
778 private AWTTilePainter printAWTTiles =
null;
788 public void setupPrint(
final double scaleMatX,
final double scaleMatY,
final int numSamples,
final int tileWidth,
final int tileHeight) {
790 final int componentCount = isOpaque() ? 3 : 4;
792 printAWTTiles =
new AWTTilePainter(printRenderer, componentCount, scaleMatX, scaleMatY, numSamples, tileWidth, tileHeight, DEBUG);
793 AWTEDTExecutor.singleton.invoke(getTreeLock(),
true ,
true , setupPrintOnEDT);
795 private final Runnable setupPrintOnEDT =
new Runnable() {
799 if( !validateComponent(
true) ) {
801 System.err.println(currentThreadName()+
": Info: NewtCanvasAWT setupPrint - skipped GL render, drawable not valid yet");
808 System.err.println(currentThreadName()+
": Info: NewtCanvasAWT setupPrint - skipped GL render, canvas not visible");
813 final GLAutoDrawable glad = getGLAD();
816 System.err.println(
"AWT print.setup exit, newtChild not a GLAutoDrawable: "+newtChild);
821 printAnimator = glad.getAnimator();
822 if(
null != printAnimator ) {
823 printAnimator.
remove(glad);
827 final int printNumSamples = printAWTTiles.
getNumSamples(gladCaps);
829 final boolean reqNewGLADSamples = printNumSamples != gladCaps.getNumSamples();
830 final boolean reqNewGLADSize = printAWTTiles.customTileWidth != -1 && printAWTTiles.customTileWidth != printDrawable.
getSurfaceWidth() ||
831 printAWTTiles.customTileHeight != -1 && printAWTTiles.customTileHeight != printDrawable.getSurfaceHeight();
832 final boolean reqNewGLADOnscrn = gladCaps.isOnscreen();
834 final GLCapabilities newGLADCaps = (GLCapabilities)gladCaps.cloneMutable();
835 newGLADCaps.setDoubleBuffered(
false);
836 newGLADCaps.setOnscreen(
false);
837 if( printNumSamples != newGLADCaps.getNumSamples() ) {
838 newGLADCaps.setSampleBuffers(0 < printNumSamples);
839 newGLADCaps.setNumSamples(printNumSamples);
841 final boolean reqNewGLADSafe = GLDrawableUtil.isSwapGLContextSafe(glad.getRequestedGLCapabilities(), gladCaps, newGLADCaps);
843 final boolean reqNewGLAD = ( reqNewGLADOnscrn || reqNewGLADSamples || reqNewGLADSize ) && reqNewGLADSafe;
846 System.err.println(
"AWT print.setup: reqNewGLAD "+reqNewGLAD+
"[ onscreen "+reqNewGLADOnscrn+
", samples "+reqNewGLADSamples+
", size "+reqNewGLADSize+
", safe "+reqNewGLADSafe+
"], "+
847 ", drawableSize "+printDrawable.getSurfaceWidth()+
"x"+printDrawable.getSurfaceHeight()+
848 ", customTileSize "+printAWTTiles.customTileWidth+
"x"+printAWTTiles.customTileHeight+
849 ", scaleMat "+printAWTTiles.scaleMatX+
" x "+printAWTTiles.scaleMatY+
850 ", numSamples "+printAWTTiles.customNumSamples+
" -> "+printNumSamples+
", printAnimator "+printAnimator);
853 final GLDrawableFactory factory = GLDrawableFactory.getFactory(newGLADCaps.getGLProfile());
854 GLOffscreenAutoDrawable offGLAD =
null;
856 offGLAD = factory.createOffscreenAutoDrawable(
null, newGLADCaps,
null,
857 printAWTTiles.customTileWidth != -1 ? printAWTTiles.customTileWidth : DEFAULT_PRINT_TILE_SIZE,
858 printAWTTiles.customTileHeight != -1 ? printAWTTiles.customTileHeight : DEFAULT_PRINT_TILE_SIZE);
859 }
catch (
final GLException gle) {
861 System.err.println(
"Caught: "+gle.getMessage());
862 gle.printStackTrace();
865 if(
null != offGLAD ) {
867 GLDrawableUtil.swapGLContextAndAllGLEventListener(glad, printGLAD);
872 printAWTTiles.renderer.setTileSize(printDrawable.getSurfaceWidth(), printDrawable.getSurfaceHeight(), 0);
873 printAWTTiles.renderer.attachAutoDrawable(printGLAD);
875 System.err.println(
"AWT print.setup "+printAWTTiles);
876 System.err.println(
"AWT print.setup AA "+printNumSamples+
", "+newGLADCaps);
878 System.err.println(
"AWT print.setup printDraw: "+printDrawable.getSurfaceWidth()+
"x"+printDrawable.getSurfaceHeight()+
", "+printDrawable);
886 if( !printActive ||
null == printGLAD ) {
887 throw new IllegalStateException(
"setupPrint() not called");
890 AWTEDTExecutor.singleton.invoke(getTreeLock(),
true ,
true , releasePrintOnEDT);
893 private final Runnable releasePrintOnEDT =
new Runnable() {
898 System.err.println(
"AWT print.release "+printAWTTiles);
900 final GLAutoDrawable glad = getGLAD();
901 printAWTTiles.dispose();
903 if( printGLAD != glad ) {
904 GLDrawableUtil.swapGLContextAndAllGLEventListener(printGLAD, glad);
908 if(
null != printAnimator ) {
909 printAnimator.
add(glad);
910 printAnimator =
null;
918 public void print(
final Graphics graphics) {
920 if( !printActive ||
null == printGLAD ) {
921 throw new IllegalStateException(
"setupPrint() not called");
923 if(DEBUG && !EventQueue.isDispatchThread()) {
924 System.err.println(currentThreadName()+
": Warning: GLCanvas print - not called from AWT-EDT");
928 final Graphics2D g2d = (Graphics2D)graphics;
930 printAWTTiles.setupGraphics2DAndClipBounds(g2d, getWidth(), getHeight());
931 final TileRenderer tileRenderer = printAWTTiles.renderer;
933 System.err.println(
"AWT print.0: "+tileRenderer);
935 if( !tileRenderer.
eot() ) {
939 }
while ( !tileRenderer.
eot() );
941 System.err.println(
"AWT print.1: "+printAWTTiles);
943 tileRenderer.
reset();
945 printAWTTiles.resetGraphics2D();
948 }
catch (
final NoninvertibleTransformException nte) {
949 System.err.println(
"Caught: Inversion failed of: "+g2d.getTransform());
950 nte.printStackTrace();
953 System.err.println(
"AWT print.X: "+printAWTTiles);
958 private final boolean validateComponent(
final boolean attachNewtChild) {
959 if( Beans.isDesignTime() || !isDisplayable() ) {
962 if (
null == newtChild ||
null == jawtWindow ) {
965 if( 0 >= getWidth() || 0 >= getHeight() ) {
969 if( attachNewtChild && !newtChildAttached &&
null != newtChild ) {
976 private final void configureNewtChild(
final boolean attach) {
977 awtWinAdapter.clear();
978 awtKeyAdapter.
clear();
979 awtMouseAdapter.
clear();
981 if(
null != keyboardFocusManager) {
982 keyboardFocusManager.removePropertyChangeListener(
"focusOwner", focusPropertyChangeListener);
983 keyboardFocusManager =
null;
986 if(
null != newtChild ) {
989 if(
null == jawtWindow.getGraphicsConfiguration()) {
990 throw new InternalError(
"XXX");
992 isOnscreen = jawtWindow.getGraphicsConfiguration().getChosenCapabilities().isOnscreen();
993 awtWinAdapter.setDownstream(jawtWindow, newtChild);
997 keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
998 keyboardFocusManager.addPropertyChangeListener(
"focusOwner", focusPropertyChangeListener);
1018 setFocusable(
false);
1037 private final void attachNewtChild() {
1038 if(
null == newtChild ||
null == jawtWindow || newtChildAttached ) {
1044 System.err.println(
"NewtCanvasAWT.attachNewtChild.0 @ "+currentThreadName());
1045 System.err.println(
"\twin "+newtWinHandleToHexString(newtChild)+
1047 ", comp "+
this+
", visible "+isVisible()+
", showing "+isShowing()+
", displayable "+isDisplayable()+
1048 ", cont "+AWTMisc.getContainer(
this));
1051 newtChildAttached =
true;
1054 System.err.println(
"NewtCanvasAWT.attachNewtChild.1: newtChild: "+newtChild);
1056 final int w = getWidth();
1057 final int h = getHeight();
1059 System.err.println(
"NewtCanvasAWT.attachNewtChild.2: size "+w+
"x"+h+
", isNValid "+newtChild.
isNativeValid());
1063 updatePixelScale(getGraphicsConfiguration(),
true );
1064 newtChild.
reparentWindow(jawtWindow, -1, -1, Window.REPARENT_HINT_BECOMES_VISIBLE);
1066 if( jawtWindow.isOffscreenLayerSurfaceEnabled() &&
1067 0 != ( JAWTUtil.JAWT_OSX_CALAYER_QUIRK_POSITION & JAWTUtil.getOSXCALayerQuirks() ) ) {
1068 AWTEDTExecutor.singleton.invoke(
false, forceRelayout);
1071 configureNewtChild(
true);
1075 System.err.println(
"NewtCanvasAWT.attachNewtChild.X: win "+newtWinHandleToHexString(newtChild)+
", EDTUtil: cur "+newtChild.
getScreen().
getDisplay().
getEDTUtil()+
", comp "+
this);
1078 private final Runnable forceRelayout =
new Runnable() {
1082 System.err.println(
"NewtCanvasAWT.forceRelayout.0");
1085 final java.awt.Component component = NewtCanvasAWT.this;
1086 final int cW = component.getWidth();
1087 final int cH = component.getHeight();
1088 component.setSize(cW+1, cH+1);
1089 component.setSize(cW, cH);
1091 System.err.println(
"NewtCanvasAWT.forceRelayout.X");
1095 private final void detachNewtChild(
final java.awt.Container cont) {
1096 if(
null == newtChild ||
null == jawtWindow || !newtChildAttached ) {
1102 System.err.println(
"NewtCanvasAWT.detachNewtChild.0: win "+newtWinHandleToHexString(newtChild)+
1104 ", comp "+
this+
", visible "+isVisible()+
", showing "+isShowing()+
", displayable "+isDisplayable()+
1109 newtChildAttached =
false;
1111 configureNewtChild(
false);
1117 System.err.println(
"NewtCanvasAWT.detachNewtChild.X: win "+newtWinHandleToHexString(newtChild)+
", EDTUtil: cur "+newtChild.
getScreen().
getDisplay().
getEDTUtil()+
", comp "+
this);
1121 protected static String
currentThreadName() {
return "["+Thread.currentThread().getName()+
", isAWT-EDT "+EventQueue.isDispatchThread()+
"]"; }
1123 static String newtWinHandleToHexString(
final Window w) {
1126 static String toHexString(
final long l) {
1127 return "0x"+Long.toHexString(l);
final CapabilitiesImmutable getRequestedCapabilities()
Return the capabilities used to choose this graphics configuration.
final CapabilitiesImmutable getChosenCapabilities()
Return the capabilities reflecting this graphics configuration, which may differ from the capabilitie...
A wrapper for an AWT GraphicsConfiguration allowing it to be handled in a toolkit-independent manner.
GraphicsConfiguration getAWTGraphicsConfiguration()
Return the AWT GraphicsConfiguration.
static AWTGraphicsConfiguration create(final GraphicsConfiguration gc, CapabilitiesImmutable capsChosen, CapabilitiesImmutable capsRequested)
Method constructs a new AWTGraphicsConfiguration primarily based on the given GraphicsConfiguration.
final WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
final WindowClosingMode getDefaultCloseOperation()
final boolean removeClosingListener()
final boolean addClosingListener()
Adds this closing listener to the components Window if exist and only one time.
final boolean isOffscreenLayerSurfaceEnabled()
Returns true if this instance uses an offscreen layer, otherwise false.
abstract EDTUtil getEDTUtil()
abstract Display getDisplay()
AWT Canvas containing a NEWT Window using native parenting.
final boolean isApplet()
Returns true if the AWT component is parented to an java.applet.Applet, otherwise false.
NewtCanvasAWT(final GraphicsConfiguration gc)
Instantiates a NewtCanvas without a NEWT child.
NativeSurface getNativeSurface()
Returns the associated NativeSurface of this NativeSurfaceHolder.
final boolean isAWTEventPassThrough()
Returns true if Key and Mouse input events will be passed through AWT, otherwise only the NEWT child ...
static String currentThreadName()
final boolean isOffscreenLayerSurfaceEnabled()
Returns true if this instance uses an offscreen layer, otherwise false.
final boolean getSkipJAWTDestroy()
See setSkipJAWTDestroy(boolean).
void print(final Graphics graphics)
WindowClosingMode setDefaultCloseOperation(final WindowClosingMode op)
WindowClosingMode getDefaultCloseOperation()
Window setNEWTChild(final Window newChild)
Sets a new NEWT child, provoking reparenting.
NewtCanvasAWT(final Window child)
Instantiates a NewtCanvas with a NEWT child.
NewtCanvasAWT()
Instantiates a NewtCanvas without a NEWT child.
final void destroy()
Destroys this resource:
void reshape(final int x, final int y, final int width, final int height)
final void setSkipJAWTDestroy(final boolean v)
Mitigates Bug 910 (IcedTea-Web), i.e.
void update(final Graphics g)
NativeWindow getNativeWindow()
Returns the associated NativeWindow of this NativeWindowHolder, which is identical to getNativeSurfac...
void setupPrint(final double scaleMatX, final double scaleMatY, final int numSamples, final int tileWidth, final int tileHeight)
Shall be called before PrinterJob#print().
void releasePrint()
Shall be called after PrinterJob#print().
void setShallUseOffscreenLayer(final boolean v)
Request an offscreen layer, if supported.
void paint(final Graphics g)
NewtCanvasAWT(final GraphicsConfiguration gc, final Window child)
Instantiates a NewtCanvas with a NEWT child.
GraphicsConfiguration getGraphicsConfiguration()
final boolean getShallUseOffscreenLayer()
Returns the property set by setShallUseOffscreenLayer(boolean).
NEWT Window events are provided for notification purposes ONLY.
static final short EVENT_WINDOW_RESIZED
Convenient adapter forwarding AWT events to NEWT via the event listener model.
final synchronized void setConsumeAWTEvent(final boolean v)
synchronized AWTAdapter setDownstream(final com.jogamp.newt.Window downstream)
Setup a pipeline adapter, AWT EventListener.
abstract AWTAdapter addTo(java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter clear()
Removes all references, downstream and NEWT-EventListener.
AWT: printable: PRESSED (t0), TYPED (t0), RELEASED (t1) non-printable: PRESSED (t0),...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
synchronized AWTAdapter addTo(final java.awt.Component awtComponent)
Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one ja...
A generic exception for OpenGL errors used throughout the binding as a substitute for RuntimeExceptio...
final void display()
Rendering one tile, by simply calling GLAutoDrawable#display().
A fairly direct port of Brian Paul's tile rendering library, found at http://www.mesa3d....
final boolean eot()
Returns true if end of tiling has been reached, otherwise false.end of tiling criteria is implementat...
final void reset()
Method resets implementation's internal state to start of tiling as required for beginTile(GL) if end...
Window closing mode if triggered by toolkit close operation.
DISPOSE_ON_CLOSE
Dispose resources on native window close operation.
Specifies an immutable set of capabilities that a window's rendering context must support,...
boolean equals(Object obj)
Equality over the immutable attributes of both objects.
Provides low-level information required for hardware-accelerated rendering using a surface in a platf...
void addSurfaceUpdatedListener(SurfaceUpdatedListener l)
Appends the given SurfaceUpdatedListener to the end of the list.
void removeSurfaceUpdatedListener(SurfaceUpdatedListener l)
Remove the specified SurfaceUpdatedListener from the list.
Accessor interface for implementing classes with ownership of a NativeWindow via an is-a or has-a rel...
Extend the NativeSurface interface with windowing information such as window-handle,...
int getHeight()
Returns the height of the client area excluding insets (window decorations) in window units.
int getWidth()
Returns the width of the client area excluding insets (window decorations) in window units.
long getWindowHandle()
Returns the window handle for this NativeWindow.
Handling requests for using an OffscreenLayerSurface within the implementation.
boolean setSurfaceScale(final float[] pixelScale)
Request a pixel scale in x- and y-direction for the associated NativeSurface, where size_in_pixel_uni...
Protocol for handling window closing events.
WindowClosingMode setDefaultCloseOperation(WindowClosingMode op)
Interface describing print lifecycle to support AWT printing, e.g.
Specifying NEWT's Window functionality:
Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
void sendWindowEvent(int eventType)
Send a WindowEvent to all WindowListener.
void setKeyboardFocusHandler(KeyListener l)
Sets a KeyListener allowing focus traversal with a covered window toolkit like AWT.
ReparentOperation reparentWindow(NativeWindow newParent, int x, int y, int hints)
Change this window's parent window.
void addWindowListener(WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
boolean windowRepaint(int x, int y, int width, int height)
Trigger window repaint while passing the dirty region in pixel units.
void requestFocus()
Request focus for this native window.
void setFocusAction(FocusRunnable focusAction)
Sets a FocusRunnable, which FocusRunnable#run() method is executed before the native focus is request...
void setSize(int width, int height)
Sets the size of the window's client area in window units, excluding decorations.
void setVisible(boolean visible)
Calls setVisible(true, visible), i.e.
CapabilitiesImmutable getRequestedCapabilities()
Gets an immutable set of requested capabilities.
void removeWindowListener(WindowListener l)
void destroy()
Destroys this window incl.releasing all related resources.
An animator control interface, which implementation may drive a com.jogamp.opengl....
void remove(GLAutoDrawable drawable)
Removes a drawable from the animator's list of rendering drawables.
void add(GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
GLDrawable getDelegatedDrawable()
If the implementation uses delegation, return the delegated GLDrawable instance, otherwise return thi...
int getNumSamples()
Returns the number of sample buffers to be allocated if sample buffers are enabled,...
GLCapabilitiesImmutable getChosenGLCapabilities()
Fetches the GLCapabilitiesImmutable corresponding to the chosen OpenGL capabilities (pixel format / v...
int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
boolean isGLOriented()
Returns true if the drawable is rendered in OpenGL's coordinate system, origin at bottom left.
int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.