Package org.svvrl.goal.core.draw
Class AutomatonDrawer<T extends Automaton>
java.lang.Object
org.svvrl.goal.core.draw.AbstractDrawer
org.svvrl.goal.core.draw.EditableDrawer<T>
org.svvrl.goal.core.draw.AutomatonDrawer<T>
- Type Parameters:
T
- the type of the automaton to be drawn
- All Implemented Interfaces:
Drawer
- Direct Known Subclasses:
AltAutomatonDrawer
,FSADrawer
,GameDrawer
,TwoWayAltAutomatonDrawer
public abstract class AutomatonDrawer<T extends Automaton> extends EditableDrawer<T>
This class provides methods for drawing a general automaton. For a state and
a transition, this drawer creates a node and a curve respectively and draws
the node and the curve with a specified
Graphics2D
object. This
drawer also provides runtime settings of highlight color and opacity for
states and transitions.- Author:
- Ming-Hsien Tsai
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
AutomatonDrawer(T aut)
Constructor with an automaton to be drawn. -
Method Summary
Modifier and Type Method Description void
clearAboveTransitionPropertyNames()
Deprecated.void
clearBelowStatePropertyNames()
Deprecated.void
clearHighlight()
Clears the current component highlights.void
clearRuntimeOpacity()
Clears the runtime opacity property of all components.void
clearRuntimeOpacity(GraphicComponent c)
Clears the runtime opacity of a graphic component.void
clearSelection()
Clears the current component selection.void
draw(java.awt.Graphics2D g)
Draws the whole automaton.protected Node
drawState(State s)
Draws a node corresponding to a specified state.protected Curve
drawTransitionCurve(Transition tran, int index, boolean visible)
Draws a curve corresponding to a transition.java.util.Map<GraphicComponent,java.awt.Color>
dumpHightlightColor()
Dumps the highlight color settings.java.util.Map<GraphicComponent,java.lang.Integer>
dumpRuntimeOpacity()
Dumps the runtime opacity settings.java.util.List<java.lang.String>
getAboveTransitionPropertyNames()
Deprecated.GraphicComponent
getAutomatonComponentAt(java.awt.Point p)
Returns a graphic component that overlaps with a specified point.GraphicComponent[]
getAutomatonComponentsIn(java.awt.Rectangle rect)
Returns all graphic components located in a specified area.java.util.List<java.lang.String>
getBelowStatePropertyNames()
Deprecated.java.awt.Rectangle
getBounds()
Returns the bounds of the automaton.protected java.awt.Color
getColor(GraphicComponent c, java.awt.Color def)
Returns the color of a graphic component.java.awt.Color
getHighlightColor(GraphicComponent c)
Returns the highlight color of a graphic component.int
getOnStateProperty()
Returns the flag indicating what should be displayed on a state.protected int
getOpacity(GraphicComponent c)
Returns the opacity of a graphic component.java.lang.Integer
getRuntimeOpacity(GraphicComponent c)
Returns the runtime opacity of a graphic component.GraphicComponent[]
getSelected()
Returns all selected components.StateSet
getSelectedStates()
Returns all selected states.TransitionSet
getSelectedTransitions()
Returns all selected transitions.State
getStateAt(java.awt.Point p)
Returns a state that overlaps with a specified point.protected java.awt.Color
getTextColor(GraphicComponent c, java.awt.Color def)
Returns the text color of a graphic component.Transition
getTransitionAt(java.awt.Point p)
Returns a transition that overlaps with a specified point.void
highlight(State pred, State succ, java.awt.Color color)
Highlights all transitions from a predecessor to a successor.void
highlight(StateRun run, java.awt.Color color)
Highlights transitions along a state run.void
invalidate()
Reconstructs nodes and curves for states and transitions.boolean
isHighlighted(GraphicComponent c)
Checks if a graphic component is highlighted.boolean
isSelected(GraphicComponent comp)
Checks if a graphic component is marked as selected.void
resetCurve()
Resets control points of all curves.void
restoreHighlightColor(java.util.Map<GraphicComponent,java.awt.Color> map)
Restores the highlight color settings.void
restoreRuntimeOpacity(java.util.Map<GraphicComponent,java.lang.Integer> map)
Restores the runtime opacity settings from a map.void
setAboveTransitionPropertyNames(java.lang.String[] names)
Deprecated.void
setAboveTransitionPropertyNames(java.util.Collection<java.lang.String> names)
void
setBelowStatePropertyNames(java.lang.String[] names)
Deprecated.void
setBelowStatePropertyNames(java.util.Collection<java.lang.String> names)
Deprecated.void
setHighlight(java.util.Collection<? extends GraphicComponent> comps, boolean b)
Highlights with the default highlight color or un-highlights graphic components at runtime.void
setHighlight(java.util.Collection<? extends GraphicComponent> comps, java.awt.Color color)
Highlights with a color or un-highlights (ifcolor
isnull
) graphic components at runtime.void
setHighlight(GraphicComponent comp, boolean b)
Highlights with the default highlight color or un-highlights a graph component at runtime.void
setHighlight(GraphicComponent comp, java.awt.Color color)
Highlights with a color or un-highlights (ifcolor
isnull
) a graphic component at runtime.void
setOnStateProperty(int i)
Sets what should be displayed on a state.void
setRuntimeOpacity(GraphicComponent c, int o)
Sets the runtime opacity of a graphic component.void
setSelected(GraphicComponent comp, boolean b)
Marks a graphic component as selected or unselected.Methods inherited from class org.svvrl.goal.core.draw.EditableDrawer
getObject, getTransform, setTransform
-
Constructor Details
-
AutomatonDrawer
Constructor with an automaton to be drawn.- Parameters:
aut
- an automaton to be drawn
-
-
Method Details
-
setBelowStatePropertyNames
public void setBelowStatePropertyNames(java.util.Collection<java.lang.String> names)Deprecated.Sets the names of the properties to be displayed below a state. If the input names is empty, then no property will be displayed.- Parameters:
names
- the names of the properties to be displayed below a state.
-
setBelowStatePropertyNames
public void setBelowStatePropertyNames(java.lang.String[] names)Deprecated.Sets the names of the properties to be displayed below a state. If the input names is empty, then no property will be displayed.- Parameters:
names
- the names of the properties to be displayed below a state.
-
clearBelowStatePropertyNames
public void clearBelowStatePropertyNames()Deprecated.Clear the custom property names to be displayed below a state. The system default property names below a state will be displayed. -
getBelowStatePropertyNames
public java.util.List<java.lang.String> getBelowStatePropertyNames()Deprecated.Returns the property names to be displayed below a state. If there are custom properties names set for the automaton, the custom properties names will be returned. Otherwise, the system default property names will be returned.- Returns:
- the property names to be displayed below a state
-
setAboveTransitionPropertyNames
public void setAboveTransitionPropertyNames(java.util.Collection<java.lang.String> names)Sets the names of the properties to be displayed above a transition. If the input names is empty, then no property will be displayed.- Parameters:
names
- the names of the properties to be displayed above a transition.
-
setAboveTransitionPropertyNames
public void setAboveTransitionPropertyNames(java.lang.String[] names)Deprecated.Sets the names of the properties to be displayed above a transition. If the input names is empty, then no property will be displayed.- Parameters:
names
- the names of the properties to be displayed above a transition.
-
clearAboveTransitionPropertyNames
public void clearAboveTransitionPropertyNames()Deprecated.Clear the custom property names to be displayed above a transition. The system default property names below a state will be displayed. -
getAboveTransitionPropertyNames
public java.util.List<java.lang.String> getAboveTransitionPropertyNames()Deprecated.Returns the property names to be displayed above a transition. If there are custom properties names set for the automaton, the custom properties names will be returned. Otherwise, the system default property names will be returned.- Returns:
- the property names to be displayed below a state
-
setOnStateProperty
public void setOnStateProperty(int i)Sets what should be displayed on a state. The value can bePreference#OnStatePrefixID
,Preference#OnStateID
, orPreference#OnStateCustomName
.- Parameters:
i
- indicating what should be displayed on a state.
-
getOnStateProperty
public int getOnStateProperty()Returns the flag indicating what should be displayed on a state. The flag can bePreference#OnStatePrefixID
,Preference#OnStateID
, orPreference#OnStateCustomName
.- Returns:
- a flag indicating what should be displayed on a state
-
setSelected
Marks a graphic component as selected or unselected.- Parameters:
comp
- a graphic component selected or unselectedb
-true
ifcomp
is selected, unselected otherwise
-
isSelected
Checks if a graphic component is marked as selected.- Parameters:
comp
- a graphic component to be checked- Returns:
true
ifcomp
is selected
-
getSelected
Returns all selected components.- Returns:
- all selected components
-
getSelectedStates
Returns all selected states.- Returns:
- all selected states
-
getSelectedTransitions
Returns all selected transitions.- Returns:
- all selected transitions
-
clearSelection
public void clearSelection()Clears the current component selection. -
setHighlight
Highlights with a color or un-highlights (ifcolor
isnull
) a graphic component at runtime. The color property of the component will remain unchanged.- Parameters:
comp
- a component to be highlighted or un-highlightedcolor
- the color for the highlight,null
for removing the highlight
-
setHighlight
public void setHighlight(java.util.Collection<? extends GraphicComponent> comps, java.awt.Color color)Highlights with a color or un-highlights (ifcolor
isnull
) graphic components at runtime. The color property of the components will remain unchanged.- Parameters:
comps
- components to be highlighted or un-highlightedcolor
- the color for the highlight,null
for removing the highlight
-
setHighlight
Highlights with the default highlight color or un-highlights a graph component at runtime. The color property of the component will not be changed.- Parameters:
comp
- a component to be highlighted or un-highlightedb
-true
ifcomp
is highlighted, un-highlighted otherwise
-
setHighlight
Highlights with the default highlight color or un-highlights graphic components at runtime. The color property of the components will not be changed.- Parameters:
comps
- components to be highlighted or un-highlightedb
-true
ifcomps
is highlighted, un-highlighted otherwise
-
highlight
Highlights all transitions from a predecessor to a successor.- Parameters:
pred
- a predecessorsucc
- a successorcolor
- the color for highlighting all transitions frompred
tosucc
-
highlight
Highlights transitions along a state run.- Parameters:
run
- a state run to be highlightedcolor
- the color for the highlight
-
isHighlighted
Checks if a graphic component is highlighted.- Parameters:
c
- a graphic component to be checked- Returns:
true
ifc
is highlighted
-
clearHighlight
public void clearHighlight()Clears the current component highlights. -
getHighlightColor
Returns the highlight color of a graphic component.- Parameters:
c
- a graphic component- Returns:
- the highlight color of
c
-
dumpHightlightColor
Dumps the highlight color settings.- Returns:
- a map from a highlighted graphic component to its highlight color
-
restoreHighlightColor
Restores the highlight color settings.- Parameters:
map
- a map from a highlighted graphic component to its highlight color
-
getRuntimeOpacity
Returns the runtime opacity of a graphic component.- Parameters:
c
- a graphic component- Returns:
- the runtime opacity of
c
-
setRuntimeOpacity
Sets the runtime opacity of a graphic component.- Parameters:
c
- a graphic componento
- the runtime opacity ofc
, which is between 0 and 100
-
clearRuntimeOpacity
Clears the runtime opacity of a graphic component.- Parameters:
c
- a graphic component
-
clearRuntimeOpacity
public void clearRuntimeOpacity()Clears the runtime opacity property of all components. -
dumpRuntimeOpacity
Dumps the runtime opacity settings.- Returns:
- a map from a graphic component with a custom opacity to the opacity value
-
restoreRuntimeOpacity
Restores the runtime opacity settings from a map.- Parameters:
map
- a map from a graphic component with a custom opacity to the opacity value
-
resetCurve
public void resetCurve()Resets control points of all curves. -
invalidate
public void invalidate()Reconstructs nodes and curves for states and transitions. -
draw
public void draw(java.awt.Graphics2D g)Draws the whole automaton.- Parameters:
g
- aGraphics2D
object used to draw the automaton
-
getAutomatonComponentsIn
Returns all graphic components located in a specified area.- Parameters:
rect
- an area- Returns:
- all graphic components located in
rect
-
getAutomatonComponentAt
Returns a graphic component that overlaps with a specified point.- Parameters:
p
- a point (relative to the automaton)- Returns:
- a graphic component that overlaps with
p
-
getStateAt
Returns a state that overlaps with a specified point.- Parameters:
p
- a point- Returns:
- a state that overlaps with
p
-
getTransitionAt
Returns a transition that overlaps with a specified point.- Parameters:
p
- a point- Returns:
- a transition that overlaps with
p
-
getColor
Returns the color of a graphic component. The color depends on whether the graphic component is selected or highlighted. The priority of the returned color is (1) the selected color if the component is selected, (2) the highlighted color if the component is highlighted, and (3) the color returned by#getComponentColor(GraphicComponent, Color)
. Note that since we only draw a visible curve for transitions form the same source state to the same destination state, if one of the transition is selected, all other transitions from the same source state to the same destination state will also get the selected color.- Parameters:
c
- a graphic componentdef
- the default color ifc
is not selected, is not highlighted, or does not have a custom color property- Returns:
- the color of
c
to be drawn
-
getTextColor
Returns the text color of a graphic component. For transitions, the text color depends on whether the graphic component is selected or highlighted. The priority of the returned text color for transitions is (1) the selected color if the transition is selected, (2) the highlighted color if the transition is highlighted, and (3) the text color returned by#getComponentTextColor(GraphicComponent, Color)
.- Parameters:
c
- a graphic componentdef
- the default text color ifc
is not selected, is not highlighted, or does not have a custom text color property- Returns:
- the text color of
c
to be drawn
-
getOpacity
Returns the opacity of a graphic component. The value depends on the runtime opacity and the opacity property of the component.- Parameters:
c
- a graphic component- Returns:
- the runtime opacity of
c
if this drawer has it, the opacity property ofc
otherwise
-
drawState
Draws a node corresponding to a specified state.- Parameters:
s
- a state to be drawn- Returns:
- a graphic node corresponding to the input state
-
drawTransitionCurve
Draws a curve corresponding to a transition. The curve may benull
because the source node of the curve or the destination node of the curve has been deleted.- Parameters:
tran
- a transition to be displayedindex
- an index oftran
among all transitions from the source state oftran
to the destination state oftran
visible
-true
if the curve corresponding totran
is visible- Returns:
- a curve corresponding to a transition to be drawn on the screen
-
getBounds
public java.awt.Rectangle getBounds()Returns the bounds of the automaton.- Specified by:
getBounds
in classEditableDrawer<T extends Automaton>
- Returns:
- the bounds of the automaton
-