chrriis.dj.nativeswing.swtimpl
Class NativeComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Canvas
          extended by chrriis.dj.nativeswing.swtimpl.NativeComponent
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public abstract class NativeComponent
extends Canvas

A native component that gets connected to a native peer.

Author:
Christopher Deckers
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Canvas
Canvas.AccessibleAWTCanvas
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NativeComponent()
           
 
Method Summary
abstract  void createBackBuffer()
          Create an image of the native peer as a back buffer, which can be used when painting the component, or to simulate alpha blending.
protected abstract  Component createEmbeddableComponent(Map<Object,Object> optionMap)
          A native component instance cannot be added directly to a component hierarchy.
abstract  void destroyBackBuffer()
          Destroy the back buffer.
protected abstract  void disposeNativePeer()
          Explicitely dispose the native resources.
protected abstract  int getComponentID()
          Get the unique identifier of this native component, used as a reference to communicate with the native peer.
protected static ObjectRegistry getControlRegistry()
          Get the registry of the controls, which references created controls using the component ID.
protected static ObjectRegistry getNativeComponentRegistry()
          Get the registry of the components, which references created components using the component ID.
static NativeComponent[] getNativeComponents()
          Get the native components that are currently registered, which may have an invalid native peer.
protected abstract  Object[] getNativePeerCreationParameters()
          Get the parameters that are passed to the creation method.
abstract  boolean hasBackBuffer()
          Indicate whether a back buffer is (still) stored in the component.
abstract  void initializeNativePeer()
          Force the component to initialize.
abstract  boolean isNativePeerDisposed()
          Indicate whether the native peer is disposed.
abstract  boolean isNativePeerInitialized()
          Indicate whether the native peer initialization phase has happened.
abstract  boolean isNativePeerValid()
          Indicate if the native peer is valid, which means initialized, not disposed, and alive (communication channel is alive).
abstract  void paintComponent(BufferedImage image)
          Paint the native component including its native peer in an image.
abstract  void paintComponent(BufferedImage image, Rectangle[] rectangles)
          Paint the native component including its native peer in an image, in the areas that are specified.
abstract  void runAsync(CommandMessage commandMessage, Object... args)
          Run the given command if the control is created, or store it to run it when the creation occurs.
abstract  void runInSequence(Runnable runnable)
          Run a command in sequence with other calls from this class.
abstract  Object runSync(CommandMessage commandMessage, Object... args)
          Run the given command if the control is created, or store it to run it when the creation occurs.
abstract  void updateBackBuffer(Rectangle[] rectangles)
          Update (eventually creating an empty one if it does not exist) the back buffer on the area specified by the rectangles.
abstract  void updateBackBufferOnVisibleTranslucentAreas()
          Update the back buffer on the areas that have non opaque overlays and that are not covered by opaque components.
 
Methods inherited from class java.awt.Canvas
addNotify, createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, paint, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NativeComponent

public NativeComponent()
Method Detail

runInSequence

public abstract void runInSequence(Runnable runnable)
Run a command in sequence with other calls from this class. Calls are performed only when the component is initialized, and this method adds to the queue of calls in case it is not.

Parameters:
runnable - the command to run in sequence with other method calls.

runSync

public abstract Object runSync(CommandMessage commandMessage,
                               Object... args)
Run the given command if the control is created, or store it to run it when the creation occurs. If the component is disposed before the command has a chance to run, it is ignored silently.

Parameters:
commandMessage - the command message to run.
args - the arguments to pass to the command message.
Returns:
the result of running the message, or null if the message is queued.

runAsync

public abstract void runAsync(CommandMessage commandMessage,
                              Object... args)
Run the given command if the control is created, or store it to run it when the creation occurs. If the component is disposed before the command has a chance to run, it is ignored silently.

Parameters:
commandMessage - the command message to run.
args - the arguments to pass to the command message.

getNativeComponents

public static NativeComponent[] getNativeComponents()
Get the native components that are currently registered, which may have an invalid native peer.

Returns:
The currently registered native components, which may have an invalid native peer.

getNativeComponentRegistry

protected static ObjectRegistry getNativeComponentRegistry()
Get the registry of the components, which references created components using the component ID.

Returns:
the registry.

getControlRegistry

protected static ObjectRegistry getControlRegistry()
Get the registry of the controls, which references created controls using the component ID.

Returns:
the registry.

getComponentID

protected abstract int getComponentID()
Get the unique identifier of this native component, used as a reference to communicate with the native peer.

Returns:
the component ID.

initializeNativePeer

public abstract void initializeNativePeer()
Force the component to initialize. All method calls will then be synchronous instead of being queued waiting for the componant to be initialized. This call fails if the component is not in a component hierarchy with a Window ancestor.


getNativePeerCreationParameters

protected abstract Object[] getNativePeerCreationParameters()
Get the parameters that are passed to the creation method. This method can be overriden by subclasses to pass additional information necessary for the native peer creation.

Returns:
the parameters.

disposeNativePeer

protected abstract void disposeNativePeer()
Explicitely dispose the native resources. This is particularly useful if deferred destruction is used (cf native component options) and the component is not going to be used anymore.


isNativePeerDisposed

public abstract boolean isNativePeerDisposed()
Indicate whether the native peer is disposed.

Returns:
true if the native peer is disposed. This method returns false if the native peer is not initialized.

isNativePeerInitialized

public abstract boolean isNativePeerInitialized()
Indicate whether the native peer initialization phase has happened. This method returns true even if the native peer is disposed or if the creation of the peer failed.

Returns:
true if the native peer is initialized.

isNativePeerValid

public abstract boolean isNativePeerValid()
Indicate if the native peer is valid, which means initialized, not disposed, and alive (communication channel is alive).

Returns:
true if the native peer is valid.

createEmbeddableComponent

protected abstract Component createEmbeddableComponent(Map<Object,Object> optionMap)
A native component instance cannot be added directly to a component hierarchy. This method needs to be called to get a component that will add the native component.

Parameters:
optionMap - the options to configure the behavior of this component.
Returns:
the component that contains the native component and that can be added to the component hierarchy.

paintComponent

public abstract void paintComponent(BufferedImage image)
Paint the native component including its native peer in an image. This method can be called from a non-UI thread.

Parameters:
image - the image to paint to.

paintComponent

public abstract void paintComponent(BufferedImage image,
                                    Rectangle[] rectangles)
Paint the native component including its native peer in an image, in the areas that are specified. This method can be called from a non-UI thread.

Parameters:
image - the image to paint to.
rectangles - the area in which the component should be painted.

createBackBuffer

public abstract void createBackBuffer()
Create an image of the native peer as a back buffer, which can be used when painting the component, or to simulate alpha blending.


hasBackBuffer

public abstract boolean hasBackBuffer()
Indicate whether a back buffer is (still) stored in the component.

Returns:
true if a back buffer is still held, false otherwise.

updateBackBufferOnVisibleTranslucentAreas

public abstract void updateBackBufferOnVisibleTranslucentAreas()
Update the back buffer on the areas that have non opaque overlays and that are not covered by opaque components.


updateBackBuffer

public abstract void updateBackBuffer(Rectangle[] rectangles)
Update (eventually creating an empty one if it does not exist) the back buffer on the area specified by the rectangles.

Parameters:
rectangles - the area to update.

destroyBackBuffer

public abstract void destroyBackBuffer()
Destroy the back buffer.