diva.canvas.event
Class LayerEvent

java.lang.Object
  extended by java.util.EventObject
      extended by java.awt.AWTEvent
          extended by java.awt.event.ComponentEvent
              extended by java.awt.event.InputEvent
                  extended by java.awt.event.MouseEvent
                      extended by diva.canvas.event.LayerEvent
All Implemented Interfaces:
java.io.Serializable

public class LayerEvent
extends java.awt.event.MouseEvent

The class representing mouse events in layers. This class extends the AWT MouseEvent class, but adds the notion of floating-point coordinates and a "layer source" and "figure source" as well as a component source. Any code that processes a LayerEvent should be sure to use the methods getLayerX, getLayerY, getLayerPoint, instead of the inherited methods getX, getY, getPoint. (Originally, this class was designed to inherit from the AWT InputEvent class, which would have avoided the awkwardness of having two sets of coordinates in the same event object. This wasn't possible because InputEvent has only one package-scope constructor, and hence cannot be subclassed outside the AWT package.)

Version:
$Id: LayerEvent.java 43472 2006-08-21 23:16:56Z cxh $
Author:
John Reekie
See Also:
Serialized Form

Field Summary
private  java.awt.event.MouseEvent _backingEvent
          The event that this event was constructed from.
private  Figure _figureSource
          The figure source
private  CanvasLayer _layerSource
          The layer source
private  double _layerX
          The x coordinate.
private  double _layerY
          The y coordinate.
 
Fields inherited from class java.awt.event.MouseEvent
BUTTON1, BUTTON2, BUTTON3, MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_EXITED, MOUSE_FIRST, MOUSE_LAST, MOUSE_MOVED, MOUSE_PRESSED, MOUSE_RELEASED, MOUSE_WHEEL, NOBUTTON
 
Fields inherited from class java.awt.event.InputEvent
ALT_DOWN_MASK, ALT_GRAPH_DOWN_MASK, ALT_GRAPH_MASK, ALT_MASK, BUTTON1_DOWN_MASK, BUTTON1_MASK, BUTTON2_DOWN_MASK, BUTTON2_MASK, BUTTON3_DOWN_MASK, BUTTON3_MASK, CTRL_DOWN_MASK, CTRL_MASK, META_DOWN_MASK, META_MASK, SHIFT_DOWN_MASK, SHIFT_MASK
 
Fields inherited from class java.awt.event.ComponentEvent
COMPONENT_FIRST, COMPONENT_HIDDEN, COMPONENT_LAST, COMPONENT_MOVED, COMPONENT_RESIZED, COMPONENT_SHOWN
 
Fields inherited from class java.awt.AWTEvent
ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, consumed, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, id, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
LayerEvent(java.awt.event.MouseEvent e)
          Create a new layer event from the given mouse event.
LayerEvent(java.awt.event.MouseEvent e, int id)
          Create a new layer event from the given mouse event, but give it a different ID.
 
Method Summary
 void consume()
          Consume this event.
private static java.lang.String flagToString(int flag)
          Print the string representation of a single flag
 Figure getFigureSource()
          Get the figure that the event occurred on.
 java.awt.geom.Point2D getLayerPoint()
          Get the point where the event occurred.
 CanvasLayer getLayerSource()
          Get the layer that the event occurred on.
 double getLayerX()
          Get the horizontal component of the point where the event occurred.
 double getLayerY()
          Get the vertical component of the point where the event occurred.
static java.lang.String idToString(int id)
          Print the string representation of an event ID
 void setFigureSource(Figure figureSource)
          Set the figure that the event occurred on.
 void setLayerPoint(java.awt.geom.Point2D point)
          Set the layer position of the event
 void setLayerSource(CanvasLayer layerSource)
          Set the layer that the event occurred on.
 void setLayerX(double x)
          Set the layer X position of the event
 void setLayerY(double y)
          Set the layer Y position of the event
 java.lang.String toString()
          Print the string representation of this event
static java.lang.String toString(int flags)
          Print the string representation of modifier flags
 void transform(java.awt.geom.AffineTransform at)
          Transform the layer coordinates of the event with the given transform.
 
Methods inherited from class java.awt.event.MouseEvent
getButton, getClickCount, getMouseModifiersText, getPoint, getX, getY, isPopupTrigger, paramString, translatePoint
 
Methods inherited from class java.awt.event.InputEvent
getModifiers, getModifiersEx, getModifiersExText, getWhen, isAltDown, isAltGraphDown, isConsumed, isControlDown, isMetaDown, isShiftDown
 
Methods inherited from class java.awt.event.ComponentEvent
getComponent
 
Methods inherited from class java.awt.AWTEvent
getID, setSource
 
Methods inherited from class java.util.EventObject
getSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_layerSource

private CanvasLayer _layerSource
The layer source


_figureSource

private Figure _figureSource
The figure source


_layerX

private double _layerX
The x coordinate.


_layerY

private double _layerY
The y coordinate.


_backingEvent

private java.awt.event.MouseEvent _backingEvent
The event that this event was constructed from.

Constructor Detail

LayerEvent

public LayerEvent(java.awt.event.MouseEvent e)
Create a new layer event from the given mouse event. The layer and figure event sources will be set to null, and the layer coordinates will be the same as the canvas coordinates.


LayerEvent

public LayerEvent(java.awt.event.MouseEvent e,
                  int id)
Create a new layer event from the given mouse event, but give it a different ID. The layer and figure event sources will be set to null, and the layer coordinates will be the same as the canvas coordinates.

Method Detail

consume

public void consume()
Consume this event. If the event was constructed from a backing mouse event, consume the backing mouse event too.

Overrides:
consume in class java.awt.event.InputEvent

getLayerSource

public CanvasLayer getLayerSource()
Get the layer that the event occurred on.


getFigureSource

public Figure getFigureSource()
Get the figure that the event occurred on. This is null if the event did not occur on a figure.


getLayerPoint

public java.awt.geom.Point2D getLayerPoint()
Get the point where the event occurred. The point is in layer coordinates, and should be assumed to be a floating-point coordinate. This point is to be a copy of any internal data, so the caller can modify it.


getLayerX

public double getLayerX()
Get the horizontal component of the point where the event occurred. The value is in layer coordinates, and should be assumed to be a floating-point coordinate.


getLayerY

public double getLayerY()
Get the vertical component of the point where the event occurred. The value is in layer coordinates, and should be assumed to be a floating-point coordinate.


setFigureSource

public void setFigureSource(Figure figureSource)
Set the figure that the event occurred on.


setLayerSource

public void setLayerSource(CanvasLayer layerSource)
Set the layer that the event occurred on.


setLayerPoint

public void setLayerPoint(java.awt.geom.Point2D point)
Set the layer position of the event


setLayerX

public void setLayerX(double x)
Set the layer X position of the event


setLayerY

public void setLayerY(double y)
Set the layer Y position of the event


toString

public java.lang.String toString()
Print the string representation of this event

Overrides:
toString in class java.awt.AWTEvent

toString

public static java.lang.String toString(int flags)
Print the string representation of modifier flags


flagToString

private static java.lang.String flagToString(int flag)
Print the string representation of a single flag


idToString

public static java.lang.String idToString(int id)
Print the string representation of an event ID


transform

public void transform(java.awt.geom.AffineTransform at)
Transform the layer coordinates of the event with the given transform.