Class GraphDisplayOptions

java.lang.Object
ghidra.service.graph.GraphDisplayOptions
All Implemented Interfaces:
OptionsChangeListener
Direct Known Subclasses:
DefaultGraphDisplayOptions, ProgramGraphDisplayOptions

public class GraphDisplayOptions extends Object implements OptionsChangeListener
Class for managing graph display options. This includes color options for each vertex and edge type and shapes for vertex types.
  • Constructor Details

    • GraphDisplayOptions

      public GraphDisplayOptions(GraphType graphType)
      Constructs a new GraphTypeDisplayOptions for the given GraphType
      Parameters:
      graphType - The GraphType for which to define display options
    • GraphDisplayOptions

      protected GraphDisplayOptions(GraphType graphType, Tool tool, HelpLocation help)
      Constructs a new GraphTypeDisplayOptions for the given GraphType and initializes from tool options. Note this form should only be used for display options on GraphTypes that have options registered in the tool.
      Parameters:
      graphType - The GraphType for which to define display options
      tool - the tool from which to initialize from ToolOptions
      help - the help location
  • Method Details

    • initializeDefaults

      protected void initializeDefaults()
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Adds a ChangeListener to be notified when display options change
      Parameters:
      listener - the listener to be notified.
    • removeChangeListener

      public void removeChangeListener(ChangeListener listener)
      Removes the listener so that it won't be notified of changes any longer
      Parameters:
      listener - the listener to be removed
    • setDefaultVertexShape

      public void setDefaultVertexShape(VertexShape shape)
      Sets the default shape to be used by vertices that don't have a vertex type set
      Parameters:
      shape - the default vertex shape
    • setDefaultVertexColor

      public void setDefaultVertexColor(Color color)
      Sets the default color to be used by vertices that don't have a vertex type set
      Parameters:
      color - the default vertex shape
    • setDefaultVertexColor

      public void setDefaultVertexColor(String themeColorId)
      Sets the default color to be used by vertices that don't have a vertex type set. The color is set via a themeColorId, which means the client defined a theme color for this.
      Parameters:
      themeColorId - the theme color id to use for the default vertex color
    • setDefaultEdgeColor

      public void setDefaultEdgeColor(Color color)
      Sets the default color to be used by edges that don't have a edge type set
      Parameters:
      color - the default edge shape
    • setDefaultEdgeColor

      public void setDefaultEdgeColor(String themeColorId)
      Sets the default color to be used by vertices that don't have a vertex type set. The color is set via a themeColorId, which means the client defined a theme color for this.
      Parameters:
      themeColorId - the theme color id to use for the default vertex color
    • getDefaultEdgeColor

      public Color getDefaultEdgeColor()
      Returns the default color for edges that don't have an edge type set
      Returns:
      the default color for edges that don't have an edge type set
    • getDefaultVertexColor

      public Color getDefaultVertexColor()
      Returns the default color for vertices that don't have an vertex type set
      Returns:
      the default color for vertices that don't have an vertex type set
    • setVertexLabelOverrideAttributeKey

      public void setVertexLabelOverrideAttributeKey(String attributeKey)
      Sets the attribute key that can be used to override the label text shown for the vertex. Normally, the vertex's name is shown as the label.
      Parameters:
      attributeKey - the attribute key that, if set, will be used to define the vertice's label
    • getVertexLabelOverride

      public String getVertexLabelOverride()
      Returns the attribute key that can override the vertices label text
      Returns:
      the attribute key that can override the vertices label text
    • setVertexColorOverrideAttributeKey

      public void setVertexColorOverrideAttributeKey(String attributeKey)
      Sets the attribute key that can be used to override the color for a vertex. Normally, the color is determined by the vertex type, which will be mapped to a color
      Parameters:
      attributeKey - the attribute key that, if set, will be used to define the vertice's color
    • setEdgeColorOverrideAttributeKey

      public void setEdgeColorOverrideAttributeKey(String attributeKey)
      Sets the attribute key that can be used to override the color for an edge. Normally, the color is determined by the edge type, which will be mapped to a color
      Parameters:
      attributeKey - the attribute key that, if set, will be used to define the edge's color
    • getEdgeColorOverrideAttributeKey

      public String getEdgeColorOverrideAttributeKey()
      Returns the attribute key that can be used to override the color of an edge
      Returns:
      the attribute key that can be used to override the color of an edge
    • setVertexShapeOverrideAttributeKey

      public void setVertexShapeOverrideAttributeKey(String attributeKey)
      Sets the attribute key that can be used to override the shape for a vertex. Normally, the shape is determined by the vertex type, which will be mapped to a shape
      Parameters:
      attributeKey - the attribute key that, if set, will be used to define the vertice's shape
    • getVertexLabel

      public String getVertexLabel(AttributedVertex vertex)
      Returns the text that will be displayed as the label for the given vertex
      Parameters:
      vertex - the vertex for which to get label text
      Returns:
      the text that will be displayed as the label for the given vertex
    • getVertexShape

      public VertexShape getVertexShape(AttributedVertex vertex)
      Returns the VertexShape that will be used to draw the vertex's shape
      Parameters:
      vertex - the vertex for which to get the shape
      Returns:
      the VertexShape that will be used to draw the vertex's shape
    • getVertexColor

      public Color getVertexColor(AttributedVertex vertex)
      Returns the color that will be used to draw the vertex
      Parameters:
      vertex - the vertex for which to get the color
      Returns:
      the color that will be used to draw the vertex
    • getEdgeColor

      public Color getEdgeColor(AttributedEdge edge)
      Returns the color that will be used to draw the edge
      Parameters:
      edge - the edge for which to get the color
      Returns:
      the color that will be used to draw the edge
    • getEdgePriority

      public Integer getEdgePriority(String edgeType)
      Returns the priority for the given edge type. This is used by layout algorithms to determine which edges should have more influence on the layout.
      Parameters:
      edgeType - the edge type for which to get it's priority
      Returns:
      the priority for the given edge type
    • getFavoredEdgeType

      public String getFavoredEdgeType()
      Returns the edge type that is the preferred edge for layout purposes
      Returns:
      the edge type that is the preferred edge for layout purposes
    • setFavoredEdgeType

      public void setFavoredEdgeType(String favoredEdgeType)
      Sets the favored edge type. The favored edge type is used to influence layout algorithms
      Parameters:
      favoredEdgeType - the edge type that is to be favored by layout algorithms
    • getGraphType

      public GraphType getGraphType()
      Returns the GraphType that this object provides display options for
      Returns:
      the GraphType that this object provides display options for
    • getVertexColor

      public Color getVertexColor(String vertexType)
      Returns the color for the given vertex type
      Parameters:
      vertexType - the vertex type to get the color for
      Returns:
      the color for the given vertex type
    • setVertexColor

      public void setVertexColor(String vertexType, Color color)
      Sets the color for vertices with the given vertex type. Note that this method does not allow the vertex color to be registered in tool options. See setVertexColor(String, String).
      Parameters:
      vertexType - the vertex type for which to set its color
      color - the color to use for vertices with the given vertex type
    • setVertexColor

      public void setVertexColor(String vertexType, String themeColorId)
      Sets the vertex color using a theme color id. By using a theme color id, this property is eligible to be registered as a tool option.
      Parameters:
      vertexType - the vertex type for which to set its color
      themeColorId - the theme color id of the color for this vertex type
    • setVertexShape

      public void setVertexShape(String vertexType, VertexShape vertexShape)
      Sets the VertexShape to use for vertices with the given vertex type
      Parameters:
      vertexType - the vertex type for which to set its shape
      vertexShape - the VertexShape to use for vertices with the given vertex type
    • getEdgeColor

      public Color getEdgeColor(String edgeType)
      Returns the color for the given edge type
      Parameters:
      edgeType - the edge type whose color is to be determined.
      Returns:
      the color for the given edge type.
    • setEdgeColor

      public void setEdgeColor(String edgeType, String themeColorId)
      Sets the edge color using a theme color id. By using a theme color id, this property is eligible to be registered as a tool option.
      Parameters:
      edgeType - the edge type for which to set its color
      themeColorId - the theme color id of the color for this edge type
    • setEdgeColor

      public void setEdgeColor(String edgeType, Color color)
      Sets the color for edges with the given edge type
      Parameters:
      edgeType - the edge type for which to set its color
      color - the new color for edges with the given edge type
    • optionsChanged

      public void optionsChanged(ToolOptions options, String optionName, Object oldValue, Object newValue) throws OptionsVetoException
      Description copied from interface: OptionsChangeListener
      Notification that an option changed.

      Note: to reject an options change, you can throw a OptionsVetoException.

      Specified by:
      optionsChanged in interface OptionsChangeListener
      Parameters:
      options - options object containing the property that changed
      optionName - name of option that changed
      oldValue - old value of the option
      newValue - new value of the option
      Throws:
      OptionsVetoException - if a change is rejected
    • getRootOptionsName

      public String getRootOptionsName()
      Returns the name for the root Options name for this GraphDisplayOptions
      Returns:
      the name for the root Options name for this GraphDisplayOptions
    • getVertexColorOverrideAttributeKey

      public String getVertexColorOverrideAttributeKey()
      Returns the attribute key that can be used to override the color of a vertex. Normally, a vertex is colored based on its vertex type. However, if this value is non-null, a vertex can override its color by setting an attribute using this key name.
      Returns:
      the attribute key that can be used to override the color of a vertex
    • getVertexShapeOverrideAttributeKey

      public String getVertexShapeOverrideAttributeKey()
      Returns the attribute key that can be used to override the shape of a vertex. Normally, a vertex has a shape based on its vertex type. However, if this value is non-null, a vertex can override its shape by setting an attribute using this key name.
      Returns:
      the attribute key that can be used to override the shape of a vertex
    • getDefaultVertexShape

      public VertexShape getDefaultVertexShape()
      returns the VertexShape for any vertex that has not vertex type defined
      Returns:
      the VertexShape for any vertex that has not vertex type defined
    • getVertexShape

      public VertexShape getVertexShape(String vertexType)
      Returns the VertexShape for vertices that have the given vertex type
      Parameters:
      vertexType - the vertex type for which to get its asigned shape
      Returns:
      the VertexShape for vertices that have the given vertex type
    • getVertexSelectionColor

      public Color getVertexSelectionColor()
      Returns the vertex selection color
      Returns:
      the vertex selection color
    • setVertexSelectionColor

      public void setVertexSelectionColor(Color vertexSelectionColor)
      Sets the vertex selection color. Use this method only if this color does not appear in the tool options.
      Parameters:
      vertexSelectionColor - the color to use for highlighting selected vertices
    • setVertexSelectionColor

      public void setVertexSelectionColor(String themeColorId)
      Sets the vertex selection color using the theme color defined by the given color id. This method will allow the property to be registered to the tool options.
      Parameters:
      themeColorId - the color id to use for highlighting vertices.
    • getEdgeSelectionColor

      public Color getEdgeSelectionColor()
      Returns the color for edge selections
      Returns:
      the color fore edge selections
    • setEdgeSelectionColor

      public void setEdgeSelectionColor(Color edgeSelectionColor)
      Sets the edge selection color. Using the method means the color will not appear in the tool options.
      Parameters:
      edgeSelectionColor - color to use for highlighting selected edges
    • setEdgeSelectionColor

      public void setEdgeSelectionColor(String themeColorId)
      Sets the edge selection color using the theme color defined by the given color id. This method will allow the property to be registered to the tool options.
      Parameters:
      themeColorId - the color id to use for highlighting edges.
    • getDefaultLayoutAlgorithmNameLayout

      public String getDefaultLayoutAlgorithmNameLayout()
      Returns the name of the default graph layout algorithm
      Returns:
      the name of the default graph layout algorithms
    • setDefaultLayoutAlgorithmName

      public void setDefaultLayoutAlgorithmName(String defaultLayout)
      Sets the name of the default layout algorithm
      Parameters:
      defaultLayout - the name of the layout algorithm to use by default
    • usesIcons

      public boolean usesIcons()
      Returns true if the rendering mode is to use icons for the vertices. If using icons, the label is drawn inside the shape.
      Returns:
      true if the rendering mode is to use icons.
    • setUsesIcons

      public void setUsesIcons(boolean b)
      Sets whether the graph rendering mode is to use icons or not. If using icons, the label and shape are drawn together into a cached icon. Otherwise, the shapes are drawn on the fly and labeled separately.
      Parameters:
      b - true to render in icon mode.
    • getLabelPosition

      public GraphLabelPosition getLabelPosition()
      Returns the label position relative to the vertex. Note this is only relevant if usesIcons() is false
      Returns:
      the label position relative to the vertex
    • setLabelPosition

      public void setLabelPosition(GraphLabelPosition labelPosition)
      Sets the label position relative to the vertex. Note this is only relevant if usesIcons() is false.
      Parameters:
      labelPosition - the GraphLabelPosition to use for rendering vertex labels
    • setFont

      public void setFont(Font font)
      Sets the font to use for drawing vertex labels
      Parameters:
      font - the font to use for drawing vertex labels
    • setFont

      public void setFont(String themeFontId)
    • getFont

      public Font getFont()
      Returns the font being used to render vertex labels
      Returns:
      the font being used to render vertex labels
    • getArrowLength

      public int getArrowLength()
      Returns the length of the arrow. The width will be proportional to the length. Note: this option is not exposed in the Options because it is too specific to a graph instance and wouldn't be appropriate to apply to shared options.
      Returns:
      the size if the arrow
    • setArrowLength

      public void setArrowLength(int length)
      Sets the length of the arrow. The width will be proportional to the length. Note: this option is not exposed in the Options because it is too specific to a graph instance and wouldn't be appropriate to apply to shared options.
      Parameters:
      length - the size of the arrow
    • getMaxNodeCount

      public int getMaxNodeCount()
      Returns the maximum number of nodes that can be in a displayed graph
      Returns:
      the maximum number of nodes that can be in a displayed graph
    • setMaxNodeCount

      public void setMaxNodeCount(int maxNodeCount)
      Sets the maximum number of nodes a graph can have and still be displayed. Be careful, setting this value too high can result in Ghidra running out of memory and/or making the system very sluggish.
      Parameters:
      maxNodeCount - the maximum number of nodes a graph can have and still be displayed.
    • isRegisteredWithTool

      public boolean isRegisteredWithTool()
      Returns true if this GraphDisplayOptions instance has been constructed with a tool for getting/saving option values in the tool options
      Returns:
      true if this GraphDisplayOptions instance is connected to tool options
    • registerOptions

      protected void registerOptions(Tool tool, HelpLocation help)
      Registers this GraphTypeDisplayOptions with ToolOptions. Note: this should only be used by plugins or other objects that get instantiated immediately when the tool is constructed. Otherwise, if the tool exits and this hasn't been called, any saved option values will be lost.

      Parameters:
      tool - The tool to use to register options
      help - the help location to be used by the OptionsDialog for display/editing these options
    • registerOptions

      protected void registerOptions(ToolOptions toolOptions, HelpLocation help)
    • displayEditor

      public void displayEditor(Tool tool, HelpLocation help)
      Pop up a dialog for editing these graph display options. If the options are registered with tool options, show the tool options with the appropriate graph options selected. Otherwise, show an editor for locally editing these options.
      Parameters:
      tool - the tool
      help - the help location to use if the options are edited locally
    • configureVertexType

      protected void configureVertexType(String vertexType, VertexShape vertexShape, Color color)
      Sets default values for vertex types. This method does not allow the vertexType color to be eligible to be registered as a tool option.
      Parameters:
      vertexType - the vertex type whose default color and shape are being defined
      vertexShape - the default vertex shape for the given vertex type
      color - the default color for the given vertex type
    • configureVertexType

      protected void configureVertexType(String vertexType, VertexShape vertexShape, String themeColorId)
      Sets default values for vertex types using theme color ids. This makes them eligible to be registered as tool options.
      Parameters:
      vertexType - the vertex type whose default color and shape are being defined
      vertexShape - the default vertex shape for the given vertex type
      themeColorId - the color id for the theme color to be used as the color.
    • configureEdgeType

      protected void configureEdgeType(String edgeType, Color color)
      Sets default values for edge types. This method does not allow the vertexType color to be eligible to be registered as a tool option.
      Parameters:
      edgeType - the edge type whose default color and shape are being defined
      color - the default color for the given edge type
    • configureEdgeType

      protected void configureEdgeType(String edgeType, String themeColorId)
      Sets default values for edge types using theme color ids. This makes them eligible to be registered as tool options.
      Parameters:
      edgeType - the edge type whose default color and shape are being defined
      themeColorId - the color id for the theme color to be used as the color.
    • initializeFromOptions

      public void initializeFromOptions(Tool tool)
      Loads values from tool options
      Parameters:
      tool - the tool from which to update values.