Class DrawerUtils

java.lang.Object
org.svvrl.goal.core.draw.DrawerUtils
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener

public class DrawerUtils
extends java.lang.Object
implements java.beans.PropertyChangeListener
This class provides some utility methods for drawing an automaton.
Author:
Ming-Hsien Tsai
  • Field Details

    • use_double_circle

      boolean use_double_circle
      Indicates if an additional shape should be used for accepting states.
  • Constructor Details

  • Method Details

    • getInstance

      public static DrawerUtils getInstance()
      Returns an instance of DrawerUtils.
      Returns:
      an instance of DrawerUtils
    • propertyChange

      public void propertyChange​(java.beans.PropertyChangeEvent e)
      Specified by:
      propertyChange in interface java.beans.PropertyChangeListener
    • isAcceptingColorStyled

      public boolean isAcceptingColorStyled()
      Returns true if accepting states are displayed with the accepting color.
      Returns:
      true if accepting states are displayed with the accepting color
    • isAcceptingDoubleCircleStyled

      public boolean isAcceptingDoubleCircleStyled()
      Returns true if accepting states are displayed with double circles.
      Returns:
      true if accepting states are displayed with double circles
    • getInitialIndicator

      public java.awt.Point[] getInitialIndicator​(java.awt.geom.Point2D center, int radius, Orientation orient)
      Returns a path that forms an initial indicator for a state at a specified location and with a specified radius.
      Parameters:
      center - the central location of the initial state
      radius - the radius of the initial state
      orient - the orient of the initial indicator
      Returns:
      a path that forms an initial indicator for the initial state at a specified location and with a specified radius
    • getInitialTrianglePosition

      public Orientation getInitialTrianglePosition​(State state)
      Computes the orientation of the initial triangle of a state.
      Parameters:
      state - a state
      Returns:
      the orientation of the initial triangle of state
      Created by:
      Conion Wu, modified by Jinn-Shu Chang
    • getLoopPosition

      public Orientation getLoopPosition​(State state)
      Decides the orientation of a self-loop.
      Parameters:
      state - a state that has a self-loop
      Returns:
      the orientation of the self-loop of state
      Created by:
      Conion Wu
    • getComponentColor

      public java.awt.Color getComponentColor​(GraphicComponent comp, java.awt.Color def)
      Returns the drawing color of a specified graphic component. The priority of the returned color is (1) the custom color of the component, (2) the accepting color if the component is in the NBW-like acceptance condition, and (3) the default color def.
      Parameters:
      comp - a graphic component
      def - the default color
      Returns:
      the drawing color of comp
    • getComponentTextColor

      public java.awt.Color getComponentTextColor​(GraphicComponent comp, java.awt.Color def)
      Returns the text color of a specified graphic component. For transitions, the priority of the returned color is (1) the custom text color of the component, (2) the accepting color if the component is in the NTBW-like acceptance condition, and (3) the default color def.
      Parameters:
      comp - a graphic component
      def - the default color
      Returns:
      the text color of comp
    • drawState

      public Node drawState​(Automaton aut, State s)
      Returns a node that visually represents an automaton state. The accepting style of the returned node will be decided by the user's preference. The opacity, information displayed on the state, and properties displayed below the state are determined by the properties set on the state and the user's preference.
      Parameters:
      aut - an automaton containing the state to be drawn
      s - a state to be drawn
      Returns:
      a node that visually represents the state
      See Also:
      drawState(Automaton, State, Color, Color, int, int, List)
    • drawState

      public Node drawState​(Automaton aut, State s, java.awt.Color color, java.awt.Color text_color, int opacity, int onState, java.util.List<java.lang.String> belowState)
      Returns a node that visually represents an automaton state. The automaton can be an FSA, an alternating automaton, or a game graph. The accepting style of the returned node will be decided by the user's preference.
      Parameters:
      aut - an automaton containing the state to be drawn
      s - a state to be drawn
      color - the color of the state
      text_color - the color of the text on the state
      opacity - the opacity of the state
      onState - a flag indicating the information to be displayed on the state
      belowState - a list of property names indicating what properties should be displayed below the state
      Returns:
      a node that visually represents the state
    • drawTransition

      public Curve drawTransition​(Transition tran, Node fromNode, Node toNode, int index, boolean visible, int ascent)
      Draws a curve corresponding to a transition. The color, opacity, and properties displayed above the transition are decided by properties set on the transition and the user's preference.
      Parameters:
      tran - a transition to be displayed
      fromNode - the node that represents the source state of the transition
      toNode - the node that represents the destination state of the transition
      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
      ascent - the font ascent of the current graphic context
      Returns:
      a curve corresponding to a transition to be drawn on the screen
      See Also:
      drawTransition(Transition, Node, Node, int, boolean, int, Color, Color, int, List)
    • drawTransition

      public Curve drawTransition​(Transition tran, Node fromNode, Node toNode, int index, boolean visible, int ascent, java.awt.Color color, java.awt.Color text_color, int opacity, java.util.List<java.lang.String> aboveTransition)
      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
      fromNode - the node that represents the source state of the transition
      toNode - the node that represents the destination state of the transition
      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
      ascent - the font ascent of the current graphic context
      color - the line color of the transition
      text_color - the color of the text on the transition
      opacity - the opacity of the transition
      aboveTransition - a list of property names indicating what properties should be displayed above the transition
      Returns:
      a curve corresponding to a transition to be drawn on the screen
    • getOnStateText

      public java.lang.String getOnStateText​(State s)
      Returns the text to be displayed on a state.
      Parameters:
      s - a state
      Returns:
      the text to be displayed on a state
      See Also:
      Preference.OnStatePropertyKey
    • setBelowStatePropertyNames

      public void setBelowStatePropertyNames​(Automaton aut, 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:
      aut - an automaton
      names - the names of the properties to be displayed below a state.
    • setBelowStatePropertyNames

      public void setBelowStatePropertyNames​(Automaton aut, 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:
      aut - an automaton
      names - the names of the properties to be displayed below a state.
    • clearBelowStatePropertyNames

      public void clearBelowStatePropertyNames​(Automaton aut)
      Clear the custom property names to be displayed below a state. The system default property names below a state will be displayed.
      Parameters:
      aut - an automaton
    • getBelowStatePropertyNames

      public java.util.List<java.lang.String> getBelowStatePropertyNames​(Automaton aut)
      Returns the property names to be displayed below a state. If there are custom properties names set for the specified automaton, the custom properties names will be returned. Otherwise, the system default property names will be returned.
      Parameters:
      aut - an automaton
      Returns:
      the property names to be displayed below a state
    • setAboveTransitionPropertyNames

      public void setAboveTransitionPropertyNames​(Automaton aut, 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:
      aut - an automaton
      names - the names of the properties to be displayed above a transition.
    • setAboveTransitionPropertyNames

      public void setAboveTransitionPropertyNames​(Automaton aut, 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:
      aut - an automaton
      names - the names of the properties to be displayed above a transition.
    • clearAboveTransitionPropertyNames

      public void clearAboveTransitionPropertyNames​(Automaton aut)
      Clear the custom property names to be displayed above a transition. The system default property names below a state will be displayed.
      Parameters:
      aut - an automaton
    • getAboveTransitionPropertyNames

      public java.util.List<java.lang.String> getAboveTransitionPropertyNames​(Automaton aut)
      Returns the property names to be displayed above a transition. If there are custom properties names set for the specified automaton, the custom properties names will be returned. Otherwise, the system default property names will be returned.
      Parameters:
      aut - an automaton
      Returns:
      the property names to be displayed below a state
    • getDisplayedLabel

      public java.lang.String getDisplayedLabel​(State s)
      Returns the label to be displayed below a state. The displayed label may contain several properties of a state.
      Parameters:
      s - a state
      Returns:
      the label to be displayed below a state
    • getDisplayedLabel

      public java.lang.String getDisplayedLabel​(Transition t)
      Returns the label to be displayed above a specified transition. The displayed label may contain several properties of the transition.
      Parameters:
      t - a transition
      Returns:
      the label to be displayed above the transition
    • getStateImage

      public java.awt.Image getStateImage​(State state, boolean init)
      Returns an image where a state is drawn.
      Parameters:
      state - a state
      init - true to draw also the initial indicator
      Returns:
      an image where the state is drawn