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 GraphDisplayOptionsDEFAULT
-
Constructor Summary
Constructors Constructor Description GraphDisplayOptions(GraphType graphType)Constructs a new GraphTypeDisplayOptions for the givenGraphTypeGraphDisplayOptions(GraphType graphType, Tool tool)Constructs a new GraphTypeDisplayOptions for the givenGraphTypeand initializes from tool options.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChangeListener(javax.swing.event.ChangeListener listener)Adds a ChangeListener to be notified when display options changeprotected voidconfigureEdgeType(java.lang.String edgeType, java.awt.Color color)Sets default values for edge typesprotected voidconfigureVertexType(java.lang.String vertexType, VertexShape vertexShape, java.awt.Color color)Sets default values for vertex typesintgetArrowLength()Returns the length of the arrow.java.awt.ColorgetDefaultEdgeColor()Returns the default color for edges that don't have an edge type setjava.lang.StringgetDefaultLayoutAlgorithmNameLayout()Returns the name of the default graph layout algorithmjava.awt.ColorgetDefaultVertexColor()Returns the default color for vertices that don't have an vertex type setVertexShapegetDefaultVertexShape()returns theVertexShapefor any vertex that has not vertex type definedjava.awt.ColorgetEdgeColor(AttributedEdge edge)Returns the color that will be used to draw the edgejava.awt.ColorgetEdgeColor(java.lang.String edgeType)Returns the color for the given edge typejava.lang.StringgetEdgeColorOverrideAttributeKey()Returns the attribute key that can be used to override the color of an edgejava.lang.IntegergetEdgePriority(java.lang.String edgeType)Returns the priority for the given edge type.java.awt.ColorgetEdgeSelectionColor()Returns the color for edge selectionsjava.lang.StringgetFavoredEdgeType()Returns the edge type that is the preferred edge for layout purposesjava.awt.FontgetFont()Returns the font being used to render vertex labelsGraphTypegetGraphType()Returns theGraphTypethat this object provides display options forGraphLabelPositiongetLabelPosition()Returns the label position relative to the vertex.intgetMaxNodeCount()Returns the maximum number of nodes that can be in a displayed graphjava.lang.StringgetRootOptionsName()Returns the name for the root Options name for thisGraphDisplayOptionsjava.awt.ColorgetVertexColor(AttributedVertex vertex)Returns the color that will be used to draw the vertexjava.awt.ColorgetVertexColor(java.lang.String vertexType)Returns the color for the given vertex typejava.lang.StringgetVertexColorOverrideAttributeKey()Returns the attribute key that can be used to override the color of a vertex.java.lang.StringgetVertexLabel(AttributedVertex vertex)Returns the text that will be displayed as the label for the given vertexjava.lang.StringgetVertexLabelOverride()Returns the attribute key that can override the vertices label textjava.awt.ColorgetVertexSelectionColor()Returns the vertex selection colorVertexShapegetVertexShape(AttributedVertex vertex)Returns theVertexShapethat will be used to draw the vertex's shapeVertexShapegetVertexShape(java.lang.String vertexType)Returns theVertexShapefor vertices that have the given vertex typejava.lang.StringgetVertexShapeOverrideAttributeKey()Returns the attribute key that can be used to override the shape of a vertex.protected voidinitializeDefaults()voidinitializeFromOptions(Tool tool)Loads values from tool optionsbooleanisRegisteredWithTool()Returns true if thisGraphDisplayOptionsinstance has been constructed with a tool for getting/saving option values in the tool optionsvoidoptionsChanged(ToolOptions options, java.lang.String optionName, java.lang.Object oldValue, java.lang.Object newValue)Notification that an option changed.voidregisterOptions(ToolOptions toolOptions, HelpLocation help)Registers this GraphTypeDisplayOptions withToolOptions.voidremoveChangeListener(javax.swing.event.ChangeListener listener)Removes the listener so that it won't be notified of changes any longervoidsetArrowLength(int length)Sets the length of the arrow.voidsetDefaultEdgeColor(java.awt.Color color)Sets the default color to be used by edges that don't have a edge type setvoidsetDefaultLayoutAlgorithmName(java.lang.String defaultLayout)Sets the name of the default layout algorithmvoidsetDefaultVertexColor(java.awt.Color color)Sets the default color to be used by vertices that don't have a vertex type setvoidsetDefaultVertexShape(VertexShape shape)Sets the default shape to be used by vertices that don't have a vertex type setvoidsetEdgeColor(java.lang.String edgeType, java.awt.Color color)Sets the color for edges with the given edge typevoidsetEdgeColorOverrideAttributeKey(java.lang.String attributeKey)Sets the attribute key that can be used to override the color for an edge.voidsetEdgeSelectionColor(java.awt.Color edgeSelectionColor)Sets the edge selection colorvoidsetFavoredEdgeType(java.lang.String favoredEdgeType)Sets the favored edge type.voidsetFont(java.awt.Font font)Sets the font to use for drawing vertex labelsvoidsetLabelPosition(GraphLabelPosition labelPosition)Sets the label position relative to the vertex.voidsetMaxNodeCount(int maxNodeCount)Sets the maximum number of nodes a graph can have and still be displayed.voidsetUsesIcons(boolean b)Sets whether the graph rendering mode is to use icons or not.voidsetVertexColor(java.lang.String vertexType, java.awt.Color color)Sets the color for vertices with the given vertex typevoidsetVertexColorOverrideAttributeKey(java.lang.String attributeKey)Sets the attribute key that can be used to override the color for a vertex.voidsetVertexLabelOverrideAttributeKey(java.lang.String attributeKey)Sets the attribute key that can be used to override the label text shown for the vertex.voidsetVertexSelectionColor(java.awt.Color vertexSelectionColor)Sets the vertex selection colorvoidsetVertexShape(java.lang.String vertexType, VertexShape vertexShape)Sets theVertexShapeto use for vertices with the given vertex typevoidsetVertexShapeOverrideAttributeKey(java.lang.String attributeKey)Sets the attribute key that can be used to override the shape for a vertex.booleanusesIcons()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- TheGraphTypefor which to define display options
-
GraphDisplayOptions
public GraphDisplayOptions(GraphType graphType, Tool tool)
Constructs a new GraphTypeDisplayOptions for the givenGraphTypeand initializes from tool options. Note this form should only be used for display options onGraphTypes that have options registered in the tool.- Parameters:
graphType- TheGraphTypefor 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 theVertexShapethat will be used to draw the vertex's shape- Parameters:
vertex- the vertex for which to get the shape- Returns:
- the
VertexShapethat 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 theGraphTypethat this object provides display options for- Returns:
- the
GraphTypethat 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 theVertexShapeto use for vertices with the given vertex type- Parameters:
vertexType- the vertex type for which to set its shapevertexShape- theVertexShapeto 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:OptionsChangeListenerNotification that an option changed.Note: to reject an options change, you can throw a
OptionsVetoException.- Specified by:
optionsChangedin 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 theVertexShapefor any vertex that has not vertex type defined- Returns:
- the
VertexShapefor any vertex that has not vertex type defined
-
getVertexShape
public VertexShape getVertexShape(java.lang.String vertexType)
Returns theVertexShapefor vertices that have the given vertex type- Parameters:
vertexType- the vertex type for which to get its asigned shape- Returns:
- the
VertexShapefor 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- theGraphLabelPositionto 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 thisGraphDisplayOptionsinstance has been constructed with a tool for getting/saving option values in the tool options- Returns:
- true if this
GraphDisplayOptionsinstance 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- theToolOptionsto register these options withhelp- the help location to be used by theOptionsDialogfor 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.
-
-