y.view
Class ViewMode

java.lang.Object
  extended by y.view.ViewMode
All Implemented Interfaces:
MouseListener, MouseMotionListener, EventListener, MouseInputListener
Direct Known Subclasses:
AbstractSelectionBoxMode, AutoDragViewMode, CellEditorMode, CreateChildEdgeMode, CreateEdgeMode, EditMode, HotSpotMode, InteractiveViewMode, MagnifierViewMode, MouseInputMode, MoveLabelMode, MovePortMode, MoveSelectionMode, MoveViewPortMode, NavigationMode, OrthogonalMoveBendsMode, PopupMode

public class ViewMode
extends Object
implements MouseInputListener

This class handles events coming from a Graph2DView. Events are mouse events like mouse button pressed, mouse button released, etc. on a certain position in the view. Depending on the event, a method of the view mode is invoked with coordinates of the mouse pointer as argument. The coordinates are world coordinates. If the view is in grid mode, these coordinates are always grid coordinates.

A ViewMode can have a child, in this case all events are delegated to the child.

 

Field Summary
static String ACTIVE_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static String ACTIVE_VIEW_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static String CHILD_MODE_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static String EDITING_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static String GRAB_FOCUS_ENABLED_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
protected  MouseEvent lastClickEvent
          Stores last mouse event received via mouseClicked(MouseEvent)
protected  MouseEvent lastDragEvent
          Stores last mouse event received via mouseDragged(MouseEvent)
protected  MouseEvent lastMoveEvent
          Stores last mouse event received via mouseMoved(java.awt.event.MouseEvent)
protected  MouseEvent lastPressEvent
          Stores last mouse event received via mousePressed(MouseEvent)
protected  MouseEvent lastReleaseEvent
          Stores last mouse event received via mouseReleased(MouseEvent)
static String MODIFIER_MASK_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
static String NAME_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
protected  int originalX
          Original view x-coordinate received with the last mouse event.
protected  int originalY
          Original view y-coordinate received with the last mouse event.
static String PARENT_MODE_PROPERTY
          Property name constant used for PropertyChangeEvent.getPropertyName().
protected  Graph2DView view
          The view this mode operates on.
 
Constructor Summary
ViewMode()
          Creates a new ViewMode
ViewMode(ViewContainer vc)
          Creates a new ViewMode which is bound to a given ViewContainer
 
Method Summary
 void activate(boolean b)
          Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ACTIVE_PROPERTY as the property name.
 void addPropertyChangeListener(PropertyChangeListener pcl)
          Adds a PropertyChangeListener to the list of registered listeners.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener pcl)
          Adds a PropertyChangeListener for the given property to the list of registered listeners.
 void cancelEditing()
          This can be used to cleanly exit an edit that is currently in progress.
protected  void firePropertyChange(String name, boolean oldValue, boolean newValue)
          Helper method for subclasses to indicate a property change.
protected  void firePropertyChange(String name, int oldValue, int newValue)
          Helper method for subclasses to indicate a property change.
protected  void firePropertyChange(String name, Object oldValue, Object newValue)
          Helper method for subclasses to indicate a property change.
 ViewMode getChild()
          Returns the current child ViewMode or null if this mode has no child.
protected  Graph2D getGraph2D()
          Returns the Graph2D displayed in the view this mode belongs to.
protected  double getGridX(double x)
          Translates a given X-Coordinate to the next X grid line coordinate.
protected  double getGridY(double y)
          Translates a given X-Coordinate to the next X grid line coordinate.
protected  HitInfo getHitInfo(double x, double y)
          Query which object is located at position (x,y) in world coordinate space.
protected  HitInfo getHitInfo(MouseEvent ev)
          Query which object is located at position (x,y) in the view.
protected  HitInfo getLastHitInfo()
          Returns the most current HitInfo object that has been set/was returned by getHitInfo(double, double).
 int getModifierMask()
          Gets the current modifierMask.
 String getName()
          Get the name of this mode
 ViewMode getParent()
          Returns the current parent ViewMode or null if this mode has no parent.
 void init()
          This method is called in a child mode when it gets installed in another mode.
 boolean isActive()
          Returns whether this Mode has been activate(boolean)d previously.
 boolean isEditing()
          Determines whether the mode is currently "editing".
 boolean isGrabFocusEnabled()
          Returns whether or not the UI focus should be grabbed by the Graph2DView associated with this mode, when pressing the mouse button.
 boolean isGridMode()
          Query if gridmode is active.
protected  boolean isModifierPressed(MouseEvent me)
          This method determines whether at the creation time of the given MouseEvent the modifier key was pressed.
 void mouseClicked(double x, double y)
          Called when the mouse was clicked
 void mouseClicked(MouseEvent e)
          A mouse button get clicked
 void mouseDragged(MouseEvent e)
          The mouse gets dragged
 void mouseDraggedLeft(double x, double y)
          Called when the mouse was dragged with the left button down.
 void mouseDraggedMiddle(double x, double y)
          Called when the mouse was dragged with the middle button down.
 void mouseDraggedRight(double x, double y)
          Called when the mouse was dragged with the right button down.
 void mouseEntered(MouseEvent e)
          The mouse enters the viewer component.
 void mouseExited(MouseEvent e)
          The mouse leaves the viewer component.
 void mouseMoved(double x, double y)
          Called when the mouse was moved
 void mouseMoved(MouseEvent e)
          The Mouse gets moved.
 void mousePressed(MouseEvent e)
          A mouse button gets pressed.
 void mousePressedLeft(double x, double y)
          Called when the left mouse button was pressed.
 void mousePressedMiddle(double x, double y)
          Called when the middle mouse button was pressed.
 void mousePressedRight(double x, double y)
          Called when the right mouse button was pressed.
 void mouseReleased(double x, double y)
          Called when a mouse button was released.
 void mouseReleased(MouseEvent e)
          A mouse button get released
 void mouseReleasedLeft(double x, double y)
          Called when the left mouse button was released.
 void mouseReleasedMiddle(double x, double y)
          Called when the middle mouse button was released.
 void mouseReleasedRight(double x, double y)
          Called when the right mouse button was released
 void mouseShiftPressedLeft(double x, double y)
          Called when the left mouse button was pressed with shift key down.
 void mouseShiftPressedMiddle(double x, double y)
          Called when the middle mouse button was pressed with shift key down.
 void mouseShiftPressedRight(double x, double y)
          Called when the right mouse button was pressed with shift key down.
 void mouseShiftReleasedLeft(double x, double y)
          Called when the left mouse button was released with shift key down.
 void mouseShiftReleasedMiddle(double x, double y)
          Called when the middle mouse button was released with shift key down NOTE: this implementation calls mouseReleasedMiddle(double, double)!
 void mouseShiftReleasedRight(double x, double y)
          Called when the right mouse button was released with shift key down.
 void reactivateParent()
          The parent of this ViewMode is reactivated and this ViewMode is deactivated.
 void removePropertyChangeListener(PropertyChangeListener pcl)
          Removes a PropertyChangeListener from the list of registered listeners.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener pcl)
          Removes a PropertyChangeListener for a given property from the list of registered listeners.
 void setActiveView(Graph2DView view)
          Sets the active view this mode operates on.
 void setChild(ViewMode child, MouseEvent pressEvent, MouseEvent dragEvent)
          Sets a child mode for this mode.
 void setChild(ViewMode child, MouseEvent pressEvent, MouseEvent dragEvent, MouseEvent releaseEvent)
          Sets a child mode for this mode.
protected  void setEditing(boolean editing)
          Used by subclasses to update the current state.
 void setGrabFocusEnabled(boolean enabled)
          Whether or not the UI focus should be grabbed by the Graph2DView associated with this mode, when pressing the mouse button.
 void setGridMode(boolean mode)
          Enable/Disable grid mode of the Graph2DView.
 void setLastHitInfo(HitInfo hInfo)
          Sets the given HitInfo as the most current HitInfo object, which is referred to as "last hit info."
 void setModifierMask(int modifierMask)
          Sets the current modifierMask.
 void setName(String s)
          Set the name of this mode, important for resource handling.
 void setParent(ViewMode l)
          Sets the parent mode of a child mode.
protected  double translateX(int x)
          Returns the world coordinate value of the given x view coordinate value.
protected  double translateY(int y)
          Returns the world coordinate value of the given y view coordinate value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTIVE_PROPERTY

public static final String ACTIVE_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if activate(boolean) is called

See Also:
Constant Field Values

CHILD_MODE_PROPERTY

public static final String CHILD_MODE_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setChild(ViewMode, MouseEvent, MouseEvent, MouseEvent) is called.

See Also:
Constant Field Values

ACTIVE_VIEW_PROPERTY

public static final String ACTIVE_VIEW_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setActiveView(Graph2DView) is called.

See Also:
Constant Field Values

GRAB_FOCUS_ENABLED_PROPERTY

public static final String GRAB_FOCUS_ENABLED_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setGrabFocusEnabled(boolean) is called.

See Also:
Constant Field Values

PARENT_MODE_PROPERTY

public static final String PARENT_MODE_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setParent(ViewMode) is called

See Also:
Constant Field Values

NAME_PROPERTY

public static final String NAME_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setName(String) is called

See Also:
Constant Field Values

MODIFIER_MASK_PROPERTY

public static final String MODIFIER_MASK_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setModifierMask(int) is called

See Also:
Constant Field Values

EDITING_PROPERTY

public static final String EDITING_PROPERTY
Property name constant used for PropertyChangeEvent.getPropertyName(). This property is used if setEditing(boolean) is called

See Also:
Constant Field Values

view

protected Graph2DView view
The view this mode operates on.


originalX

protected int originalX
Original view x-coordinate received with the last mouse event.


originalY

protected int originalY
Original view y-coordinate received with the last mouse event.


lastPressEvent

protected MouseEvent lastPressEvent
Stores last mouse event received via mousePressed(MouseEvent)


lastDragEvent

protected MouseEvent lastDragEvent
Stores last mouse event received via mouseDragged(MouseEvent)


lastMoveEvent

protected MouseEvent lastMoveEvent
Stores last mouse event received via mouseMoved(java.awt.event.MouseEvent)


lastReleaseEvent

protected MouseEvent lastReleaseEvent
Stores last mouse event received via mouseReleased(MouseEvent)


lastClickEvent

protected MouseEvent lastClickEvent
Stores last mouse event received via mouseClicked(MouseEvent)

Constructor Detail

ViewMode

public ViewMode()
Creates a new ViewMode


ViewMode

public ViewMode(ViewContainer vc)
Creates a new ViewMode which is bound to a given ViewContainer

Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener pcl)
Adds a PropertyChangeListener to the list of registered listeners.


addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener pcl)
Adds a PropertyChangeListener for the given property to the list of registered listeners.


removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener pcl)
Removes a PropertyChangeListener from the list of registered listeners.


removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener pcl)
Removes a PropertyChangeListener for a given property from the list of registered listeners.


firePropertyChange

protected void firePropertyChange(String name,
                                  Object oldValue,
                                  Object newValue)
Helper method for subclasses to indicate a property change.


firePropertyChange

protected void firePropertyChange(String name,
                                  boolean oldValue,
                                  boolean newValue)
Helper method for subclasses to indicate a property change.


firePropertyChange

protected void firePropertyChange(String name,
                                  int oldValue,
                                  int newValue)
Helper method for subclasses to indicate a property change.


isEditing

public boolean isEditing()
Determines whether the mode is currently "editing". Interpretation of this flag depends on the exact implementation. Usually this flag should be set if the editMode cannot simply be deactivated without interrupting the user's current input.
Subclassed are encouraged to keep this flag always up to date.

Returns:
whether this mode is currently editing something
See Also:
setEditing(boolean), cancelEditing()

setEditing

protected void setEditing(boolean editing)
Used by subclasses to update the current state. This is a bound property using EDITING_PROPERTY as the property name.

Parameters:
editing - the new editing state
See Also:
isEditing(), cancelEditing()

cancelEditing

public void cancelEditing()
                   throws UnsupportedOperationException
This can be used to cleanly exit an edit that is currently in progress.
The implementation and interpretation of "cancelling" is left to subclasses. This implementation does nothing but calls setEditing(false) if isEditing() returns true

Throws:
UnsupportedOperationException - if the editing cannot be cancelled for any reason.

setActiveView

public void setActiveView(Graph2DView view)
Sets the active view this mode operates on. This method is typically called whenever a ViewContainer changes it's current view. This is a bound property using ACTIVE_VIEW_PROPERTY as the property name.


activate

public void activate(boolean b)
Invoked when the Mode is activated/deactivated from the ViewControl or via the setChild() and reactivateParent operations This behaves like a bound property using ACTIVE_PROPERTY as the property name.

Parameters:
b - set true when mode was activated false otherwise

isActive

public boolean isActive()
Returns whether this Mode has been activate(boolean)d previously.


setGridMode

public void setGridMode(boolean mode)
Enable/Disable grid mode of the Graph2DView. This call is a convenience method that delegates the actual request to the Graph2DView.


isGridMode

public boolean isGridMode()
Query if gridmode is active. This call is a convenience method that delegates the actual request to the Graph2DView.


setGrabFocusEnabled

public void setGrabFocusEnabled(boolean enabled)
Whether or not the UI focus should be grabbed by the Graph2DView associated with this mode, when pressing the mouse button.

By default this property is set to true. This is a bound property using GRAB_FOCUS_ENABLED_PROPERTY as the property name.


isGrabFocusEnabled

public boolean isGrabFocusEnabled()
Returns whether or not the UI focus should be grabbed by the Graph2DView associated with this mode, when pressing the mouse button.


setChild

public void setChild(ViewMode child,
                     MouseEvent pressEvent,
                     MouseEvent dragEvent)
Sets a child mode for this mode. All mouse events will be delegated this child mode until the child calls reactivateParent(). After the child mode is installed it will receive the given press and drag events before any other mouse events. Only non-null events will be delegated.


setChild

public void setChild(ViewMode child,
                     MouseEvent pressEvent,
                     MouseEvent dragEvent,
                     MouseEvent releaseEvent)
Sets a child mode for this mode. All mouse events will be delegated this child mode until the child calls reactivateParent(). After the child mode is installed it will receive the given press, drag and release events before any other mouse events. Only non-null events will be delegated.
Prior to that the child mode will be informed about the active view, its new parent, the last HitInfo, and will be activated.
If null is passed as the child or the child calls its reactivateParent() method, the previously installed child will be deactivated and have its parent set to null. This behaves like a bound property using CHILD_MODE_PROPERTY as the property name.


init

public void init()
This method is called in a child mode when it gets installed in another mode.

See Also:
setChild(ViewMode,MouseEvent,MouseEvent)

reactivateParent

public void reactivateParent()
The parent of this ViewMode is reactivated and this ViewMode is deactivated.


setParent

public void setParent(ViewMode l)
Sets the parent mode of a child mode. This is a bound property using PARENT_MODE_PROPERTY as the property name.


getParent

public ViewMode getParent()
Returns the current parent ViewMode or null if this mode has no parent.

Returns:
the current parent mode or null
See Also:
reactivateParent(), setChild(ViewMode, java.awt.event.MouseEvent, java.awt.event.MouseEvent, java.awt.event.MouseEvent)

getChild

public ViewMode getChild()
Returns the current child ViewMode or null if this mode has no child.

Returns:
the current child mode or null
See Also:
getParent(), setChild(ViewMode, java.awt.event.MouseEvent, java.awt.event.MouseEvent, java.awt.event.MouseEvent)

mousePressed

public void mousePressed(MouseEvent e)
A mouse button gets pressed.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
A mouse button get released

Specified by:
mouseReleased in interface MouseListener

mouseClicked

public void mouseClicked(MouseEvent e)
A mouse button get clicked

Specified by:
mouseClicked in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
The mouse gets dragged

Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
The Mouse gets moved. Delegates to