Class AutomatonDrawer<T extends Automaton>

java.lang.Object
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
  • Constructor Details

    • AutomatonDrawer

      protected AutomatonDrawer​(T aut)
      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)
      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)
      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()
      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()
      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)
      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()
      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()
      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 be Preference#OnStatePrefixID, Preference#OnStateID, or Preference#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 be Preference#OnStatePrefixID, Preference#OnStateID, or Preference#OnStateCustomName.
      Returns:
      a flag indicating what should be displayed on a state
    • setSelected

      public void setSelected​(GraphicComponent comp, boolean b)
      Marks a graphic component as selected or unselected.
      Parameters:
      comp - a graphic component selected or unselected
      b - true if comp is selected, unselected otherwise
    • isSelected

      public boolean isSelected​(GraphicComponent comp)
      Checks if a graphic component is marked as selected.
      Parameters:
      comp - a graphic component to be checked
      Returns:
      true if comp is selected
    • getSelected

      public GraphicComponent[] getSelected()
      Returns all selected components.
      Returns:
      all selected components
    • getSelectedStates

      public StateSet getSelectedStates()
      Returns all selected states.
      Returns:
      all selected states
    • getSelectedTransitions

      public TransitionSet getSelectedTransitions()
      Returns all selected transitions.
      Returns:
      all selected transitions
    • clearSelection

      public void clearSelection()
      Clears the current component selection.
    • setHighlight

      public void setHighlight​(GraphicComponent comp, java.awt.Color color)
      Highlights with a color or un-highlights (if color is null) a graphic component at runtime. The color property of the component will remain unchanged.
      Parameters:
      comp - a component to be highlighted or un-highlighted
      color - 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 (if color is null) graphic components at runtime. The color property of the components will remain unchanged.
      Parameters:
      comps - components to be highlighted or un-highlighted
      color - the color for the highlight, null for removing the highlight
    • setHighlight

      public void setHighlight​(GraphicComponent comp, boolean b)
      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-highlighted
      b - true if comp is highlighted, un-highlighted otherwise
    • setHighlight

      public void setHighlight​(java.util.Collection<? extends GraphicComponent> comps, boolean b)
      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-highlighted
      b - true if comps is highlighted, un-highlighted otherwise
    • highlight

      public void highlight​(State pred, State succ, java.awt.Color color)
      Highlights all transitions from a predecessor to a successor.
      Parameters:
      pred - a predecessor
      succ - a successor
      color - the color for highlighting all transitions from pred to succ
    • highlight

      public void highlight​(StateRun run, java.awt.Color color)
      Highlights transitions along a state run.
      Parameters:
      run - a state run to be highlighted
      color - the color for the highlight
    • isHighlighted

      public boolean isHighlighted​(GraphicComponent c)
      Checks if a graphic component is highlighted.
      Parameters:
      c - a graphic component to be checked
      Returns:
      true if c is highlighted
    • clearHighlight

      public void clearHighlight()
      Clears the current component highlights.
    • getHighlightColor

      public java.awt.Color getHighlightColor​(GraphicComponent c)
      Returns the highlight color of a graphic component.
      Parameters:
      c - a graphic component
      Returns:
      the highlight color of c
    • dumpHightlightColor

      public java.util.Map<GraphicComponent,​java.awt.Color> dumpHightlightColor()
      Dumps the highlight color settings.
      Returns:
      a map from a highlighted graphic component to its highlight color
    • restoreHighlightColor

      public void restoreHighlightColor​(java.util.Map<GraphicComponent,​java.awt.Color> map)
      Restores the highlight color settings.
      Parameters:
      map - a map from a highlighted graphic component to its highlight color
    • getRuntimeOpacity

      public java.lang.Integer getRuntimeOpacity​(GraphicComponent c)
      Returns the runtime opacity of a graphic component.
      Parameters:
      c - a graphic component
      Returns:
      the runtime opacity of c
    • setRuntimeOpacity

      public void setRuntimeOpacity​(GraphicComponent c, int o)
      Sets the runtime opacity of a graphic component.
      Parameters:
      c - a graphic component
      o - the runtime opacity of c, which is between 0 and 100
    • clearRuntimeOpacity

      public void clearRuntimeOpacity​(GraphicComponent c)
      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

      public java.util.Map<GraphicComponent,​java.lang.Integer> dumpRuntimeOpacity()
      Dumps the runtime opacity settings.
      Returns:
      a map from a graphic component with a custom opacity to the opacity value
    • restoreRuntimeOpacity

      public void restoreRuntimeOpacity​(java.util.Map<GraphicComponent,​java.lang.Integer> map)
      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 - a Graphics2D object used to draw the automaton
    • getAutomatonComponentsIn

      public GraphicComponent[] getAutomatonComponentsIn​(java.awt.Rectangle rect)
      Returns all graphic components located in a specified area.
      Parameters:
      rect - an area
      Returns:
      all graphic components located in rect
    • getAutomatonComponentAt

      public GraphicComponent getAutomatonComponentAt​(java.awt.Point p)
      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

      public State getStateAt​(java.awt.Point p)
      Returns a state that overlaps with a specified point.
      Parameters:
      p - a point
      Returns:
      a state that overlaps with p
    • getTransitionAt

      public Transition getTransitionAt​(java.awt.Point p)
      Returns a transition that overlaps with a specified point.
      Parameters:
      p - a point
      Returns:
      a transition that overlaps with p
    • getColor

      protected java.awt.Color getColor​(GraphicComponent c, java.awt.Color def)
      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 component
      def - the default color if c is not selected, is not highlighted, or does not have a custom color property
      Returns:
      the color of c to be drawn
    • getTextColor

      protected java.awt.Color getTextColor​(GraphicComponent c, java.awt.Color def)
      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 component
      def - the default text color if c 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

      protected int getOpacity​(GraphicComponent c)
      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 of c otherwise
    • drawState

      protected Node drawState​(State s)
      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

      protected Curve drawTransitionCurve​(Transition tran, int index, boolean visible)
      Draws a curve corresponding to a transition. The curve may be null because the source node of the curve or the destination node of the curve has been deleted.
      Parameters:
      tran - a transition to be displayed
      index - an index of tran among all transitions from the source state of tran to the destination state of tran
      visible - true if the curve corresponding to tran 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 class EditableDrawer<T extends Automaton>
      Returns:
      the bounds of the automaton