mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-757 - Function Graph - added options to set background color for
graph view and for the vertices Closes #1324
This commit is contained in:
parent
c905c203f0
commit
9e785c25ec
18 changed files with 150 additions and 30 deletions
|
@ -124,7 +124,7 @@ public class GraphComponent<V extends VisualVertex, E extends VisualEdge<V>, G e
|
|||
// a cache to prevent unnecessary layout calculations
|
||||
private Dimension lastSize;
|
||||
|
||||
private VisualGraphOptions options = new VisualGraphOptions();
|
||||
protected VisualGraphOptions options = new VisualGraphOptions();
|
||||
|
||||
public GraphComponent(G graph) {
|
||||
|
||||
|
@ -208,9 +208,7 @@ public class GraphComponent<V extends VisualVertex, E extends VisualEdge<V>, G e
|
|||
renderContext.setVertexFillPaintTransformer(
|
||||
new PickableVertexPaintTransformer<>(pickedVertexState, Color.WHITE, Color.YELLOW));
|
||||
|
||||
viewer.setBackground(Color.WHITE);
|
||||
|
||||
viewer.setGraphOptions(new VisualGraphOptions());
|
||||
viewer.setGraphOptions(options);
|
||||
|
||||
return viewer;
|
||||
}
|
||||
|
@ -297,6 +295,8 @@ public class GraphComponent<V extends VisualVertex, E extends VisualEdge<V>, G e
|
|||
|
||||
SatelliteGraphViewer<V, E> viewer = createSatelliteGraphViewer(masterViewer, viewerSize);
|
||||
|
||||
viewer.setGraphOptions(options);
|
||||
|
||||
viewer.setMinimumSize(viewerSize);
|
||||
viewer.setMaximumSize(viewerSize);
|
||||
|
||||
|
@ -525,6 +525,15 @@ public class GraphComponent<V extends VisualVertex, E extends VisualEdge<V>, G e
|
|||
|
||||
public void setGraphOptions(VisualGraphOptions options) {
|
||||
this.options = options;
|
||||
|
||||
// the viewers may be null if called during initialization
|
||||
if (primaryViewer != null) {
|
||||
primaryViewer.setGraphOptions(options);
|
||||
}
|
||||
|
||||
if (satelliteViewer != null) {
|
||||
satelliteViewer.setGraphOptions(options);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUninitialized() {
|
||||
|
@ -562,6 +571,11 @@ public class GraphComponent<V extends VisualVertex, E extends VisualEdge<V>, G e
|
|||
return mainPanel;
|
||||
}
|
||||
|
||||
public void optionsChanged() {
|
||||
primaryViewer.optionsChanged();
|
||||
satelliteViewer.optionsChanged();
|
||||
}
|
||||
|
||||
public void repaint() {
|
||||
mainPanel.repaint();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ public class GraphViewer<V extends VisualVertex, E extends VisualEdge<V>>
|
|||
gPickedState = new GPickedState<>((MultiPickedState<V>) pickedState);
|
||||
setPickedVertexState(gPickedState);
|
||||
|
||||
popupRegulator = new PopupRegulator<V, E>(new GraphViewerPopupSource());
|
||||
popupRegulator = new PopupRegulator<>(new GraphViewerPopupSource());
|
||||
}
|
||||
|
||||
private void buildUpdater() {
|
||||
|
@ -158,6 +158,11 @@ public class GraphViewer<V extends VisualVertex, E extends VisualEdge<V>>
|
|||
|
||||
public void setGraphOptions(VisualGraphOptions options) {
|
||||
this.options = options;
|
||||
optionsChanged();
|
||||
}
|
||||
|
||||
public void optionsChanged() {
|
||||
setBackground(options.getGraphBackgroundColor());
|
||||
}
|
||||
|
||||
public VisualGraphOptions getOptions() {
|
||||
|
|
|
@ -21,6 +21,7 @@ import edu.uci.ics.jung.visualization.control.SatelliteVisualizationViewer;
|
|||
import edu.uci.ics.jung.visualization.renderers.Renderer;
|
||||
import ghidra.graph.viewer.event.mouse.VisualGraphPluggableGraphMouse;
|
||||
import ghidra.graph.viewer.event.mouse.VisualGraphSatelliteGraphMouse;
|
||||
import ghidra.graph.viewer.options.VisualGraphOptions;
|
||||
import ghidra.graph.viewer.renderer.VisualGraphRenderer;
|
||||
import ghidra.graph.viewer.renderer.VisualVertexSatelliteRenderer;
|
||||
|
||||
|
@ -36,6 +37,7 @@ public class SatelliteGraphViewer<V extends VisualVertex, E extends VisualEdge<V
|
|||
|
||||
protected GraphViewer<V, E> graphViewer;
|
||||
private boolean docked;
|
||||
private VisualGraphOptions options;
|
||||
|
||||
public SatelliteGraphViewer(GraphViewer<V, E> master, Dimension preferredSize) {
|
||||
super(master, preferredSize);
|
||||
|
@ -73,6 +75,15 @@ public class SatelliteGraphViewer<V extends VisualVertex, E extends VisualEdge<V
|
|||
return new VisualVertexSatelliteRenderer<>();
|
||||
}
|
||||
|
||||
public void setGraphOptions(VisualGraphOptions options) {
|
||||
this.options = options;
|
||||
optionsChanged();
|
||||
}
|
||||
|
||||
public void optionsChanged() {
|
||||
setBackground(options.getGraphBackgroundColor());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public VisualGraphPluggableGraphMouse<V, E> getGraphMouse() {
|
||||
|
@ -87,5 +98,4 @@ public class SatelliteGraphViewer<V extends VisualVertex, E extends VisualEdge<V
|
|||
}
|
||||
super.setGraphMouse(graphMouse);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ import ghidra.graph.VisualGraph;
|
|||
import ghidra.graph.viewer.event.mouse.VertexTooltipProvider;
|
||||
import ghidra.graph.viewer.event.mouse.VisualGraphMousePlugin;
|
||||
import ghidra.graph.viewer.layout.LayoutProvider;
|
||||
import ghidra.graph.viewer.options.VisualGraphOptions;
|
||||
import ghidra.graph.viewer.vertex.VertexClickListener;
|
||||
import ghidra.graph.viewer.vertex.VertexFocusListener;
|
||||
|
||||
|
@ -159,6 +158,13 @@ public class VisualGraphView<V extends VisualVertex,
|
|||
undockedSatelliteContentPanel.validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the options used by this graph view have changed
|
||||
*/
|
||||
public void optionsChanged() {
|
||||
graphComponent.optionsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the given layout provider, <b>but does not actually perform a layout</b>.
|
||||
* @param newLayoutProvider the new provider
|
||||
|
@ -201,7 +207,6 @@ public class VisualGraphView<V extends VisualVertex,
|
|||
|
||||
protected void installGraphViewer() {
|
||||
GraphComponent<V, E, G> newGraphComponent = new GraphComponent<>(graph);
|
||||
newGraphComponent.setGraphOptions(new VisualGraphOptions());
|
||||
setGraphComponent(newGraphComponent);
|
||||
}
|
||||
|
||||
|
@ -522,7 +527,7 @@ public class VisualGraphView<V extends VisualVertex,
|
|||
public MouseEvent translateMouseEventFromVertexToViewSpace(V v, MouseEvent e) {
|
||||
Point viewerPoint = translatePointFromVertexToViewSpace(v, e.getPoint());
|
||||
VisualizationViewer<V, E> newSource = getPrimaryGraphViewer();
|
||||
return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiers(),
|
||||
return new MouseEvent(newSource, e.getID(), e.getWhen(), e.getModifiersEx(),
|
||||
(int) viewerPoint.getX(), (int) viewerPoint.getY(), e.getClickCount(),
|
||||
e.isPopupTrigger(), e.getButton());
|
||||
}
|
||||
|
|
|
@ -15,10 +15,16 @@
|
|||
*/
|
||||
package ghidra.graph.viewer.options;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import docking.DockingUtils;
|
||||
|
||||
public class VisualGraphOptions {
|
||||
|
||||
public static final String GRAPH_BACKGROUND_COLOR_KEY = "Graph Background Color";
|
||||
public static final String GRAPH_BACKGROUND_COLOR_DESCRPTION =
|
||||
"The graph display background color";
|
||||
|
||||
public static final String SHOW_ANIMATION_OPTIONS_KEY = "Use Animation";
|
||||
public static final String SHOW_ANIMATION_DESCRIPTION = "Signals to the Function Graph to " +
|
||||
"use animated transitions for certain operations, like navigation.";
|
||||
|
@ -48,6 +54,9 @@ public class VisualGraphOptions {
|
|||
"new graphs and already rendered graphs are zoomed and positioned. See the help for " +
|
||||
"more details.";
|
||||
|
||||
public static final Color DEFAULT_GRAPH_BACKGROUND_COLOR = Color.WHITE;
|
||||
protected Color graphBackgroundColor = DEFAULT_GRAPH_BACKGROUND_COLOR;
|
||||
|
||||
protected boolean useAnimation = true;
|
||||
protected boolean scrollWheelPans = false;
|
||||
|
||||
|
@ -59,6 +68,10 @@ public class VisualGraphOptions {
|
|||
|
||||
protected ViewRestoreOption viewRestoreOption = ViewRestoreOption.START_FULLY_ZOOMED_OUT;
|
||||
|
||||
public Color getGraphBackgroundColor() {
|
||||
return graphBackgroundColor;
|
||||
}
|
||||
|
||||
public boolean getScrollWheelPans() {
|
||||
return scrollWheelPans;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,6 @@ public class TestGraphAlgorithmSteppingViewerPanel<V, E extends GEdge<V>> extend
|
|||
|
||||
tvg.setLayout(layout);
|
||||
viewer = new GraphViewer<>(layout, new Dimension(400, 400));
|
||||
viewer.setBackground(Color.WHITE);
|
||||
viewer.setGraphOptions(new VisualGraphOptions());
|
||||
|
||||
Renderer<AlgorithmTestSteppingVertex<V>, AlgorithmTestSteppingEdge<V>> renderer =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue