jcreek.cke.tool
Class MoveTool

java.lang.Object
  extended byjcreek.cke.tool.MoveTool
All Implemented Interfaces:
ConceptViewListener, ConceptViewPaintListener, CreekTool, java.awt.dnd.DragGestureListener, java.awt.dnd.DragSourceListener, java.awt.dnd.DropTargetListener, java.util.EventListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.beans.PropertyChangeListener

public class MoveTool
extends java.lang.Object
implements CreekTool, ConceptViewPaintListener, java.beans.PropertyChangeListener, java.awt.dnd.DropTargetListener, java.awt.dnd.DragGestureListener, java.awt.dnd.DragSourceListener

Tool for moving entities and relations around a graph; acts as a go-between for the user and the graph. This class takes user input and coordinates the interaction by talking to the model and view to provide appropriate feedback to the user. In this way, the view and model appear to be operating as one entity.

User can select a entity or relation by clicking on it. If user clicks in empty space and drags the mouse they can select any number of entities that fall within the bounding rectangle. To select multiple objects, user must hold down Control key.

Version:
Author:

Field Summary
static java.awt.datatransfer.DataFlavor dataFlavor
           
protected  CreekDocument document
          Document this mediator is associated with.
protected  java.awt.dnd.DragSource dragSource
           
protected  java.awt.Point firstMousePos
          First mouse press position when dragging started.
protected  boolean isCTRLDown
          True if user has pressed CTRL key.
protected  boolean isSelectRegion
          True if user is selecting entities by defining a region.
protected  java.awt.Point lastMousePos
          Most recent mouse position while dragging.
protected  CreekModel model
          Model that we're associated with.
protected  VertexList movingVertices
          The list of the entities being moved around.
protected  VisualEntity pressVertex
          Vertex the user pressed on in mousePressed().
protected  VisualEntity propVertex
          Vertex the rightClicked.
 PropertyWindow propWin
           
protected  javax.swing.JPopupMenu relationList
           
protected  VertexList selectedList
          List of the selected entities in the order they were selected by the user.
protected  boolean wasPressed
          True if mouse was pressed on the view before being released.
protected  ConceptView view
          View that we're associated with.
 
Constructor Summary
MoveTool()
          Creates a new MoveTool object.
 
Method Summary
 VisualEntity activateEntity(Entity ed, VisualEntity activator)
           
protected  void activateRelation(Relation r)
           
protected  void activateRelation(java.lang.String relationType)
           
 void attach(CreekModel model, ConceptView view, javax.swing.JInternalFrame win)
          Attach to the given model and view objects.
 boolean canPerformAction(int action, java.awt.Point location)
           
protected  javax.swing.JMenuItem createMenuItem(java.lang.String cmd)
           
protected  javax.swing.JMenu createRelationsMenu()
           
 void deactivateRelation(java.lang.String relationName)
           
 void detach()
          Detach from the model and view and prepare to be deactivated.
 void dragDropEnd(java.awt.dnd.DragSourceDropEvent e)
          DragSourceListener Methods
 void dragEnter(java.awt.dnd.DragSourceDragEvent e)
           
 void dragEnter(java.awt.dnd.DropTargetDragEvent e)
           
 void dragExit(java.awt.dnd.DragSourceEvent e)
           
 void dragExit(java.awt.dnd.DropTargetEvent e)
           
 void dragGestureRecognized(java.awt.dnd.DragGestureEvent e)
          DragGestureRecognized for DragGestureListener
 void dragOver(java.awt.dnd.DragSourceDragEvent e)
           
 void dragOver(java.awt.dnd.DropTargetDragEvent e)
           
 void drop(java.awt.dnd.DropTargetDropEvent e)
          DropTargetListener methods
 void dropActionChanged(java.awt.dnd.DragSourceDragEvent e)
           
 void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
           
protected  VisualEntity findNode(int x, int y)
          Find an entity close to the given x,y position.
protected  void finishMoving()
          If we were moving entities, clean up now.
protected  void formPopup(int x, int y)
           
 java.awt.Point getMousePosition()
          Returns the position of the mouse,this will return the first Mouse Position or last Mouse Position depending on the current Tool and the state of the tool
 VertexList getSelected()
          Returns the list of selected entities, in the order they were selected by the user.
 VisualEntity getVisualEntity(VisualEntity ve, VertexList vl)
           
protected  void initialiseEntities(VertexList vl)
           
protected  void initialiseRelations(RelationList rl)
           
 boolean isSelected(VisualRelation vr, VisualEntity[] ves)
           
 void mouseClicked(java.awt.event.MouseEvent e)
          We ignore this event.
 void mouseDragged(java.awt.event.MouseEvent me)
          The user is dragging the mouse so lets see about moving the selected entities.
 void mouseEntered(java.awt.event.MouseEvent e)
          We ignore this event.
 void mouseExited(java.awt.event.MouseEvent me)
          We ignore this event.
 void mouseMoved(java.awt.event.MouseEvent me)
          We ignore this event.
 void mousePressed(java.awt.event.MouseEvent me)
          User has pressed a mouse button on us.
 void mouseReleased(java.awt.event.MouseEvent me)
          User has released the mouse button.
 void paintAfter(ConceptViewPaintEvent event)
          Called after the view draws the graph.
 void paintBefore(ConceptViewPaintEvent event)
          Called before the view draws the graph.
 void propertyChange(java.beans.PropertyChangeEvent e)
          The state of the object we're listening to has changed.
protected  void resetMovingVertices()
          Moves all the moving entities back to their original positions by using the original positions stored in the copy of the entities.
protected  void selectRegion()
          Called when user was defining a rectangular region with which to select entities.
protected  void toggleRelation(VisualEntity e, java.lang.String relationName)
           
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

model

protected CreekModel model
Model that we're associated with.


view

protected ConceptView view
View that we're associated with.


document

protected CreekDocument document
Document this mediator is associated with.


pressVertex

protected VisualEntity pressVertex
Vertex the user pressed on in mousePressed(). Could be null if the user didn't press on a entity.


propVertex

protected VisualEntity propVertex
Vertex the rightClicked. Could be null if the user didn't rightClick on a entity.


selectedList

protected VertexList selectedList
List of the selected entities in the order they were selected by the user.


wasPressed

protected boolean wasPressed
True if mouse was pressed on the view before being released. Helps avoid some mis-firings of the mouse buttons.


isSelectRegion

protected boolean isSelectRegion
True if user is selecting entities by defining a region. This is true when user pressed but not on a entity and begins dragging the mouse.


isCTRLDown

protected boolean isCTRLDown
True if user has pressed CTRL key.


movingVertices

protected VertexList movingVertices
The list of the entities being moved around. These entities are a copy of the originals and can be modified.


firstMousePos

protected java.awt.Point firstMousePos
First mouse press position when dragging started.


lastMousePos

protected java.awt.Point lastMousePos
Most recent mouse position while dragging.


propWin

public PropertyWindow propWin

relationList

protected javax.swing.JPopupMenu relationList

dragSource

protected java.awt.dnd.DragSource dragSource

dataFlavor

public static final java.awt.datatransfer.DataFlavor dataFlavor
Constructor Detail

MoveTool

public MoveTool()
Creates a new MoveTool object.

Method Detail

attach

public void attach(CreekModel model,
                   ConceptView view,
                   javax.swing.JInternalFrame win)
Attach to the given model and view objects. This begins user interaction and will imply that this tool is the currently active tool. The tool should add itself as a listener to the view object to begin interaction with the user.

Specified by:
attach in interface CreekTool
Parameters:
model - CreekModel to attach to
view - ConceptView to attach to

detach

public void detach()
Detach from the model and view and prepare to be deactivated. This does not imply that this object is about to be destroyed. The tool should remove itself from the view listener list and cease interaction with the user.

Note that this method may be called more than once between calls to attach()

Specified by:
detach in interface CreekTool

findNode

protected VisualEntity findNode(int x,
                                int y)
Find an entity close to the given x,y position.

Parameters:
x - mouse x position
y - mouse y position

finishMoving

protected void finishMoving()
If we were moving entities, clean up now.


getSelected

public VertexList getSelected()
Returns the list of selected entities, in the order they were selected by the user. Often called by another class that is going to perform some operation on the graph, such as a search.

Specified by:
getSelected in interface CreekTool
Returns:
selected entity list

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
We ignore this event.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent me)
The user is dragging the mouse so lets see about moving the selected entities.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
me - mouse event

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
We ignore this event.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - mouse event

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
We ignore this event.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
me - mouse event

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent me)
We ignore this event.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
User has pressed a mouse button on us. Interpret the click as clicking a entity and save the entity reference. May be null if the user didn't click on a entity.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
me - mouse event for this canvas

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
User has released the mouse button. We now check to see if the user was moving entities, selecting a region, selecting a entity, or selecting an relation.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
me - mouse event for this canvas

paintAfter

public void paintAfter(ConceptViewPaintEvent event)
Called after the view draws the graph. Gives the listener a chance to draw something to the view after everything else has been drawn. The order in which listeners are called is non-deterministic.

Specified by:
paintAfter in interface ConceptViewPaintListener
Parameters:
event - view paint event

paintBefore

public void paintBefore(ConceptViewPaintEvent event)
Called before the view draws the graph. Gives the listener a chance to draw something to the view before anything else appears. The order in which listeners are called is non-deterministic.

Specified by:
paintBefore in interface ConceptViewPaintListener
Parameters:
event - view paint event

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
The state of the object we're listening to has changed. This means we should check if any of the selected entities have been removed.

Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
e - change event

resetMovingVertices

protected void resetMovingVertices()
Moves all the moving entities back to their original positions by using the original positions stored in the copy of the entities.


selectRegion

protected void selectRegion()
Called when user was defining a rectangular region with which to select entities. Determines which entities are within the rectangle and marks them selected.


toString

public java.lang.String toString()
Returns a string representation of this object.

Returns:
string representing this object

getMousePosition

public java.awt.Point getMousePosition()
Returns the position of the mouse,this will return the first Mouse Position or last Mouse Position depending on the current Tool and the state of the tool

Specified by:
getMousePosition in interface CreekTool
Returns:
Point position of the mouse

formPopup

protected void formPopup(int x,
                         int y)

createMenuItem

protected javax.swing.JMenuItem createMenuItem(java.lang.String cmd)

createRelationsMenu

protected javax.swing.JMenu createRelationsMenu()

toggleRelation

protected void toggleRelation(VisualEntity e,
                              java.lang.String relationName)

deactivateRelation

public void deactivateRelation(java.lang.String relationName)

activateRelation

protected void activateRelation(java.lang.String relationType)

activateRelation

protected void activateRelation(Relation r)

activateEntity

public VisualEntity activateEntity(Entity ed,
                                   VisualEntity activator)

drop

public void drop(java.awt.dnd.DropTargetDropEvent e)
DropTargetListener methods

Specified by:
drop in interface java.awt.dnd.DropTargetListener

dragEnter

public void dragEnter(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dragEnter in interface java.awt.dnd.DropTargetListener

dragExit

public void dragExit(java.awt.dnd.DropTargetEvent e)
Specified by:
dragExit in interface java.awt.dnd.DropTargetListener

dragOver

public void dragOver(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dragOver in interface java.awt.dnd.DropTargetListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DropTargetDragEvent e)
Specified by:
dropActionChanged in interface java.awt.dnd.DropTargetListener

dragGestureRecognized

public void dragGestureRecognized(java.awt.dnd.DragGestureEvent e)
DragGestureRecognized for DragGestureListener

Specified by:
dragGestureRecognized in interface java.awt.dnd.DragGestureListener

dragDropEnd

public void dragDropEnd(java.awt.dnd.DragSourceDropEvent e)
DragSourceListener Methods

Specified by:
dragDropEnd in interface java.awt.dnd.DragSourceListener

dragEnter

public void dragEnter(java.awt.dnd.DragSourceDragEvent e)
Specified by:
dragEnter in interface java.awt.dnd.DragSourceListener

dragExit

public void dragExit(java.awt.dnd.DragSourceEvent e)
Specified by:
dragExit in interface java.awt.dnd.DragSourceListener

dragOver

public void dragOver(java.awt.dnd.DragSourceDragEvent e)
Specified by:
dragOver in interface java.awt.dnd.DragSourceListener

dropActionChanged

public void dropActionChanged(java.awt.dnd.DragSourceDragEvent e)
Specified by:
dropActionChanged in interface java.awt.dnd.DragSourceListener

canPerformAction

public boolean canPerformAction(int action,
                                java.awt.Point location)

isSelected

public boolean isSelected(VisualRelation vr,
                          VisualEntity[] ves)

getVisualEntity

public VisualEntity getVisualEntity(VisualEntity ve,
                                    VertexList vl)

initialiseEntities

protected void initialiseEntities(VertexList vl)

initialiseRelations

protected void initialiseRelations(RelationList rl)


Created at IDI, NTNU by the Artificial Intelligence and Learning group