Package ghidra.service.graph
Class GraphDisplayOptions
- java.lang.Object
-
- ghidra.service.graph.GraphDisplayOptions
-
- All Implemented Interfaces:
OptionsChangeListener
- Direct Known Subclasses:
DefaultGraphDisplayOptions
,ProgramGraphDisplayOptions
public class GraphDisplayOptions extends java.lang.Object implements OptionsChangeListener
Class for managing graph display options. This includes color options for each vertex and edge type and shapes for vertex types.
-
-
Field Summary
Fields Modifier and Type Field Description static GraphDisplayOptions
DEFAULT
-
Constructor Summary
Constructors Constructor Description GraphDisplayOptions(GraphType graphType)
Constructs a new GraphTypeDisplayOptions for the givenGraphType
GraphDisplayOptions(GraphType graphType, Tool tool)
Constructs a new GraphTypeDisplayOptions for the givenGraphType
and initializes from tool options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(javax.swing.event.ChangeListener listener)
Adds a ChangeListener to be notified when display options changeprotected void
configureEdgeType(java.lang.String edgeType, java.awt.Color color)
Sets default values for edge typesprotected void
configureVertexType(java.lang.String vertexType, VertexShape vertexShape, java.awt.Color color)
Sets default values for vertex typesint
getArrowLength()
Returns the length of the arrow.java.awt.Color
getDefaultEdgeColor()
Returns the default color for edges that don't have an edge type setjava.lang.String
getDefaultLayoutAlgorithmNameLayout()
Returns the name of the default graph layout algorithmjava.awt.Color
getDefaultVertexColor()
Returns the default color for vertices that don't have an vertex type setVertexShape
getDefaultVertexShape()
returns theVertexShape
for any vertex that has not vertex type definedjava.awt.Color
getEdgeColor(AttributedEdge edge)
Returns the color that will be used to draw the edgejava.awt.Color
getEdgeColor(java.lang.String edgeType)
Returns the color for the given edge typejava.lang.String
getEdgeColorOverrideAttributeKey()
Returns the attribute key that can be used to override the color of an edgejava.lang.Integer
getEdgePriority(java.lang.String edgeType)
Returns the priority for the given edge type.java.awt.Color
getEdgeSelectionColor()
Returns the color for edge selectionsjava.lang.String
getFavoredEdgeType()
Returns the edge type that is the preferred edge for layout purposesjava.awt.Font
getFont()
Returns the font being used to render vertex labelsGraphType
getGraphType()
Returns theGraphType
that this object provides display options forGraphLabelPosition
getLabelPosition()
Returns the label position relative to the vertex.int
getMaxNodeCount()
Returns the maximum number of nodes that can be in a displayed graphjava.lang.String
getRootOptionsName()
Returns the name for the root Options name for thisGraphDisplayOptions
java.awt.Color
getVertexColor(AttributedVertex vertex)
Returns the color that will be used to draw the vertexjava.awt.Color
getVertexColor(java.lang.String vertexType)
Returns the color for the given vertex typejava.lang.String
getVertexColorOverrideAttributeKey()
Returns the attribute key that can be used to override the color of a vertex.java.lang.String
getVertexLabel(AttributedVertex vertex)
Returns the text that will be displayed as the label for the given vertexjava.lang.String
getVertexLabelOverride()
Returns the attribute key that can override the vertices label textjava.awt.Color
getVertexSelectionColor()
Returns the vertex selection colorVertexShape
getVertexShape(AttributedVertex vertex)
Returns theVertexShape
that will be used to draw the vertex's shapeVertexShape
getVertexShape(java.lang.String vertexType)
Returns theVertexShape
for vertices that have the given vertex typejava.lang.String
getVertexShapeOverrideAttributeKey()
Returns the attribute key that can be used to override the shape of a vertex.protected void
initializeDefaults()
void
initializeFromOptions(Tool tool)
Loads values from tool optionsboolean
isRegisteredWithTool()
Returns true if thisGraphDisplayOptions
instance has been constructed with a tool for getting/saving option values in the tool optionsvoid
optionsChanged(ToolOptions options, java.lang.String optionName, java.lang.Object oldValue, java.lang.Object newValue)
Notification that an option changed.void
registerOptions(ToolOptions toolOptions, HelpLocation help)
Registers this GraphTypeDisplayOptions withToolOptions
.void
removeChangeListener(javax.swing.event.ChangeListener listener)
Removes the listener so that it won't be notified of changes any longervoid
setArrowLength(int length)
Sets the length of the arrow.void
setDefaultEdgeColor(java.awt.Color color)
Sets the default color to be used by edges that don't have a edge type setvoid
setDefaultLayoutAlgorithmName(java.lang.String defaultLayout)
Sets the name of the default layout algorithmvoid
setDefaultVertexColor(java.awt.Color color)
Sets the default color to be used by vertices that don't have a vertex type setvoid
setDefaultVertexShape(VertexShape shape)
Sets the default shape to be used by vertices that don't have a vertex type setvoid
setEdgeColor(java.lang.String edgeType, java.awt.Color color)
Sets the color for edges with the given edge typevoid
setEdgeColorOverrideAttributeKey(java.lang.String attributeKey)
Sets the attribute key that can be used to override the color for an edge.void
setEdgeSelectionColor(java.awt.Color edgeSelectionColor)
Sets the edge selection colorvoid
setFavoredEdgeType(java.lang.String favoredEdgeType)
Sets the favored edge type.void
setFont(java.awt.Font font)
Sets the font to use for drawing vertex labelsvoid
setLabelPosition(GraphLabelPosition labelPosition)
Sets the label position relative to the vertex.void
setMaxNodeCount(int maxNodeCount)
Sets the maximum number of nodes a graph can have and still be displayed.void
setUsesIcons(boolean b)
Sets whether the graph rendering mode is to use icons or not.void
setVertexColor(java.lang.String vertexType, java.awt.Color color)
Sets the color for vertices with the given vertex typevoid
setVertexColorOverrideAttributeKey(java.lang.String attributeKey)
Sets the attribute key that can be used to override the color for a vertex.void
setVertexLabelOverrideAttributeKey(java.lang.String attributeKey)
Sets the attribute key that can be used to override the label text shown for the vertex.void
setVertexSelectionColor(java.awt.Color vertexSelectionColor)
Sets the vertex selection colorvoid
setVertexShape(java.lang.String vertexType, VertexShape vertexShape)
Sets theVertexShape
to use for vertices with the given vertex typevoid
setVertexShapeOverrideAttributeKey(java.lang.String attributeKey)
Sets the attribute key that can be used to override the shape for a vertex.boolean
usesIcons()
Returns true if the rendering mode is to use icons for the vertices.
-
-
-
Field Detail
-
DEFAULT
public static final GraphDisplayOptions DEFAULT
-
-
Constructor Detail
-
GraphDisplayOptions
public GraphDisplayOptions(GraphType graphType)
Constructs a new GraphTypeDisplayOptions for the givenGraphType
- Parameters:
graphType
- TheGraphType
for which to define display options
-
GraphDisplayOptions
public GraphDisplayOptions(GraphType graphType, Tool tool)
Constructs a new GraphTypeDisplayOptions for the givenGraphType
and initializes from tool options. Note this form should only be used for display options onGraphType
s that have options registered in the tool.- Parameters:
graphType
- TheGraphType
for which to define display optionstool
- the tool from which to initialize fromToolOptions
-
-
Method Detail
-
initializeDefaults
protected void initializeDefaults()
-
addChangeListener
public void addChangeListener(javax.swing.event.ChangeListener listener)
Adds a ChangeListener to be notified when display options change- Parameters:
listener
- the listener to be notified.
-
removeChangeListener
public void removeChangeListener(javax.swing.event.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(java.awt.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
-
setDefaultEdgeColor
public void setDefaultEdgeColor(java.awt.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
-
getDefaultEdgeColor
public java.awt.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 java.awt.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(java.lang.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 java.lang.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(java.lang.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(java.lang.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 java.lang.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(java.lang.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 java.lang.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 theVertexShape
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 java.awt.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 java.awt.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 java.lang.Integer getEdgePriority(java.lang.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 java.lang.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(java.lang.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 theGraphType
that this object provides display options for- Returns:
- the
GraphType
that this object provides display options for
-
getVertexColor
public java.awt.Color getVertexColor(java.lang.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(java.lang.String vertexType, java.awt.Color color)
Sets the color for vertices with the given vertex type- Parameters:
vertexType
- the vertex type for which to set its colorcolor
- the color to use for vertices with the given vertex type
-
setVertexShape
public void setVertexShape(java.lang.String vertexType, VertexShape vertexShape)
Sets theVertexShape
to use for vertices with the given vertex type- Parameters:
vertexType
- the vertex type for which to set its shapevertexShape
- theVertexShape
to use for vertices with the given vertex type
-
getEdgeColor
public java.awt.Color getEdgeColor(java.lang.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(java.lang.String edgeType, java.awt.Color color)
Sets the color for edges with the given edge type- Parameters:
edgeType
- the edge type for which to set its colorcolor
- the new color for edges with the given edge type
-
optionsChanged
public void optionsChanged(ToolOptions options, java.lang.String optionName, java.lang.Object oldValue, java.lang.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 interfaceOptionsChangeListener
- Parameters:
options
- options object containing the property that changedoptionName
- name of option that changedoldValue
- old value of the optionnewValue
- new value of the option- Throws:
OptionsVetoException
- if a change is rejected
-
getRootOptionsName
public java.lang.String getRootOptionsName()
Returns the name for the root Options name for thisGraphDisplayOptions
- Returns:
- the name for the root Options name for this
GraphDisplayOptions
-
getVertexColorOverrideAttributeKey
public java.lang.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 java.lang.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 theVertexShape
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(java.lang.String vertexType)
Returns theVertexShape
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 java.awt.Color getVertexSelectionColor()
Returns the vertex selection color- Returns:
- the vertex selection color
-
setVertexSelectionColor
public void setVertexSelectionColor(java.awt.Color vertexSelectionColor)
Sets the vertex selection color- Parameters:
vertexSelectionColor
- the color to use for highlighting selected vertices
-
getEdgeSelectionColor
public java.awt.Color getEdgeSelectionColor()
Returns the color for edge selections- Returns:
- the color fore edge selections
-
setEdgeSelectionColor
public void setEdgeSelectionColor(java.awt.Color edgeSelectionColor)
Sets the edge selection color- Parameters:
edgeSelectionColor
- color to use for highlighting selected edges
-
getDefaultLayoutAlgorithmNameLayout
public java.lang.String getDefaultLayoutAlgorithmNameLayout()
Returns the name of the default graph layout algorithm- Returns:
- the name of the default graph layout algorithms
-
setDefaultLayoutAlgorithmName
public void setDefaultLayoutAlgorithmName(java.lang.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 ifusesIcons()
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 ifusesIcons()
is false.- Parameters:
labelPosition
- theGraphLabelPosition
to use for rendering vertex labels
-
setFont
public void setFont(java.awt.Font font)
Sets the font to use for drawing vertex labels- Parameters:
font
- the font to use for drawing vertex labels
-
getFont
public java.awt.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 thisGraphDisplayOptions
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
public void registerOptions(ToolOptions toolOptions, HelpLocation help)
Registers this GraphTypeDisplayOptions withToolOptions
. 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:
toolOptions
- theToolOptions
to register these options withhelp
- the help location to be used by theOptionsDialog
for display/editing these options
-
configureVertexType
protected void configureVertexType(java.lang.String vertexType, VertexShape vertexShape, java.awt.Color color)
Sets default values for vertex types- Parameters:
vertexType
- the vertex type whose default color and shape are being definedvertexShape
- the default vertex shape for the given vertex typecolor
- the default color for the given vertex type
-
configureEdgeType
protected void configureEdgeType(java.lang.String edgeType, java.awt.Color color)
Sets default values for edge types- Parameters:
edgeType
- the edge type whose default color and shape are being definedcolor
- the default color for the given edge type
-
initializeFromOptions
public void initializeFromOptions(Tool tool)
Loads values from tool options- Parameters:
tool
- the tool from which to update values.
-
-