diva.canvas.event
Class EventLayer

java.lang.Object
  extended by diva.canvas.CanvasLayer
      extended by diva.canvas.event.EventLayer
All Implemented Interfaces:
CanvasComponent, EventAcceptor

public class EventLayer
extends CanvasLayer
implements EventAcceptor

An event layer is a canvas layer that accepts mouse events. It is designed to be layered over or under other layers, such as FigureLayer, and accepts a number of options that control whether it consumes events and so on. Event layers can have event listeners attached to them, which will be notified when events occur.

Sample uses of the event layer

Version:
$Id: EventLayer.java 53042 2009-04-10 20:31:21Z cxh $
Author:
John Reekie

Field Summary
private  boolean _consuming
          The consuming flag.
private  Interactor _currentInteractor
          The current interactor
private  boolean _enabled
          The enabled flag.
private  java.util.ArrayList<Interactor> _interactors
          The list of attached interactors
private  LayerListener layerListener
          The layer listeners
private  LayerMotionListener layerMotionListener
          The layer motion listeners
 
Constructor Summary
EventLayer()
           
 
Method Summary
 void addInteractor(Interactor i)
          Add an interactor to this interactor.
 void addLayerListener(LayerListener l)
          Add the given layer listener to this dispatcher.
 void addLayerMotionListener(LayerMotionListener l)
          Add the given layer motion listener to this dispatcher.
 void dispatchEvent(java.awt.AWTEvent event)
          Dispatch an AWT event on this layer.
 java.util.Iterator interactors()
          Return an interactor over the attached interactors.
 boolean isConsuming()
          Test the consuming flag of this layer.
 boolean isEnabled()
          Test the enabled flag of this layer.
protected  void processLayerEvent(LayerEvent event)
          Process a layer event.
 void removeInteractor(Interactor i)
          Remove the given interactor from this interactor.
 void removeLayerListener(LayerListener l)
          Remove the given layer listener from this dispatcher.
 void removeLayerMotionListener(LayerMotionListener l)
          Remove the given layer motion listener from this dispatcher.
 void setConsuming(boolean flag)
          Set the consuming flag of this layer.
 void setEnabled(boolean flag)
          Set the enabled flag of this layer.
 
Methods inherited from class diva.canvas.CanvasLayer
getCanvasPane, getLayerBounds, getParent, getToolTipText, getTransformContext, repaint, repaint, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.canvas.CanvasComponent
getParent, getTransformContext, repaint, repaint
 

Field Detail

_enabled

private boolean _enabled
The enabled flag.


_consuming

private boolean _consuming
The consuming flag.


_currentInteractor

private Interactor _currentInteractor
The current interactor


_interactors

private java.util.ArrayList<Interactor> _interactors
The list of attached interactors


layerListener

private transient LayerListener layerListener
The layer listeners


layerMotionListener

private transient LayerMotionListener layerMotionListener
The layer motion listeners

Constructor Detail

EventLayer

public EventLayer()
Method Detail

addInteractor

public void addInteractor(Interactor i)
Add an interactor to this interactor. The added interactor will have events forwarded to it if it accepts the event.


addLayerListener

public void addLayerListener(LayerListener l)
Add the given layer listener to this dispatcher.


addLayerMotionListener

public void addLayerMotionListener(LayerMotionListener l)
Add the given layer motion listener to this dispatcher.


dispatchEvent

public void dispatchEvent(java.awt.AWTEvent event)
Dispatch an AWT event on this layer. Currently only layer events are handled.

Specified by:
dispatchEvent in interface EventAcceptor

interactors

public java.util.Iterator interactors()
Return an interactor over the attached interactors.


isConsuming

public boolean isConsuming()
Test the consuming flag of this layer. If this flag is set, the layer consumes all input events.


isEnabled

public boolean isEnabled()
Test the enabled flag of this layer. Note that this flag does not indicate whether the layer is actually enabled, as its pane or one if its ancestors may not be enabled.

Specified by:
isEnabled in interface EventAcceptor

processLayerEvent

protected void processLayerEvent(LayerEvent event)
Process a layer event. This method dispatches the event to any registered layer listeners or layer motion listeners, and then to any interactors. If the "consuming" flag is set, it consumes the event before returning.


removeInteractor

public void removeInteractor(Interactor i)
Remove the given interactor from this interactor.


removeLayerListener

public void removeLayerListener(LayerListener l)
Remove the given layer listener from this dispatcher.


removeLayerMotionListener

public void removeLayerMotionListener(LayerMotionListener l)
Remove the given layer motion listener from this dispatcher.


setConsuming

public void setConsuming(boolean flag)
Set the consuming flag of this layer. If this flag is set, the layer consumes all input events.


setEnabled

public void setEnabled(boolean flag)
Set the enabled flag of this layer. If the flag is false, then the layer will not respond to user input events.

Specified by:
setEnabled in interface EventAcceptor