Package org.apache.batik.gvt.event
Class AWTEventDispatcher
- java.lang.Object
-
- org.apache.batik.gvt.event.AWTEventDispatcher
-
- All Implemented Interfaces:
java.awt.event.KeyListener,java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.awt.event.MouseWheelListener,java.util.EventListener,EventDispatcher
public class AWTEventDispatcher extends java.lang.Object implements EventDispatcher, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.awt.event.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.
- Version:
- $Id: AWTEventDispatcher.java 1831615 2018-05-15 09:50:53Z ssteiner $
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.geom.AffineTransformbaseTransformThe base AffineTransform for InputEvent-to-GraphicsNodeEvent coordinates as determined by setBaseTransform().protected GraphicsNodecurrentKeyEventTargetThe current GraphicsNode targeted by an key events.protected booleaneventDispatchEnabledprotected java.util.ListeventQueueThese are used to queue events while a rendering event is in progress.protected inteventQueueMaxSizeprotected javax.swing.event.EventListenerListglistenersThe global listener list.protected GraphicsNodelastHitThe lastest node which has been targeted by an event.(package private) static intMAX_QUEUE_SIZEdefault max size of the event queue.private intnodeDecrementEventCodeprivate intnodeDecrementEventIDprivate intnodeDecrementEventModifiersprivate intnodeIncrementEventCodeprivate intnodeIncrementEventIDprivate intnodeIncrementEventModifiersprotected GraphicsNoderootThe root GraphicsNode as determined by setRootNode().
-
Constructor Summary
Constructors Constructor Description AWTEventDispatcher()Constructs a new event dispatcher.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.private voiddecrementKeyTarget()voiddispatchEvent(java.util.EventObject evt)Dispatches the specified AWT event.protected voiddispatchKeyEvent(java.awt.event.KeyEvent evt)Dispatches the specified AWT key event.protected voiddispatchMouseEvent(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event.protected voiddispatchMouseWheelEvent(java.awt.event.MouseWheelEvent evt)Dispatches the specified AWT mouse wheel event.java.awt.geom.AffineTransformgetBaseTransform()Returns the base transform applied to MouseEvent coordinates prior to dispatch.protected intgetCurrentLockState()Returns a bitmask representing the state of the key locks.java.util.EventListener[]getListeners(java.lang.Class listenerType)Returns an array of listeners that were added to this event dispatcher and of the specified type.GraphicsNodegetRootNode()Returns the root node for MouseEvent dispatch containment searches and field selections.private voidincrementKeyTarget()protected static booleanisMetaDown(int modifiers)Returns whether the meta key is down according to the given modifiers bitfield.protected booleanisNodeDecrementEvent(java.awt.event.InputEvent e)Returns true if the input event e is a node decrement event, false otherwise.protected booleanisNodeIncrementEvent(java.awt.event.InputEvent e)Returns true if the input event e is a node increment event, false otherwise.voidkeyPressed(java.awt.event.KeyEvent evt)Dispatches the specified AWT key event down to the GVT tree.voidkeyReleased(java.awt.event.KeyEvent evt)Dispatches the specified AWT key event down to the GVT tree.voidkeyTyped(java.awt.event.KeyEvent evt)Dispatches the specified AWT key event down to the GVT tree.voidmouseClicked(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseDragged(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseEntered(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseExited(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseMoved(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmousePressed(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseReleased(java.awt.event.MouseEvent evt)Dispatches the specified AWT mouse event down to the GVT tree.voidmouseWheelMoved(java.awt.event.MouseWheelEvent evt)Dispatches the specified AWT mouse wheel 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.protected voidprocessMouseWheelEvent(GraphicsNodeMouseWheelEvent 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(java.awt.geom.AffineTransform t)Sets the base transform applied to MouseEvent coordinates prior to dispatch.voidsetEventDispatchEnabled(boolean b)voidsetEventQueueMaxSize(int n)voidsetNodeDecrementEvent(java.awt.event.InputEvent e)Associates all InputEvents of typee.getID()with "decrementing" of the currently selected GraphicsNode.voidsetNodeIncrementEvent(java.awt.event.InputEvent e)Associates all InputEvents of typee.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
-
root
protected GraphicsNode root
The root GraphicsNode as determined by setRootNode().
-
baseTransform
protected java.awt.geom.AffineTransform baseTransform
The base AffineTransform for InputEvent-to-GraphicsNodeEvent coordinates as determined by setBaseTransform().
-
glisteners
protected javax.swing.event.EventListenerList glisteners
The global listener list.
-
lastHit
protected GraphicsNode lastHit
The lastest node which has been targeted by an event.
-
currentKeyEventTarget
protected GraphicsNode currentKeyEventTarget
The current GraphicsNode targeted by an key events.
-
eventQueue
protected java.util.List eventQueue
These are used to queue events while a rendering event is in progress.
-
eventDispatchEnabled
protected boolean eventDispatchEnabled
-
eventQueueMaxSize
protected int eventQueueMaxSize
-
MAX_QUEUE_SIZE
static final int MAX_QUEUE_SIZE
default max size of the event queue.- See Also:
- Constant Field Values
-
nodeIncrementEventID
private int nodeIncrementEventID
-
nodeIncrementEventCode
private int nodeIncrementEventCode
-
nodeIncrementEventModifiers
private int nodeIncrementEventModifiers
-
nodeDecrementEventID
private int nodeDecrementEventID
-
nodeDecrementEventCode
private int nodeDecrementEventCode
-
nodeDecrementEventModifiers
private int nodeDecrementEventModifiers
-
-
Method Detail
-
setRootNode
public void setRootNode(GraphicsNode root)
Sets the root node for MouseEvent dispatch containment searches and field selections.- Specified by:
setRootNodein interfaceEventDispatcher- Parameters:
root- the root node
-
getRootNode
public GraphicsNode getRootNode()
Returns the root node for MouseEvent dispatch containment searches and field selections.- Specified by:
getRootNodein interfaceEventDispatcher
-
setBaseTransform
public void setBaseTransform(java.awt.geom.AffineTransform t)
Sets the base transform applied to MouseEvent coordinates prior to dispatch.- Specified by:
setBaseTransformin interfaceEventDispatcher- Parameters:
t- the affine transform
-
getBaseTransform
public java.awt.geom.AffineTransform getBaseTransform()
Returns the base transform applied to MouseEvent coordinates prior to dispatch.- Specified by:
getBaseTransformin interfaceEventDispatcher
-
mousePressed
public void mousePressed(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mousePressedin interfacejava.awt.event.MouseListener- Parameters:
evt- the mouse event to propagate
-
mouseReleased
public void mouseReleased(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseReleasedin interfacejava.awt.event.MouseListener- Parameters:
evt- the mouse event to propagate
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener- Parameters:
evt- the mouse event to propagate
-
mouseExited
public void mouseExited(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseExitedin interfacejava.awt.event.MouseListener- Parameters:
evt- the mouse event to propagate
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener- Parameters:
evt- the mouse event to propagate
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Parameters:
evt- the mouse event to propagate
-
mouseDragged
public void mouseDragged(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event down to the GVT tree. The mouse event is mutated to a GraphicsNodeMouseEvent.- Specified by:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Parameters:
evt- the mouse event to propagate
-
mouseWheelMoved
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt)
Dispatches the specified AWT mouse wheel event down to the GVT tree. The mouse wheel event is mutated to a GraphicsNodeMouseWheelEvent.- Specified by:
mouseWheelMovedin interfacejava.awt.event.MouseWheelListener- Parameters:
evt- the mouse event to propagate
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.- Specified by:
keyPressedin interfacejava.awt.event.KeyListener- Parameters:
evt- the key event to propagate
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener- Parameters:
evt- the key event to propagate
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent evt)
Dispatches the specified AWT key event down to the GVT tree. The mouse event is mutated to a GraphicsNodeKeyEvent.- Specified by:
keyTypedin interfacejava.awt.event.KeyListener- Parameters:
evt- the key event to propagate
-
addGraphicsNodeMouseListener
public void addGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Adds the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.- Specified by:
addGraphicsNodeMouseListenerin interfaceEventDispatcher- Parameters:
l- the listener to add
-
removeGraphicsNodeMouseListener
public void removeGraphicsNodeMouseListener(GraphicsNodeMouseListener l)
Removes the specified 'global' GraphicsNodeMouseListener which is notified of all MouseEvents dispatched.- Specified by:
removeGraphicsNodeMouseListenerin interfaceEventDispatcher- Parameters:
l- the listener to remove
-
addGraphicsNodeMouseWheelListener
public void addGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Adds the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.- Specified by:
addGraphicsNodeMouseWheelListenerin interfaceEventDispatcher- Parameters:
l- the listener to add
-
removeGraphicsNodeMouseWheelListener
public void removeGraphicsNodeMouseWheelListener(GraphicsNodeMouseWheelListener l)
Removes the specified 'global' GraphicsNodeMouseWheelListener which is notified of all MouseWheelEvents dispatched.- Specified by:
removeGraphicsNodeMouseWheelListenerin interfaceEventDispatcher- Parameters:
l- the listener to remove
-
addGraphicsNodeKeyListener
public void addGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Adds the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.- Specified by:
addGraphicsNodeKeyListenerin interfaceEventDispatcher- Parameters:
l- the listener to add
-
removeGraphicsNodeKeyListener
public void removeGraphicsNodeKeyListener(GraphicsNodeKeyListener l)
Removes the specified 'global' GraphicsNodeKeyListener which is notified of all KeyEvents dispatched.- Specified by:
removeGraphicsNodeKeyListenerin interfaceEventDispatcher- Parameters:
l- the listener to remove
-
getListeners
public java.util.EventListener[] getListeners(java.lang.Class listenerType)
Returns an array of listeners that were added to this event dispatcher and of the specified type.- Specified by:
getListenersin interfaceEventDispatcher- Parameters:
listenerType- the type of the listeners to return
-
setEventDispatchEnabled
public void setEventDispatchEnabled(boolean b)
-
setEventQueueMaxSize
public void setEventQueueMaxSize(int n)
-
dispatchEvent
public void dispatchEvent(java.util.EventObject evt)
Dispatches the specified AWT event.- Specified by:
dispatchEventin interfaceEventDispatcher- Parameters:
evt- the event to dispatch
-
getCurrentLockState
protected int getCurrentLockState()
Returns a bitmask representing the state of the key locks.
-
dispatchKeyEvent
protected void dispatchKeyEvent(java.awt.event.KeyEvent evt)
Dispatches the specified AWT key event.- Parameters:
evt- the key event to dispatch
-
dispatchMouseEvent
protected void dispatchMouseEvent(java.awt.event.MouseEvent evt)
Dispatches the specified AWT mouse event.- Parameters:
evt- the mouse event to dispatch
-
dispatchMouseWheelEvent
protected void dispatchMouseWheelEvent(java.awt.event.MouseWheelEvent evt)
Dispatches the specified AWT mouse wheel event.- Parameters:
evt- the mouse wheel event 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
-
processMouseWheelEvent
protected void processMouseWheelEvent(GraphicsNodeMouseWheelEvent evt)
Processes the specified event by firing the 'global' listeners attached to this event dispatcher.- Parameters:
evt- the event to process
-
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
-
incrementKeyTarget
private void incrementKeyTarget()
-
decrementKeyTarget
private void decrementKeyTarget()
-
setNodeIncrementEvent
public void setNodeIncrementEvent(java.awt.event.InputEvent e)
Associates all InputEvents of typee.getID()with "incrementing" of the currently selected GraphicsNode.- Specified by:
setNodeIncrementEventin interfaceEventDispatcher
-
setNodeDecrementEvent
public void setNodeDecrementEvent(java.awt.event.InputEvent e)
Associates all InputEvents of typee.getID()with "decrementing" of the currently selected GraphicsNode. The notion of "currently selected" GraphicsNode is used for dispatching KeyEvents.- Specified by:
setNodeDecrementEventin interfaceEventDispatcher
-
isNodeIncrementEvent
protected boolean isNodeIncrementEvent(java.awt.event.InputEvent e)
Returns true if the input event e is a node increment event, false otherwise.- Parameters:
e- the input event
-
isNodeDecrementEvent
protected boolean isNodeDecrementEvent(java.awt.event.InputEvent e)
Returns true if the input event e is a node decrement event, false otherwise.
-
isMetaDown
protected static boolean isMetaDown(int modifiers)
Returns whether the meta key is down according to the given modifiers bitfield.
-
-