y.view
Class ViewMode

java.lang.Object
  |
  +--y.view.ViewMode
All Implemented Interfaces:
EventListener, MouseInputListener, MouseListener, MouseMotionListener
Direct Known Subclasses:
AbstractSelectionBoxMode, CreateEdgeMode, EditMode, HotSpotMode, InteractiveViewMode, MoveLabelMode, MovePortMode, MoveSelectionMode, MoveViewPortMode, NavigationMode, PopupMode

public class ViewMode
extends Object
implements MouseInputListener

This class handles events comming 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
protected  MouseEvent lastClickEvent
          Stores last mouse event received via ViewMode.mouseClicked(MouseEvent)
protected  MouseEvent lastDragEvent
          Stores last mouse event received via ViewMode.mouseDragged(MouseEvent)
protected  MouseEvent lastPressEvent
          Stores last mouse event received via ViewMode.mousePressed(MouseEvent)
protected  MouseEvent lastReleaseEvent
          Stores last mouse event received via ViewMode.mouseReleased(MouseEvent)
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.
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/deactiveted from the ViewControl
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 objects are located on Position (x,y) in the view.
protected  HitInfo getHitInfo(MouseEvent ev)
          Query which objects are located on Position (x,y) in the view.
protected  HitInfo getLastHitInfo()
          Returns the last hit info that has was returned by ViewMode.getHitInfo(double,double).
 String getName()
          Get the name of this mode
 void init()
          This method is called in a child mode when it gets installed in another mode.
 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.
 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 ViewMode.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 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.
 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)
           
 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

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 ViewMode.mousePressed(MouseEvent)


lastDragEvent

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


lastReleaseEvent

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


lastClickEvent

protected MouseEvent lastClickEvent
Stores last mouse event received via ViewMode.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

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.


activate

public void activate(boolean b)
Invoked when the Mode is activated/deactiveted from the ViewControl

Parameters:
b - set true when mode should be activated false otherwise

setGridMode

public void setGridMode(boolean mode)
Enable/Disable grid mode of the Graph2DView


isGridMode

public boolean isGridMode()
Query if gridmode is active.


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 feature is active.


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 ViewMode.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 ViewMode.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.


init

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

See Also:
ViewMode.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.


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 ViewMode.mouseMoved(double,double).

Specified by:
mouseMoved in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
The mouse enters the viewer component.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
The mouse leaves the viewer component.

Specified by:
mouseExited in interface MouseListener

getGridX

protected double getGridX(double x)
Translates a given X-Coordinate to the next X grid line coordinate.


getGridY

protected double getGridY(double y)
Translates a given X-Coordinate to the next X grid line coordinate.


getGraph2D

protected Graph2D getGraph2D()
Returns the Graph2D displayed in the view this mode belongs to.


translateX

protected double translateX(int x)
Returns the world coordinate value of the given x view coordinate value


translateY

protected double translateY(int y)
Returns the world coordinate value of the given y view coordinate value


setName

public void setName(String s)
Set the name of this mode, important for resource handling


getName

public String getName()
Get the name of this mode


getHitInfo

protected HitInfo getHitInfo(MouseEvent ev)
Query which objects are located on Position (x,y) in the view.


getHitInfo

protected HitInfo getHitInfo(double x,
                             double y)
Query which objects are located on Position (x,y) in the view.


getLastHitInfo

protected HitInfo getLastHitInfo()
Returns the last hit info that has was returned by ViewMode.getHitInfo(double,double).


setLastHitInfo

public void setLastHitInfo(HitInfo hInfo)

mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Called when the left mouse button was pressed.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftPressedLeft

public void mouseShiftPressedLeft(double x,
                                  double y)
Called when the left mouse button was pressed with shift key down. NOTE: this implementation calls ViewMode.mousePressedLeft(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftPressedRight

public void mouseShiftPressedRight(double x,
                                   double y)
Called when the right mouse button was pressed with shift key down. NOTE: this implementation calls ViewMode.mousePressedRight(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftPressedMiddle

public void mouseShiftPressedMiddle(double x,
                                    double y)
Called when the middle mouse button was pressed with shift key down. NOTE: this implementation calls ViewMode.mousePressedMiddle(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mousePressedMiddle

public void mousePressedMiddle(double x,
                               double y)
Called when the middle mouse button was pressed.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mousePressedRight

public void mousePressedRight(double x,
                              double y)
Called when the right mouse button was pressed.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseReleased

public void mouseReleased(double x,
                          double y)
Called when a mouse button was released.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseReleasedLeft

public void mouseReleasedLeft(double x,
                              double y)
Called when the left mouse button was released.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftReleasedLeft

public void mouseShiftReleasedLeft(double x,
                                   double y)
Called when the left mouse button was released with shift key down. NOTE: this implementation calls ViewMode.mouseReleasedLeft(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftReleasedRight

public void mouseShiftReleasedRight(double x,
                                    double y)
Called when the right mouse button was released with shift key down. NOTE: this implementation calls ViewMode.mouseReleasedRight(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseReleasedMiddle

public void mouseReleasedMiddle(double x,
                                double y)
Called when the middle mouse button was released.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseShiftReleasedMiddle

public void mouseShiftReleasedMiddle(double x,
                                     double y)
Called when the middle mouse button was released with shift key down NOTE: this implementation calls ViewMode.mouseReleasedMiddle(double, double)!

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseReleasedRight

public void mouseReleasedRight(double x,
                               double y)
Called when the right mouse button was released

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedLeft

public void mouseDraggedLeft(double x,
                             double y)
Called when the mouse was dragged with the left button down.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedMiddle

public void mouseDraggedMiddle(double x,
                               double y)
Called when the mouse was dragged with the middle button down.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseDraggedRight

public void mouseDraggedRight(double x,
                              double y)
Called when the mouse was dragged with the right button down.

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseClicked

public void mouseClicked(double x,
                         double y)
Called when the mouse was clicked

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

mouseMoved

public void mouseMoved(double x,
                       double y)
Called when the mouse was moved

Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003