com.jogamp.newt.event.awt

## Class AWTAdapter

- java.lang.Object
- - com.jogamp.newt.event.awt.AWTAdapter

- All Implemented Interfaces:
    EventListener
  Direct Known Subclasses:
    AWTKeyAdapter, AWTMouseAdapter, AWTWindowAdapter

      public abstract class AWTAdapter
      extends Object
      implements EventListener

  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 `javax.media.opengl.GLEvenListener` and some appropriate NEWT `NEWTEventListener`.

  Attach the `javax.media.opengl.GLEvenListener` to a NEWT `GLAutoDrawable`, e.g. `GLWindow`,
  or to an AWT `GLAutoDrawable`, e.g. `GLCanvas`.
  Attach the NEWT `NEWTEventListener` to a NEWT component, e.g. `Window`,
  or to an AWT component, e.g. `Component`.

  Common:

          // your demo/render code
          javax.media.opengl.GLEvenListener demo1 = new javax.media.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`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `DEBUG_IMPLEMENTATION`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AWTAdapter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract AWTAdapter` | `addTo(Component awtComponent)` Due to the fact that some NEWT `NEWTEventListener` are mapped to more than one `EventListener`, this method is for your convenience to use this Adapter as a listener for all types. E.g.
    `AWTAdapter` | `clear()` Removes all references, downstream and NEWT-EventListener.
    `NativeSurfaceHolder` | `getNativeSurfaceHolder()` Returns the `NativeSurfaceHolder` acting `as downstream`, `NEWT window proxy` or as an `NativeSurfaceHolder proxy`.
    `NEWTEventListener` | `getNewtEventListener()` Returns the `NEWT event-listener` if instance is used as an `NativeSurfaceHolder proxy` or `NEWT window proxy`, otherwise method returns `null`.
    `Window` | `getNewtWindow()` Returns the `NEWT Window` acting `as downstream` or as a `NEWT window proxy`.
    `abstract AWTAdapter` | `removeFrom(Component awtComponent)`
    `void` | `setConsumeAWTEvent(boolean v)`
    `AWTAdapter` | `setDownstream(Window downstream)` 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!

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEBUG_IMPLEMENTATION

          public static final boolean DEBUG_IMPLEMENTATION

  - ### Constructor Detail

    - #### AWTAdapter

          public AWTAdapter()

  - ### Method Detail

    - #### setDownstream

          public AWTAdapter setDownstream(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!
      Throws:
        `IllegalStateException` - if EDT is not enabled

    - #### clear

          public AWTAdapter clear()

      Removes all references, downstream and NEWT-EventListener.

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

    - #### setConsumeAWTEvent

          public final void setConsumeAWTEvent(boolean v)

    - #### getNativeSurfaceHolder

          public final NativeSurfaceHolder getNativeSurfaceHolder()

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

      Returned value is never null.

    - #### getNewtWindow

          public final 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`.

    - #### getNewtEventListener

          public final NEWTEventListener getNewtEventListener()

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

    - #### addTo

          public abstract AWTAdapter addTo(Component awtComponent)

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

    - #### removeFrom

          public abstract AWTAdapter removeFrom(Component awtComponent)

      See Also:
        `addTo(java.awt.Component)`

Copyright 2010 JogAmp Community.