net.refractions.udig.tools.edit
Class EditToolHandler

java.lang.Object
  extended by net.refractions.udig.tools.edit.EditToolHandler

public class EditToolHandler
extends java.lang.Object

This is the class that does all the work. An Edit tool adds Mode objects to the EditToolHandler. Each Mode has attributes that indicate whether it is valid.

Since:
1.1.0
Author:
jones

Field Summary
static java.lang.String CURRENT_SHAPE
          The key for the currently selected/edit shape.
 Cursor editCursor
          Cursor that should be set when editing can occur.
static java.lang.String EDITSTATE
          The key for the currently selected/edit state.
 Cursor selectionCursor
          Cursor that should be set when a selection can occur.
static java.lang.String STORED_CURRENT_SHAPE
          When there is a switch in the currently selected layer the current shape is stored on the old layer so if the layer selected layer the state can be restored.
static java.lang.String STORED_CURRENT_STATE
          When there is a switch in the currently selected layer the current state is stored on the old layer so if the layer selected layer the state can be restored.
protected  boolean testing
           
protected  AbstractEditTool tool
           
 
Constructor Summary
EditToolHandler(Cursor selectionCursor, Cursor editCursor)
           
 
Method Summary
 java.util.List<Behaviour> getAcceptBehaviours()
          Returns the list of behaviours that are run when the Enter key is pressed.
 java.util.Set<Activator> getActivators()
          Returns the Activators that are run during activation and deactivation This list is thread safe and may be modified.
 java.util.List<EventBehaviour> getBehaviours()
          Returns the EventBehaviours that may be run when an event occurs.
 java.util.List<Behaviour> getCancelBehaviours()
          Returns the list of behaviours that are run when the Esc key is pressed.
 BehaviourCommand getCommand(java.util.List<Behaviour> list)
          Runs a list of behaviours.
 IToolContext getContext()
          Gets the tool context object that Modes and Activators may use.
 EditGeom getCurrentGeom()
           
 PrimitiveShape getCurrentShape()
           
 EditState getCurrentState()
           
 java.util.List<IDrawCommand> getDrawCommands()
          Returns the draw actions that need to be deactivated when the tool is deactivated.
 EditBlackboard getEditBlackboard(ILayer layer)
          Gets the EditBlackboard of the map.
 ILayer getEditLayer()
          Returns the currently selected layer, or if the EditManager is locked, it will return the edit layer.
 java.util.List<EnablementBehaviour> getEnablementBehaviours()
          Returns the behaviours that determine whether the tool is active at the current locations
 MouseTracker getMouseTracker()
           
 AbstractEditTool getTool()
           
protected  void handleEvent(MapMouseEvent e, EventType eventType)
          Runs through the list of modes and runs all the modes that are valid in the current context.
 boolean isLocked()
          Returns true if Handler has been locked by lock(LockingBehaviour)
 boolean isLockOwner(LockingBehaviour behaviour)
          Returns true if the behaviour's LockingBehaviour.getKey(EditToolHandler) returns the key for the lock.
 void lock(LockingBehaviour behaviour)
          Locks the handler so only the only behaviours that can run are LockingBehaviours who's LockingBehaviour.getKey(EditToolHandler) method returns the same object as the locking LockingBehaviour's LockingBehaviour.getKey(EditToolHandler) method.
 void repaint()
          All behaviours and listeners should call this method so that only one redraw is done per mouse event.
protected  void setActive(boolean active)
          Called by AbstractEditTool when activated.
protected  void setContext(IToolContext context2)
           
 void setCurrentShape(PrimitiveShape currentShape)
           
 void setCurrentState(EditState currentState)
           
 void setCursor(int cursor_id)
          Deprecated.  
 void setCursor(java.lang.String cursorID)
          The method gets ID of the cursor as configured by extension or by ModalTool.*_CURSOR value corresponding to SWT.CURSOR_* constants and delegates the call to ModalTool to find the cursor in cache and set it.
 void setTool(AbstractEditTool tool)
           
 java.lang.String toString()
           
 void unlock(LockingBehaviour behaviour)
          Unlocks the handler so all behaviours can run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EDITSTATE

public static final java.lang.String EDITSTATE
The key for the currently selected/edit state. It is put on the map referenced by the context (see getContext())

See Also:
Constant Field Values

CURRENT_SHAPE

public static final java.lang.String CURRENT_SHAPE
The key for the currently selected/edit shape. It is put on the map referenced by the context (see getContext())

See Also:
Constant Field Values

STORED_CURRENT_STATE

public static final java.lang.String STORED_CURRENT_STATE
When there is a switch in the currently selected layer the current state is stored on the old layer so if the layer selected layer the state can be restored.

Modify with Care this is primarily used by the framework for its workflow but if the workflow is not pleasing then modification is permitted.

See Also:
Constant Field Values

STORED_CURRENT_SHAPE

public static final java.lang.String STORED_CURRENT_SHAPE
When there is a switch in the currently selected layer the current shape is stored on the old layer so if the layer selected layer the state can be restored.

Modify with Care this is primarily used by the framework for its workflow but if the workflow is not pleasing then modification is permitted.

See Also:
Constant Field Values

selectionCursor

public final Cursor selectionCursor
Cursor that should be set when a selection can occur.


editCursor

public final Cursor editCursor
Cursor that should be set when editing can occur.


testing

protected boolean testing

tool

protected AbstractEditTool tool
Constructor Detail

EditToolHandler

public EditToolHandler(Cursor selectionCursor,
                       Cursor editCursor)
Method Detail

setActive

protected void setActive(boolean active)
Called by AbstractEditTool when activated.

Parameters:
active -

getCommand

public BehaviourCommand getCommand(java.util.List<Behaviour> list)
Runs a list of behaviours. Expected uses are handler.runBehaviours(handler.getAcceptBehaviours()); or handler.runBehaviours(handler.getCancelBehaviours());

Parameters:
list -

handleEvent

protected void handleEvent(MapMouseEvent e,
                           EventType eventType)
Runs through the list of modes and runs all the modes that are valid in the current context.

Parameters:
e - mouse event that just occurred.
eventType - the type of event that just occurred

getCurrentGeom

public EditGeom getCurrentGeom()
Returns:
Returns the currentGeom.

setCurrentShape

public void setCurrentShape(PrimitiveShape currentShape)

getCurrentShape

public PrimitiveShape getCurrentShape()
Returns:
Returns the currentShape.

getCurrentState

public EditState getCurrentState()
Returns:
Returns the currentState.

setCurrentState

public void setCurrentState(EditState currentState)
Parameters:
currentState - The currentState to set.

getBehaviours

public java.util.List<EventBehaviour> getBehaviours()
Returns the EventBehaviours that may be run when an event occurs. This list is thread safe and may be modified.

Returns:
the EventBehaviours that may be run when an event occurs. This list is thread safe and may be modified.

getEnablementBehaviours

public java.util.List<EnablementBehaviour> getEnablementBehaviours()
Returns the behaviours that determine whether the tool is active at the current locations

Returns:
the behaviours that determine whether the tool is active at the current locations

getEditBlackboard

public EditBlackboard getEditBlackboard(ILayer layer)
Gets the EditBlackboard of the map.

Returns:

getEditLayer

public ILayer getEditLayer()
Returns the currently selected layer, or if the EditManager is locked, it will return the edit layer.

Returns:

getActivators

public java.util.Set<Activator> getActivators()
Returns the Activators that are run during activation and deactivation This list is thread safe and may be modified.

Returns:
Returns the activationActions.

getDrawCommands

public java.util.List<IDrawCommand> getDrawCommands()
Returns the draw actions that need to be deactivated when the tool is deactivated.

This list is thread safe and may be modified.

Returns:
Returns the drawCommands.

getContext

public IToolContext getContext()
Gets the tool context object that Modes and Activators may use.

Returns:

setContext

protected void setContext(IToolContext context2)
Parameters:
context2 - The context to set.

setCursor

public void setCursor(int cursor_id)
Deprecated. 

Sets the ViewportPane's cursor

Parameters:
cursor_id - the SWT.CURSOR_XXX id of the cursor to set.

setCursor

public void setCursor(java.lang.String cursorID)
The method gets ID of the cursor as configured by extension or by ModalTool.*_CURSOR value corresponding to SWT.CURSOR_* constants and delegates the call to ModalTool to find the cursor in cache and set it.

Parameters:
cursorID -

getMouseTracker

public MouseTracker getMouseTracker()
Returns:
Returns the mouseTracker.

getAcceptBehaviours

public java.util.List<Behaviour> getAcceptBehaviours()
Returns the list of behaviours that are run when the Enter key is pressed. EventBehaviours are welcome to run these behaviours as well if they wish to accept the current edit. The list is thread safe and can be modified.

Returns:
Returns the acceptBehaviours.

getCancelBehaviours

public java.util.List<Behaviour> getCancelBehaviours()
Returns the list of behaviours that are run when the Esc key is pressed. The list is thread safe and can be modified.

Returns:
Returns the cancelBehaviours.
See Also:
getCommand(List)

lock

public void lock(LockingBehaviour behaviour)
Locks the handler so only the only behaviours that can run are LockingBehaviours who's LockingBehaviour.getKey(EditToolHandler) method returns the same object as the locking LockingBehaviour's LockingBehaviour.getKey(EditToolHandler) method.

This is not a reentrant lock so it cannot be locked multiple times. Also the lock cannot be null

Parameters:
behaviour - the behaviour that is locking the handler

isLocked

public boolean isLocked()
Returns true if Handler has been locked by lock(LockingBehaviour)

Returns:
Returns true if Handler has been locked by lock(LockingBehaviour)

unlock

public void unlock(LockingBehaviour behaviour)
Unlocks the handler so all behaviours can run. The behaviour's LockingBehaviour.getKey(EditToolHandler) method must return the same object as the locking behaviours LockingBehaviour.getKey(EditToolHandler) method.

Parameters:
behaviour -

isLockOwner

public boolean isLockOwner(LockingBehaviour behaviour)
Returns true if the behaviour's LockingBehaviour.getKey(EditToolHandler) returns the key for the lock.

Parameters:
behaviour - the behaviour to test
Returns:
Returns true if the behaviour's LockingBehaviour.getKey(EditToolHandler) returns the key for the lock.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

repaint

public void repaint()
All behaviours and listeners should call this method so that only one redraw is done per mouse event.


setTool

public void setTool(AbstractEditTool tool)

getTool

public AbstractEditTool getTool()