Top Description Inners Fields Constructors Methods
com.jogamp.newt.event.awt

public abstract Class AWTAdapter

extends Object
implements EventListener
Class Inheritance
All Implemented Interfaces
java.util.EventListener
Known Direct Subclasses
com.jogamp.newt.event.awt.AWTKeyAdapter, com.jogamp.newt.event.awt.AWTMouseAdapter, com.jogamp.newt.event.awt.AWTWindowAdapter
Imports
com.jogamp.nativewindow.NativeSurfaceHolder, jogamp.newt.Debug

Convenient adapter forwarding AWT events to NEWT via the event listener model.

You may attach an instance of this adapter to an AWT Component. When an event happens, it is converted to a NEWT event and the given NEWT listener is being called.

This adapter fullfills three use cases. First as a plain utility to write code AWT agnostic, ie write an com.jogamp.opengl.GLEvenListener and some appropriate NEWT com.jogamp.newt.event.NEWTEventListener.

Attach the com.jogamp.opengl.GLEvenListener to a NEWT com.jogamp.opengl.GLAutoDrawable, e.g. com.jogamp.newt.opengl.GLWindow,
or to an AWT com.jogamp.opengl.GLAutoDrawable, e.g. com.jogamp.opengl.awt.GLCanvas.

Attach the NEWT com.jogamp.newt.event.NEWTEventListener to a NEWT component, e.g. com.jogamp.newt.Window,
or to an AWT component, e.g. java.awt.Component.

Common:

   // your demo/render code
   com.jogamp.opengl.GLEvenListener demo1 = new com.jogamp.opengl.GLEvenListener() { ... } ;

   // your AWT agnostic NEWT mouse listener code
   com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ;

Default NEWT use case, without using the AWTAdapter:

   // the NEWT GLAutoDrawable and Window
   GLWindow glWindow = GLWindow.create();

   // attach the renderer demo1
   glWindow.addGLEventListener(demo1);

   // attach the NEWT mouse event listener to glWindow
   glWindow.addMouseListener(mouseListener);

AWT use case, AWTAdapter used as an AWT event translator and forwarder to your NEWT listener:

   // the AWT GLAutoDrawable and Canvas
   GLCanvas glCanvas = new GLCanvas();

   // attach the renderer demo1
   glCanvas.addGLEventListener(demo1);

   // attach the AWTMouseAdapter to glCanvas, which translates and forwards events to the NEWT mouseListener
   new AWTMouseAdapter(mouseListener).addTo(glCanvas);

Previous code in detail:

   AWTMouseAdapter mouseAdapter = new AWTMouseAdapter(mouseListener);
   glCanvas.addMouseListener(mouseAdapter);
   glCanvas.addMouseMotionListener(mouseAdapter);

Second use case is just a litte variation of the previous use case, where we pass a NEWT Window
to be used as the source of the event.

   com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ;
Component comp = ... ; // the AWT component
GLWindow glWindow = GLWindow.create(); // the NEWT component

new AWTMouseAdapter(mouseListener, glWindow).addTo(comp);

Last but not least, the AWTAdapter maybe used as a general AWT event forwarder to NEWT.

   com.jogamp.newt.event.MouseListener mouseListener = new com.jogamp.newt.event.MouseAdapter() { ... } ;
Component comp = ... ; // the AWT component
GLWindow glWindow = GLWindow.create(); // the NEWT component
glWindow.addMouseListener(mouseListener); // add the custom EventListener to the NEWT component

new AWTMouseAdapter(glWindow).addTo(comp); // forward all AWT events to glWindow, as NEWT events

See Also
attachTo

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum

Field Summary

Modifier and TypeField and Description
pack-priv boolean
public static final boolean
protected boolean
pack-priv NEWTEventListener
pack-priv Window
pack-priv NativeSurfaceHolder

Constructor Summary

AccessConstructor and Description
protected
AWTAdapter(final NEWTEventListener newtListener, final NativeSurfaceHolder nsProxy)

Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener, where the given NativeSurfaceHolder impersonates the event's source.

protected
AWTAdapter(final NEWTEventListener newtListener, final Window newtProxy)

Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener, where the given NEWT Window, a NativeSurfaceHolder, impersonates the event's source.

protected
AWTAdapter(final Window downstream)

Create a pipeline adapter, AWT EventListener.

public

Method Summary

Modifier and TypeMethod and Description
public abstract AWTAdapter
addTo(Component awtComponent)

Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one java.util.EventListener, this method is for your convenience to use this Adapter as a listener for all types.

public synchronized AWTAdapter
clear()

Removes all references, downstream and NEWT-EventListener.

public final synchronized NativeSurfaceHolder
public final synchronized NEWTEventListener
getNewtEventListener()

Returns the NEWT event-listener if instance is used as an NativeSurfaceHolder proxy or NEWT window proxy, otherwise method returns null.

public final synchronized Window
pack-priv AWTAdapter.EventProcRes

Returns:

One of the EventProcRes values, see above.
processEvent
(final boolean
In case the event will be ENQUEUED, passing true will block until the event has been processed, otherwise method returns immediately.
wait
,
final NEWTEvent
The event to enqueue.
event
)

Process the event.

public abstract AWTAdapter
removeFrom(Component awtComponent)

public final synchronized void
setConsumeAWTEvent(final boolean v)

public synchronized AWTAdapter
setDownstream(final Window downstream)

Setup a pipeline adapter, AWT EventListener.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

consumeAWTEventback to summary
pack-priv boolean consumeAWTEvent
DEBUG_IMPLEMENTATIONback to summary
public static final boolean DEBUG_IMPLEMENTATION
isSetupback to summary
protected boolean isSetup
newtListenerback to summary
pack-priv NEWTEventListener newtListener
newtWindowback to summary
pack-priv Window newtWindow
nsHolderback to summary
pack-priv NativeSurfaceHolder nsHolder

Constructor Detail

AWTAdapterback to summary
protected AWTAdapter(final NEWTEventListener newtListener, final NativeSurfaceHolder nsProxy)

Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,
where the given NativeSurfaceHolder impersonates the event's source. The NEWT EventListener will be called when an event happens.

AWTAdapterback to summary
protected AWTAdapter(final NEWTEventListener newtListener, final Window newtProxy)

Create a proxy adapter, wrapping around an NEWT EventListener, exposed as an AWT EventListener,
where the given NEWT Window, a NativeSurfaceHolder, impersonates the event's source. The NEWT EventListener will be called when an event happens.

AWTAdapterback to summary
protected AWTAdapter(final Window downstream) throws IllegalStateException

Create a pipeline adapter, AWT EventListener.
Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
This is only supported with EDT enabled!

Exceptions
IllegalStateException:
if EDT is not enabled
AWTAdapterback to summary
public AWTAdapter()

Method Detail

addToback to summary
public abstract AWTAdapter addTo(Component awtComponent)

Due to the fact that some NEWT com.jogamp.newt.event.NEWTEventListener are mapped to more than one java.util.EventListener, this method is for your convenience to use this Adapter as a listener for all types.
E.g. com.jogamp.newt.event.MouseListener is mapped to java.awt.event.MouseListener and java.awt.event.MouseMotionListener.

clearback to summary
public synchronized AWTAdapter clear()

Removes all references, downstream and NEWT-EventListener.

Also sets the internal setup flag and setConsumeAWTEvent(boolean) to false.

getNativeSurfaceHolderback to summary
public final synchronized NativeSurfaceHolder getNativeSurfaceHolder()

Returns the NativeSurfaceHolder acting as downstream, NEWT window proxy or as an NativeSurfaceHolder proxy.

Returned value is never null.

getNewtEventListenerback to summary
public final synchronized NEWTEventListener getNewtEventListener()

Returns the NEWT event-listener if instance is used as an NativeSurfaceHolder proxy or NEWT window proxy, otherwise method returns null.

getNewtWindowback to summary
public final synchronized Window getNewtWindow()

Returns the NEWT Window acting as downstream or as a NEWT window proxy.

Returned value maybe null if instance is used to be a NativeSurfaceHolder proxy.

processEventback to summary
pack-priv AWTAdapter.EventProcRes processEvent(final boolean wait, final NEWTEvent event)

Process the event.

If getNewtEventListener() is not null, DISPATCH is returned and caller shall dispatch the event appropriately.

If getNewtWindow() is not null, ENQUEUED is returned and the event has been enqueued already.

If none of the above matches, NOP is returned and none of the above processing method applies.

Parameters
wait:boolean

In case the event will be ENQUEUED, passing true will block until the event has been processed, otherwise method returns immediately.

event:NEWTEvent

The event to enqueue.

Returns:AWTAdapter.EventProcRes

One of the EventProcRes values, see above.

removeFromback to summary
public abstract AWTAdapter removeFrom(Component awtComponent)
See Also
addTo(java.awt.Component)
setConsumeAWTEventback to summary
public final synchronized void setConsumeAWTEvent(final boolean v)
setDownstreamback to summary
public synchronized AWTAdapter setDownstream(final Window downstream) throws IllegalStateException

Setup a pipeline adapter, AWT EventListener.
Once attached to an AWT component, it sends the converted AWT events to the NEWT downstream window.
This is only supported with EDT enabled!

Exceptions
IllegalStateException:
if EDT is not enabled
com.jogamp.newt.event.awt back to summary

pack-priv final Enum AWTAdapter.EventProcRes

extends Enum<AWTAdapter.EventProcRes>
Class Inheritance

Return value for event processing.

Field Summary

Modifier and TypeField and Description
public static final AWTAdapter.EventProcRes
DISPATCH

Event shall be dispatched appropriately

public static final AWTAdapter.EventProcRes
ENQUEUED

Event has been enqueued

public static final AWTAdapter.EventProcRes
NOP

No known processing method applies

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AWTAdapter.EventProcRes
public static AWTAdapter.EventProcRes[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DISPATCHback to summary
public static final AWTAdapter.EventProcRes DISPATCH

Event shall be dispatched appropriately

ENQUEUEDback to summary
public static final AWTAdapter.EventProcRes ENQUEUED

Event has been enqueued

NOPback to summary
public static final AWTAdapter.EventProcRes NOP

No known processing method applies

Constructor Detail

EventProcResback to summary
private EventProcRes()

Method Detail

valueOfback to summary
public static AWTAdapter.EventProcRes valueOf(String name)
valuesback to summary
public static AWTAdapter.EventProcRes[] values()