y.view
Class EditMode

java.lang.Object
  |
  +--y.view.ViewMode
        |
        +--y.view.EditMode
All Implemented Interfaces:
EventListener, MouseInputListener, MouseListener, MouseMotionListener
Direct Known Subclasses:
HierarchyEditMode

public class EditMode
extends ViewMode

This view mode is the default edit mode for a Graph2DView. With this mode it is possible to

  1. Create nodes.
  2. Create edges.
  3. Create bends.
  4. Select and unselect graph elements.
  5. Display context sensitive popup menus for graph elements and the view background.
  6. Reassign ports positions.
  7. Reassign label positions.

This complex mode makes use of other minor modes that have specialized responsibilities. It is possible to exchange these minor modes by specialized versions.


Field Summary
protected  ViewMode createEdgeMode
           
protected  ViewMode hotSpotMode
           
protected  ViewMode moveLabelMode
           
protected  ViewMode movePortMode
           
protected  ViewMode moveSelectionMode
           
protected  ViewMode popupMode
          Predefined Modes, which represent substates
protected  Node pressedNode
          Will be set when the mouse was press over a node.
protected  ViewMode selectionBoxMode
           
 
Fields inherited from class y.view.ViewMode
lastClickEvent, lastDragEvent, lastPressEvent, lastReleaseEvent, originalX, originalY, view
 
Constructor Summary
EditMode()
          Instantiates a new EditMode
EditMode(ViewContainer vc)
          Instantiates a new EditMode for a given ViewContainer
 
Method Summary
 void activate(boolean b)
          Invoked when the Mode is activated/deactiveted from the ViewControl
 void allowBendCreation(boolean b)
          Allows or disallows bend creation.
 void allowEdgeCreation(boolean b)
          Allows or disallows edge creation.
 void allowMoveSelection(boolean b)
          Allows or disallows moving around the selected features of the displayed graph.
 void allowMoving(boolean b)
          Allows or disallows moving the viewport of the view via the right mouse button.
 void allowNodeCreation(boolean b)
          Allows or disallows node creation.
 void allowResizeNodes(boolean b)
          Allows or disllows resizing of nodes by dragging at the selection hotspots.
protected  ViewMode createCreateEdgeMode()
          Factory method, which creates the CreateEdgeMode.
protected  ViewMode createHotSpotMode()
          Factory method, which creates the HotSpotMode.
protected  ViewMode createMoveLabelMode()
          Factory method, which creates the MoveLabelMode.
protected  ViewMode createMovePortMode()
          Factory method, which creates the MovePortMode.
protected  ViewMode createMoveSelectionMode()
          Factory method, which creates the MoveSelectionMode.
protected  ViewMode createPopupMode()
          Factory method, which can create the PopupMode.
protected  ViewMode createSelectionBoxMode()
          Factory method, which creates the SelectionBoxMode.
 boolean doAllowBendCreation()
          Returns true iff the creation of bends should be allowed.
 boolean doAllowEdgeCreation()
          Returns true iff the creation of edges should be allowed.
 boolean doAllowMoveSelection()
          Whether or not to allow moving around the selected features of the displayed graph.
 boolean doAllowMoving()
          Whether or not to allow moving the viewport of the view via right mouse drag action.
 boolean doAllowNodeCreation()
          Returns true iff the creation of nodes should be allowed.
 boolean doAllowResizeNodes()
          Whether or not to allow resizing of nodes by dragging at the selection hotspots.
 boolean doShowEdgeTips()
          Returns true if this mode should display tip text for an edge.
 boolean doShowNodeTips()
          Returns true if this mode should display tip text for a node.
 ViewMode getCreateEdgeMode()
          Returns the minor create edge mode associated with this mode.
protected  String getEdgeTip(Edge e)
          Returns the tip text displayed for the given edge.
 ViewMode getHotSpotMode()
          Getter for child mode HotSpotMode.
 ViewMode getMoveLabelMode()
          Getter for child mode MoveLabelMode.
 ViewMode getMovePortMode()
          Getter for child mode MovePortMode.
 ViewMode getMoveSelectionMode()
          Returns the minor move selection mode associated with this mode.
protected  String getNodeTip(Node v)
          Returns the tip text displayed for the given node.
 ViewMode getPopupMode()
          Returns the minor popup mode associated with this mode
 ViewMode getSelectionBoxMode()
          Returns the minor selection box mode associated with this mode.
protected  boolean isCreateEdgeGesture(MouseEvent lastPress, MouseEvent lastDrag)
           
 void mouseDraggedLeft(double x, double y)
          Activates a minor mode.
 void mouseMoved(double x, double y)
          When moving the mouse, the mouse cursor has to be adjusted.
 void mousePressedLeft(double x, double y)
          Takes the given coordiante and performs with it a hit test on all graph elements.
 void mousePressedRight(double x, double y)
          If a popup mode is associates with this mode then it will be actived.
 void mouseReleasedLeft(double x, double y)
          Depending on the history, actions are triggered, but only if Mouse was not moved since the button was pressed.
 void mouseShiftPressedLeft(double x, double y)
          Takes the given coordiante and performs with it a hit test on all graph elements.
 void mouseShiftReleasedLeft(double x, double y)
          Depending on the history, actions are triggered, but only if Mouse was not moved since the button was pressed.
protected  void nodeClicked(Node v)
          This method gets called after a left mouse click on a node occured.
protected  void nodeCreated(Node v)
          This method gets called after a new node was completely created by this mode.
 void setCreateEdgeMode(ViewMode mode)
          Sets the minor create edge mode associated with this mode.
 void setHotSpotMode(ViewMode hotSpotMode)
          Setter for child mode HotSpotMode.
 void setMoveLabelMode(ViewMode moveLabelMode)
          Setter for child mode MoveLabelMode.
 void setMovePortMode(ViewMode movePortMode)
          Setter for child mode MovePortMode.
 void setMoveSelectionMode(ViewMode mode)
          Sets the minor move selection mode associated with this mode.
 void setPopupMode(ViewMode mode)
          Sets the minor popup mode associated with this mode.
 void setSelectionBoxMode(ViewMode mode)
          Sets the minor selection box mode associated with this mode.
 void showEdgeTips(boolean b)
          If set to true this mode will show a tip displaying whatever is returned by EditMode.getEdgeTip(Edge e).
 void showNodeTips(boolean b)
          If set to true this mode will show a tip displaying whatever is returned by EditMode.getNodeTip(Node v).
 
Methods inherited from class y.view.ViewMode
getGraph2D, getGridX, getGridY, getHitInfo, getHitInfo, getLastHitInfo, getName, init, isGrabFocusEnabled, isGridMode, mouseClicked, mouseClicked, mouseDragged, mouseDraggedMiddle, mouseDraggedRight, mouseEntered, mouseExited, mouseMoved, mousePressed, mousePressedMiddle, mouseReleased, mouseReleased, mouseReleasedMiddle, mouseReleasedRight, mouseShiftPressedMiddle, mouseShiftPressedRight, mouseShiftReleasedMiddle, mouseShiftReleasedRight, reactivateParent, setActiveView, setChild, setChild, setGrabFocusEnabled, setGridMode, setLastHitInfo, setName, setParent, translateX, translateY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pressedNode

protected Node pressedNode
Will be set when the mouse was press over a node.


popupMode

protected ViewMode popupMode
Predefined Modes, which represent substates


hotSpotMode

protected ViewMode hotSpotMode

selectionBoxMode

protected ViewMode selectionBoxMode

createEdgeMode

protected ViewMode createEdgeMode

moveSelectionMode

protected ViewMode moveSelectionMode

moveLabelMode

protected ViewMode moveLabelMode

movePortMode

protected ViewMode movePortMode
Constructor Detail

EditMode

public EditMode(ViewContainer vc)
Instantiates a new EditMode for a given ViewContainer


EditMode

public EditMode()
Instantiates a new EditMode

Method Detail

createHotSpotMode

protected ViewMode createHotSpotMode()
Factory method, which creates the HotSpotMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createMovePortMode

protected ViewMode createMovePortMode()
Factory method, which creates the MovePortMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createMoveLabelMode

protected ViewMode createMoveLabelMode()
Factory method, which creates the MoveLabelMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createMoveSelectionMode

protected ViewMode createMoveSelectionMode()
Factory method, which creates the MoveSelectionMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createCreateEdgeMode

protected ViewMode createCreateEdgeMode()
Factory method, which creates the CreateEdgeMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createSelectionBoxMode

protected ViewMode createSelectionBoxMode()
Factory method, which creates the SelectionBoxMode. Subclasses can override this method in order to return a more specialized version.

Returns:
a specialized HotSpotMode

createPopupMode

protected ViewMode createPopupMode()
Factory method, which can create the PopupMode. Subclasses can override this method in order to return an instance.

Returns:
null

activate

public void activate(boolean b)
Description copied from class: ViewMode
Invoked when the Mode is activated/deactiveted from the ViewControl

Overrides:
activate in class ViewMode
Parameters:
b - set true when mode should be activated false otherwise

allowNodeCreation

public void allowNodeCreation(boolean b)
Allows or disallows node creation. By default node creation is allowed.


allowEdgeCreation

public void allowEdgeCreation(boolean b)
Allows or disallows edge creation. By default edge creation is allowed.


allowBendCreation

public void allowBendCreation(boolean b)
Allows or disallows bend creation. By default bend creation is allowed.


allowMoveSelection

public void allowMoveSelection(boolean b)
Allows or disallows moving around the selected features of the displayed graph.


allowMoving

public void allowMoving(boolean b)
Allows or disallows moving the viewport of the view via the right mouse button. If a popup listener is set for this mode then moving is not possible anymore.


allowResizeNodes

public void allowResizeNodes(boolean b)
Allows or disllows resizing of nodes by dragging at the selection hotspots.


doAllowNodeCreation

public boolean doAllowNodeCreation()
Returns true iff the creation of nodes should be allowed. This mode will act according to the return value of this method.


doAllowEdgeCreation

public boolean doAllowEdgeCreation()
Returns true iff the creation of edges should be allowed. This mode will act according to the return value of this method.


doAllowBendCreation

public boolean doAllowBendCreation()
Returns true iff the creation of bends should be allowed. This mode will act according to the return value of this method.


doAllowMoveSelection

public boolean doAllowMoveSelection()
Whether or not to allow moving around the selected features of the displayed graph.


doAllowMoving

public boolean doAllowMoving()
Whether or not to allow moving the viewport of the view via right mouse drag action.


doAllowResizeNodes

public boolean doAllowResizeNodes()
Whether or not to allow resizing of nodes by dragging at the selection hotspots.


showNodeTips

public void showNodeTips(boolean b)
If set to true this mode will show a tip displaying whatever is returned by EditMode.getNodeTip(Node v).


doShowNodeTips

public boolean doShowNodeTips()
Returns true if this mode should display tip text for a node.


showEdgeTips

public void showEdgeTips(boolean b)
If set to true this mode will show a tip displaying whatever is returned by EditMode.getEdgeTip(Edge e).


doShowEdgeTips

public boolean doShowEdgeTips()
Returns true if this mode should display tip text for an edge.


getPopupMode

public ViewMode getPopupMode()
Returns the minor popup mode associated with this mode


setPopupMode

public void setPopupMode(ViewMode mode)
Sets the minor popup mode associated with this mode. If a popup mode is set for this mode, then it gets activated by a right click of the mouse.


getMoveSelectionMode

public ViewMode getMoveSelectionMode()
Returns the minor move selection mode associated with this mode.


setMoveSelectionMode

public void setMoveSelectionMode(ViewMode mode)
Sets the minor move selection mode associated with this mode. If graph elements are selected then by starting to drag the mouse this mode gets activated and moves the selection around.


getCreateEdgeMode

public ViewMode getCreateEdgeMode()
Returns the minor create edge mode associated with this mode.


setCreateEdgeMode

public void setCreateEdgeMode(ViewMode mode)
Sets the minor create edge mode associated with this mode. If a drag starts from a non-selected node this mode gets activated and starts to create a new edge starting at that node.


getSelectionBoxMode

public ViewMode getSelectionBoxMode()
Returns the minor selection box mode associated with this mode.


setSelectionBoxMode

public void setSelectionBoxMode(ViewMode mode)
Sets the minor selection box mode associated with this mode. If a drag starts from a background location this mode gets activated and starts to open up a selection box


mousePressedLeft

public void mousePressedLeft(double x,
                             double y)
Takes the given coordiante and performs with it a hit test on all graph elements. The so collected information will be used when the mouse gets released or dragged next.

Overrides:
mousePressedLeft in class ViewMode
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)
Takes the given coordiante and performs with it a hit test on all graph elements. The so collected information will be used when the mouse gets released or dragged next.

Overrides:
mouseShiftPressedLeft in class ViewMode
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)
Depending on the history, actions are triggered, but only if Mouse was not moved since the button was pressed. That means this is essentially a routine that processes mouse clicks.

Overrides:
mouseReleasedLeft in class ViewMode
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)
Depending on the history, actions are triggered, but only if Mouse was not moved since the button was pressed. That means this is essentially a routine that processes mouse clicks.

Overrides:
mouseShiftReleasedLeft in class ViewMode
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)
If a popup mode is associates with this mode then it will be actived. Otherwise the right mouse press serves as activation point for dragging the view port of the underlying view.

Overrides:
mousePressedRight in class ViewMode
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)
Activates a minor mode. Which minor mode gets activeted depends on the kind of graph element was hit when pressing the mouse button down.

Overrides:
mouseDraggedLeft in class ViewMode
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)
When moving the mouse, the mouse cursor has to be adjusted. When moving over an hotspot, the hotspotmode is activated.

Overrides:
mouseMoved in class ViewMode
Parameters:
x - the x-coordinate of the mouse event in world coordinates.
y - the y-coordinate of the mouse event in world coordinates.

getNodeTip

protected String getNodeTip(Node v)
Returns the tip text displayed for the given node. This method will be called to get the tip text associated with the given node. the tip text will only be displayed if node tip display was activated via showNodeTips.

By default the label text of the node will be returned. Subclasses may want to overwrite this behaviour.


getEdgeTip

protected String getEdgeTip(Edge e)
Returns the tip text displayed for the given edge. This method will be called to get the tip text associated with the given edge. the tip text will only be displayed if edge tip display was activated via showEdgeTips.

By default the first label text of the edge will be returned. Subclasses may want to overwrite this behaviour.


nodeCreated

protected void nodeCreated(Node v)
This method gets called after a new node was completely created by this mode. It serves as a hook to perform some actions after this event has happened. By default this method does nothing.


nodeClicked

protected void nodeClicked(Node v)
This method gets called after a left mouse click on a node occured. The default implementation triggers no action. Subclasses that want to listen to node clicks can overwrite this method.


getMoveLabelMode

public ViewMode getMoveLabelMode()
Getter for child mode MoveLabelMode. This mode gets activated when the user drags a node or edge label.

Returns:
Value of property moveLabelMode.

setMoveLabelMode

public void setMoveLabelMode(ViewMode moveLabelMode)
Setter for child mode MoveLabelMode. This mode gets activated when the user drags a node or edge label. By default an instance of MoveLabelMode is set.

Parameters:
moveLabelMode - New value of property moveLabelMode.

getMovePortMode

public ViewMode getMovePortMode()
Getter for child mode MovePortMode. This mode gets activated when the user drags the highlighted endpoints of a selected edge.

Returns:
Value of property movePortMode.

setMovePortMode

public void setMovePortMode(ViewMode movePortMode)
Setter for child mode MovePortMode. This mode gets activated when the user drags the highlighted endpoints of a selected edge. By default an instance of MovePortMode is set.

Parameters:
movePortMode - New value of property movePortMode.

getHotSpotMode

public ViewMode getHotSpotMode()
Getter for child mode HotSpotMode. This mode gets activated when the user drags one of the eight hotspots (resize handles) displayed around a selected node.

Returns:
Value of property hotSpotMode.

setHotSpotMode

public void setHotSpotMode(ViewMode hotSpotMode)
Setter for child mode HotSpotMode. This mode gets activated when the user drags one of the eight hotspots (resize handles) displayed around a selected node. By default an instance of HotSpotMode is set.


isCreateEdgeGesture

protected boolean isCreateEdgeGesture(MouseEvent lastPress,
                                      MouseEvent lastDrag)

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

2003