org.graffiti.plugin.tool
Class ToolEnvironment<T extends InteractiveView<T>>

java.lang.Object
  extended by org.graffiti.plugin.tool.ToolEnvironment<T>
Type Parameters:
T - The superclass of all views belonging to the view family.

public final class ToolEnvironment<T extends InteractiveView<T>>
extends Object

The environment the tools operate on. It holds the performed user gesture, the current view, graph and session and provides methods to match the user gesture against triggers and issue actions. The put-methods, which fill the input and parameter slots of triggers and actions, may be concatenated as in the following example: ToolEnvironment env = ... env.putIn(ZoomRotation.snapSlot, true) .putIn(ZoomRotation.rawPositionSlot, new Point2D.Double()) .execute(ZoomRotation.class);

Version:
$Revision$ $Date$
Author:
Andreas Gleißner
See Also:
Tool, UserGesture, Trigger, ToolAction

Nested Class Summary
 class ToolEnvironment.SlotHelper
          Class that is used to allow for the concatenation of several put -Methods, which fill the slots.
 
Constructor Summary
ToolEnvironment()
          Constructs a tool environment.
 
Method Summary
 void execute(Class<? extends ToolAction<?>> toolClass)
          Executes the action implemented by the specified class.
 void execute(String actionId)
          Executes the action with the specified id.
 void execute(ToolAction<T> action)
          Executes the specified action.
 UserGesture getGesture()
          Returns the performed user gesture.
 Graph getGraph()
          Returns the graph to operate on.
 SlotMap getIn()
          Returns the input slots.
 SlotMap getOut()
          Returns the output slots.
<S> S
getOut(Slot<S> outSlot)
          Returns the value of the specified output slot.
 SlotMap getParam()
          Return the parameter slots.
 EditorSession getSession()
          Returns the current session.
 Trigger getTrigger(String triggerId)
          Returns the trigger with the specified id.
 T getView()
          Returns the view where the user gesture occurred.
 boolean matches(String triggerId)
          Returns if the performed user gesture matches the trigger with the specified id.
 boolean matches(Trigger trigger)
          Returns if the performed user gesture matches the specified trigger.
<S> ToolEnvironment.SlotHelper
putIn(Slot<S> slot, S value)
          Fills the specified input slot with the specified value.
<S> ToolEnvironment.SlotHelper
putParam(Slot<S> slot, S value)
          Fills the specified parameter slot with the specified value.
 void setUserGesture(UserGesture userGesture)
          Sets the performed user gesture.
protected  void setView(T view)
          Updates the references to the currently active view, graph and session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToolEnvironment

public ToolEnvironment()
Constructs a tool environment.

Method Detail

getIn

public SlotMap getIn()
Returns the input slots.

Returns:
the input slots, which are used to specify the next executed action.

getOut

public SlotMap getOut()
Returns the output slots.

Returns:
the output slots, which are filled by the results of matching triggers and executed actions.

getOut

public <S> S getOut(Slot<S> outSlot)
Returns the value of the specified output slot.

Type Parameters:
S - the type of the output slot.
Parameters:
outSlot - the output slot whose value is to be returned.
Returns:
the value of the specified output slot.

getParam

public SlotMap getParam()
Return the parameter slots.

Returns:
the parameter slots, which are used to narrow the scope of the next trigger to match the performed user gesture against.

getGesture

public UserGesture getGesture()
Returns the performed user gesture.

Returns:
the performed user gesture. May be null if the

getView

public T getView()
Returns the view where the user gesture occurred.

Returns:
the view where the user gesture occurred.

getGraph

public Graph getGraph()
Returns the graph to operate on.

Returns:
the graph to operate on.

getSession

public EditorSession getSession()
Returns the current session.

Returns:
the current session, which contains the graph to operate on and the view where the user gesture occurred.

putParam

public <S> ToolEnvironment.SlotHelper putParam(Slot<S> slot,
                                               S value)
Fills the specified parameter slot with the specified value.

Type Parameters:
S - the type of the parameter slot.
Parameters:
slot - the parameter slot to fill.
value - the value to assign to the slot.
Returns:
a reference to this object.

putIn

public <S> ToolEnvironment.SlotHelper putIn(Slot<S> slot,
                                            S value)
Fills the specified input slot with the specified value.

Type Parameters:
S - the type of the input slot.
Parameters:
slot - the input slot to fill.
value - the value to assign to the slot.
Returns:
a reference to this object.

getTrigger

public Trigger getTrigger(String triggerId)
Returns the trigger with the specified id.

Parameters:
triggerId - the id of the trigger to return.
Returns:
the trigger with the specified id.

matches

public boolean matches(Trigger trigger)
Returns if the performed user gesture matches the specified trigger.

Parameters:
trigger - the trigger the performed user gesture to match against.
Returns:
if the performed user gesture matches the specified trigger.

matches

public boolean matches(String triggerId)
Returns if the performed user gesture matches the trigger with the specified id.

Parameters:
triggerId - the id of the trigger the performed user gesture to match against.
Returns:
if the performed user gesture matches the trigger with the specified id.

execute

public void execute(String actionId)
Executes the action with the specified id.

Parameters:
actionId - the id of the action to execute.
See Also:
ToolAction

execute

public void execute(Class<? extends ToolAction<?>> toolClass)
Executes the action implemented by the specified class.

Parameters:
toolClass - the class implementing the action to execute.
See Also:
ToolAction

execute

public void execute(ToolAction<T> action)
Executes the specified action.

Parameters:
action - the action to execute.

setView

protected void setView(T view)
Updates the references to the currently active view, graph and session.

Parameters:
view - the current view.
See Also:
Graph, Session

setUserGesture

public void setUserGesture(UserGesture userGesture)
Sets the performed user gesture.

Parameters:
userGesture - the gesture that was performed by the user.


Generated at 2012-05-30 11:00:36 PM CEST