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
Direct Known Subclasses:
OleNativeComponent

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
protected  EventListenerList listenerList
           
 
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()
          Construct a native component.
 
Method Summary
 void addMouseMotionListener(MouseMotionListener listener)
           
 void addNotify()
           
 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  Component createEmbeddableComponent(Map<Object,Object> optionMap)
          A native component instance cannot be added directly to a component hierarchy.
 void destroyBackBuffer()
          Destroy the back buffer.
protected  void disposeNativePeer()
          Explicitely dispose the native resources.
protected  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.
<T extends EventListener>
T[]
getListeners(Class<T> listenerType)
           
 Dimension getMinimumSize()
           
protected static ObjectRegistry getNativeComponentRegistry()
          Get the registry of the components, which references created components using the component ID.
protected  Object[] getNativePeerCreationParameters()
          Get the parameters that are passed to the creation method.
 Dimension getPreferredSize()
           
 boolean hasFocus()
           
 void initializeNativePeer()
          Force the component to initialize.
 boolean isNativePeerDisposed()
          Indicate whether the native peer is disposed.
 boolean isNativePeerInitialized()
          Indicate whether the native peer initialization phase has happened.
 boolean isNativePeerValid()
          Indicate if the native peer is valid, which means initialized, not disposed, and alive (communication channel is alive).
 void paint(Graphics g)
          Paint the component, which also paints the back buffer if any.
 void paintComponent(BufferedImage image)
          Paint the native component including its native peer in an image.
 void paintComponent(BufferedImage image, Rectangle[] rectangles)
          Paint the native component including its native peer in an image, in the areas that are specified.
 void print(Graphics g)
          Print the component, which also prints the native peer.
protected  void processKeyEvent(KeyEvent e)
           
 void removeMouseMotionListener(MouseMotionListener listener)
           
 void removeNotify()
           
 void reshape(int x, int y, int width, int height)
           
 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.
 void runInSequence(Runnable runnable)
          Run a command in sequence with other calls from this class.
 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.
 void setEnabled(boolean isEnabled)
          Set whether this component and its native peer are enabled.
 String toString()
           
 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.
 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
createBufferStrategy, createBufferStrategy, getAccessibleContext, getBufferStrategy, update
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, 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, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, 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, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

listenerList

protected EventListenerList listenerList
Constructor Detail

NativeComponent

public NativeComponent()
Construct a native component.

Method Detail

runInSequence

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

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 int getComponentID()
Get the unique identifier of this native component, used as a reference to communicate with the native peer.

Returns:
the component ID.

processKeyEvent

protected void processKeyEvent(KeyEvent e)
Overrides:
processKeyEvent in class Component

reshape

public void reshape(int x,
                    int y,
                    int width,
                    int height)
Overrides:
reshape in class Component

addMouseMotionListener

public void addMouseMotionListener(MouseMotionListener listener)
Overrides:
addMouseMotionListener in class Component

removeMouseMotionListener

public void removeMouseMotionListener(MouseMotionListener listener)
Overrides:
removeMouseMotionListener in class Component

paint

public void paint(Graphics g)
Paint the component, which also paints the back buffer if any.

Overrides:
paint in class Canvas
Parameters:
g - the graphics to paint to.

print

public void print(Graphics g)
Print the component, which also prints the native peer.

Overrides:
print in class Component
Parameters:
g - the graphics to paint to.

addNotify

public void addNotify()
Overrides:
addNotify in class Canvas

initializeNativePeer

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

removeNotify

public void removeNotify()
Overrides:
removeNotify in class Component

disposeNativePeer

protected 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 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 boolean isNativePeerInitialized()
Indicate whether the native peer initialization phase has happened. This method returns true even if the native peer is disposed of if the creation of the peer failed.

Returns:
true if the native peer is initialized.

isNativePeerValid

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

toString

public String toString()
Overrides:
toString in class Component

createEmbeddableComponent

protected 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.

setEnabled

public void setEnabled(boolean isEnabled)
Set whether this component and its native peer are enabled.

Overrides:
setEnabled in class Component
Parameters:
isEnabled - true it the component and its native peer should be enabled, false otherwise.

hasFocus

public boolean hasFocus()
Overrides:
hasFocus in class Component

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class Component

paintComponent

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

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class Component

createBackBuffer

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


updateBackBufferOnVisibleTranslucentAreas

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


updateBackBuffer

public 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 void destroyBackBuffer()
Destroy the back buffer.


getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Overrides:
getListeners in class Component