org.apache.batik.gvt.event

Class AbstractAWTEventDispatcher

public abstract class AbstractAWTEventDispatcher extends Object implements EventDispatcher, MouseListener, MouseMotionListener, KeyListener

An EventDispatcher implementation based on AWT events.

Mouse events are dispatched to their "containing" node (the GraphicsNode corresponding to the mouse event coordinate). Searches for containment are performed from the EventDispatcher's "root" node.

This class is made abstract so that concrete versions can be made for different JDK versions.
Field Summary
protected AffineTransformbaseTransform
The base AffineTransform for InputEvent-to-GraphicsNodeEvent coordinates as determined by setBaseTransform().
protected GraphicsNodecurrentKeyEventTarget
The current GraphicsNode targeted by an key events.
protected booleaneventDispatchEnabled
protected ListeventQueue
These are used to queue events while a rendering event is in progress.
protected inteventQueueMaxSize
protected EventListenerListglisteners
The global listener list.
protected GraphicsNodelastHit
The lastest node which has been targeted by an event.
protected GraphicsNoderoot
The root GraphicsNode as determined by setRootNode().
Constructor Summary
AbstractAWTEventDispatcher()
Constructs a new event dispatcher.
Method Summary
voidaddGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Adds the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.
voidaddGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Adds the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.
voidaddGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Adds the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.
voiddispatchEvent(EventObject evt)
Dispatches the specified AWT event.
protected abstract voiddispatchKeyEvent(KeyEvent evt)
Dispatches the specified AWT key event.
protected voiddispatchMouseEvent(MouseEvent evt)
Dispatches the specified AWT mouse event.
AffineTransformgetBaseTransform()
Returns the base transform applied to MouseEvent coordinates prior to dispatch.
protected intgetCurrentLockState()
Returns a bitmask representing the state of the key locks.
EventListener[]getListeners(Class listenerType)
Returns an array of listeners that were added to this event dispatcher and of the specified type.
protected abstract intgetModifiers(InputEvent evt)
Returns the modifiers mask for this event.
GraphicsNodegetRootNode()
Returns the root node for MouseEvent dispatch containment searches and field selections.
protected booleanisNodeDecrementEvent(InputEvent e)
Returns true if the input event e is a node decrement event, false otherwise.
protected booleanisNodeIncrementEvent(InputEvent e)
Returns true if the input event e is a node increment event, false otherwise.
voidkeyPressed(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree.
voidkeyReleased(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree.
voidkeyTyped(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree.
voidmouseClicked(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmouseDragged(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmouseEntered(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmouseExited(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmouseMoved(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmousePressed(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidmouseReleased(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree.
voidprocessKeyEvent(GraphicsNodeKeyEvent evt)
Dispatches a graphics node key event to by firing the 'global' listeners attached to this event dispatcher.
protected voidprocessMouseEvent(GraphicsNodeMouseEvent evt)
Processes the specified event by firing the 'global' listeners attached to this event dispatcher.
voidremoveGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Removes the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.
voidremoveGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Removes the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.
voidremoveGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Removes the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.
voidsetBaseTransform(AffineTransform t)
Sets the base transform applied to MouseEvent coordinates prior to dispatch.
voidsetEventDispatchEnabled(boolean b)
voidsetEventQueueMaxSize(int n)
voidsetNodeDecrementEvent(InputEvent e)
Associates all InputEvents of type e.getID() with "decrementing" of the currently selected GraphicsNode.
voidsetNodeIncrementEvent(InputEvent e)
Associates all InputEvents of type e.getID() with "incrementing" of the currently selected GraphicsNode.
voidsetRootNode(GraphicsNode root)
Sets the root node for MouseEvent dispatch containment searches and field selections.

Field Detail

baseTransform

protected AffineTransform baseTransform
The base AffineTransform for InputEvent-to-GraphicsNodeEvent coordinates as determined by setBaseTransform().

currentKeyEventTarget

protected GraphicsNode currentKeyEventTarget
The current GraphicsNode targeted by an key events.

eventDispatchEnabled

protected boolean eventDispatchEnabled

eventQueue

protected List eventQueue
These are used to queue events while a rendering event is in progress.

eventQueueMaxSize

protected int eventQueueMaxSize

glisteners

protected EventListenerList glisteners
The global listener list.

lastHit

protected GraphicsNode lastHit
The lastest node which has been targeted by an event.

root

protected GraphicsNode root
The root GraphicsNode as determined by setRootNode().

Constructor Detail

AbstractAWTEventDispatcher

public AbstractAWTEventDispatcher()
Constructs a new event dispatcher.

Method Detail

addGraphicsNodeKeyListener

public void addGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Adds the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.

Parameters: l the listener to add

addGraphicsNodeMouseListener

public void addGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Adds the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.

Parameters: l the listener to add

addGraphicsNodeMouseWheelListener

public void addGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Adds the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.

Parameters: l the listener to add

dispatchEvent

public void dispatchEvent(EventObject evt)
Dispatches the specified AWT event.

Parameters: evt the event to dispatch

dispatchKeyEvent

protected abstract void dispatchKeyEvent(KeyEvent evt)
Dispatches the specified AWT key event. Abstract because KeyEvent.getKeyLocation() is available only in JDKs >= 1.4.

Parameters: evt the key event to dispatch

dispatchMouseEvent

protected void dispatchMouseEvent(MouseEvent evt)
Dispatches the specified AWT mouse event.

Parameters: evt the mouse event to dispatch

getBaseTransform

public AffineTransform getBaseTransform()
Returns the base transform applied to MouseEvent coordinates prior to dispatch.

getCurrentLockState

protected int getCurrentLockState()
Returns a bitmask representing the state of the key locks.

getListeners

public EventListener[] getListeners(Class listenerType)
Returns an array of listeners that were added to this event dispatcher and of the specified type.

Parameters: listenerType the type of the listeners to return

getModifiers

protected abstract int getModifiers(InputEvent evt)
Returns the modifiers mask for this event. Overridden in the descendent class to use {@link InputEvent#getModifiers()} in JRE 1.3 or {@link InputEvent#getModifiersEx()} in JREs >= 1.4.

getRootNode

public GraphicsNode getRootNode()
Returns the root node for MouseEvent dispatch containment searches and field selections.

isNodeDecrementEvent

protected boolean isNodeDecrementEvent(InputEvent e)
Returns true if the input event e is a node decrement event, false otherwise.

isNodeIncrementEvent

protected boolean isNodeIncrementEvent(InputEvent e)
Returns true if the input event e is a node increment event, false otherwise.

Parameters: e the input event

keyPressed

public void keyPressed(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.

Parameters: evt the key event to propagate

keyReleased

public void keyReleased(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.

Parameters: evt the key event to propagate

keyTyped

public void keyTyped(KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.

Parameters: evt the key event to propagate

mouseClicked

public void mouseClicked(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mouseDragged

public void mouseDragged(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mouseEntered

public void mouseEntered(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mouseExited

public void mouseExited(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mouseMoved

public void mouseMoved(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mousePressed

public void mousePressed(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

mouseReleased

public void mouseReleased(MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.

Parameters: evt the mouse event to propagate

processKeyEvent

public void processKeyEvent(GraphicsNodeKeyEvent evt)
Dispatches a graphics node key event to by firing the 'global' listeners attached to this event dispatcher.

Parameters: evt the evt to dispatch

processMouseEvent

protected void processMouseEvent(GraphicsNodeMouseEvent evt)
Processes the specified event by firing the 'global' listeners attached to this event dispatcher.

Parameters: evt the event to process

removeGraphicsNodeKeyListener

public void removeGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Removes the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.

Parameters: l the listener to remove

removeGraphicsNodeMouseListener

public void removeGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Removes the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.

Parameters: l the listener to remove

removeGraphicsNodeMouseWheelListener

public void removeGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Removes the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.

Parameters: l the listener to remove

setBaseTransform

public void setBaseTransform(AffineTransform t)
Sets the base transform applied to MouseEvent coordinates prior to dispatch.

Parameters: t the affine transform

setEventDispatchEnabled

public void setEventDispatchEnabled(boolean b)

setEventQueueMaxSize

public void setEventQueueMaxSize(int n)

setNodeDecrementEvent

public void setNodeDecrementEvent(InputEvent e)
Associates all InputEvents of type e.getID() with "decrementing" of the currently selected GraphicsNode. The notion of "currently selected" GraphicsNode is used for dispatching KeyEvents.

setNodeIncrementEvent

public void setNodeIncrementEvent(InputEvent e)
Associates all InputEvents of type e.getID() with "incrementing" of the currently selected GraphicsNode.

setRootNode

public void setRootNode(GraphicsNode root)
Sets the root node for MouseEvent dispatch containment searches and field selections.

Parameters: root the root node

Copyright B) 2007 Apache Software Foundation. All Rights Reserved.