Class GraphViewerUtils

java.lang.Object
ghidra.graph.viewer.GraphViewerUtils

public class GraphViewerUtils extends Object
This class houses various methods for translating location and size data from the various graph coordinate spaces. Graph Spaces Size and location information is represented in multiple coordinate spaces, as listed below. To translate from one to the other, use GraphViewerUtils; for example, to see if a mouse click is on a given vertex.
  • Layout Space - the layout contains Point2D objects that represent positions of the vertices.
  • Graph Space - the space where the Layout points are transformed as the view is moved around the screen (e.g., as the user pans)
  • View Space - the coordinate system of Java 2D rendering; scaling (zooming) transformations are applied at this layer

Note: vertex relative means that the value is from inside the vertex, or the vertex's coordinate space (like a component that is inside the vertex), where it's coordinate values are relative to the component's parent.

  • Field Details

    • GRAPH_DECORATOR_THREAD_POOL_NAME

      public static final String GRAPH_DECORATOR_THREAD_POOL_NAME
      See Also:
    • GRAPH_BUILDER_THREAD_POOL_NAME

      public static final String GRAPH_BUILDER_THREAD_POOL_NAME
      See Also:
    • INTERACTION_ZOOM_THRESHOLD

      public static final double INTERACTION_ZOOM_THRESHOLD
      See Also:
    • PAINT_ZOOM_THRESHOLD

      public static final double PAINT_ZOOM_THRESHOLD
      See Also:
    • EDGE_ROW_SPACING

      public static final int EDGE_ROW_SPACING
      See Also:
    • EDGE_COLUMN_SPACING

      public static final int EDGE_COLUMN_SPACING
      See Also:
    • EXTRA_LAYOUT_ROW_SPACING

      public static final int EXTRA_LAYOUT_ROW_SPACING
      See Also:
    • EXTRA_LAYOUT_ROW_SPACING_CONDENSED

      public static final int EXTRA_LAYOUT_ROW_SPACING_CONDENSED
      See Also:
    • EXTRA_LAYOUT_COLUMN_SPACING

      public static final int EXTRA_LAYOUT_COLUMN_SPACING
      See Also:
    • EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED

      public static final int EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED
      See Also:
  • Constructor Details

    • GraphViewerUtils

      public GraphViewerUtils()
  • Method Details

    • translatePointFromViewSpaceToVertexRelativeSpace

      public static <V, E> Point translatePointFromViewSpaceToVertexRelativeSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point startPoint)
    • translatePointFromViewSpaceToVertexRelativeSpace

      public static <V, E> Point translatePointFromViewSpaceToVertexRelativeSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point startPoint, V vertex)
    • getVertexUpperLeftCornerInLayoutSpace

      public static <V, E> Point getVertexUpperLeftCornerInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getVertexUpperLeftCornerInViewSpace

      public static <V, E> Point getVertexUpperLeftCornerInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getVertexBoundsInViewSpace

      public static <V, E> Rectangle getVertexBoundsInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getVertexBoundsInGraphSpace

      public static <V, E> Rectangle getVertexBoundsInGraphSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getVertexBoundsInLayoutSpace

      public static <V, E> Rectangle getVertexBoundsInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • convertMouseEventToVertexMouseEvent

      public static <V extends VisualVertex, E extends VisualEdge<V>> VertexMouseInfo<V,E> convertMouseEventToVertexMouseEvent(GraphViewer<V,E> viewer, MouseEvent mouseEvent)
    • getVertexUpperLeftCornerInGraphSpace

      public static <V, E> Point getVertexUpperLeftCornerInGraphSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • translatePointFromLayoutSpaceToGraphSpace

      public static <V, E> Point translatePointFromLayoutSpaceToGraphSpace(Point2D pointInLayoutSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translatePointFromLayoutSpaceToViewSpace

      public static <V, E> Point translatePointFromLayoutSpaceToViewSpace(Point2D pointInLayoutSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translatePointFromViewSpaceToGraphSpace

      public static <V, E> Point translatePointFromViewSpaceToGraphSpace(Point2D pointInViewSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translatePointFromViewSpaceToLayoutSpace

      public static <V, E> Point translatePointFromViewSpaceToLayoutSpace(Point2D pointInViewSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translatePointFromGraphSpaceToViewSpace

      public static <V, E> Point translatePointFromGraphSpaceToViewSpace(Point2D pointInGraphSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translatePointFromGraphSpaceToLayoutSpace

      public static <V, E> Point translatePointFromGraphSpaceToLayoutSpace(Point2D pointInGraphSpace, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translateShapeFromLayoutSpaceToViewSpace

      public static <V, E> Shape translateShapeFromLayoutSpaceToViewSpace(Shape shape, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translateShapeFromLayoutSpaceToGraphSpace

      public static <V, E> Shape translateShapeFromLayoutSpaceToGraphSpace(Shape shape, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translateShapeFromViewSpaceToLayoutSpace

      public static <V, E> Shape translateShapeFromViewSpaceToLayoutSpace(Shape shape, edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • translateRectangleFromVertexRelativeSpaceToViewSpace

      public static <V, E> Rectangle translateRectangleFromVertexRelativeSpaceToViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex, Rectangle rectangle)
    • translateRectangleFromLayoutSpaceToViewSpace

      public static <V, E> Rectangle translateRectangleFromLayoutSpaceToViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Rectangle rectangle)
    • getVertexFromPointInViewSpace

      public static <V, E> V getVertexFromPointInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point point)
    • getPointInViewSpaceForVertex

      public static <V, E> Point getPointInViewSpaceForVertex(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
      Get the upper-left point of vertex in the view space (Java component space)
      Parameters:
      viewer - the viewer containing the UI
      vertex - the vertex
      Returns:
      the upper-left point of the vertex
    • translatePointFromVertexRelativeSpaceToViewSpace

      public static <V, E> Point translatePointFromVertexRelativeSpaceToViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex, Point startPoint)
    • getEdgeFromPointInViewSpace

      public static <V, E> E getEdgeFromPointInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point point)
    • getScaleRatioToFitInDimension

      public static Double getScaleRatioToFitInDimension(Dimension currentSize, Dimension targetSize)
    • setGraphScale

      public static <V, E> void setGraphScale(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, double scale)
    • adjustEdgePickSizeForZoom

      public static <V, E> void adjustEdgePickSizeForZoom(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • createCollectionWithZOrderBySelection

      public static <V extends VisualVertex> List<V> createCollectionWithZOrderBySelection(Collection<V> vertices)
      Moves the selected vertices to the end of the list of vertices so that when picked (or painted), we will prefer the selected vertices, since we have configured the algorithms for the graph stuff to prefer the last accessed vertex (like when picking and painting).
      Parameters:
      vertices - the vertices to order
      Returns:
      the given vertices, ordered by selected/emphasized state
    • createHollowEgdeLoop

      public static Shape createHollowEgdeLoop()
    • createHollowEgdeLoopInGraphSpace

      public static Shape createHollowEgdeLoopInGraphSpace(Shape vertexShape, double x, double y)
      Creates a self-loop edge to be used with a vertex that calls itself. The returned shape is hollow (not a filled loop) so that mouse hit detection does not occur in the middle of the circle.
      Parameters:
      vertexShape - The shape of the vertex for which the edge is being created.
      x - The x coordinate of the vertex
      y - The y coordinate of the vertex
      Returns:
      a self-loop edge to be used with a vertex that calls itself.
    • createEgdeLoopInGraphSpace

      public static Shape createEgdeLoopInGraphSpace(Shape vertexShape, double x, double y)
      Creates a loop shape for a vertex that calls itself. The loop is transformed to graph space, which includes updating the size and location of the loop to be relative to the vertex.
      Parameters:
      vertexShape - The shape of the vertex for which the edge is being created.
      x - The x coordinate of the vertex
      y - The y coordinate of the vertex
      Returns:
      a loop shape for a vertex that calls itself.
    • createEgdeLoopInGraphSpace

      public static Shape createEgdeLoopInGraphSpace(Shape edgeLoopShape, Shape vertexShape, double x, double y)
      Transforms the given edge loop shape to graph space, which includes updating the size and location of the loop to be relative to the vertex.
      Parameters:
      edgeLoopShape - The shape to transform
      vertexShape - The shape of the vertex for which the edge is being created
      x - The x coordinate of the vertex
      y - The y coordinate of the vertex
      Returns:
      the transformed edge loop shape
    • getEdgeShapeInGraphSpace

      public static <V, E> Shape getEdgeShapeInGraphSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, E e)
    • getVertexCenterPointInViewSpace

      public static <V, E> Point2D getVertexCenterPointInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V v)
    • getVertexOffsetFromLayoutCenter

      public static <V, E> Point2D.Double getVertexOffsetFromLayoutCenter(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getVertexOffsetFromLayoutCenterTop

      public static <V, E> Point2D.Double getVertexOffsetFromLayoutCenterTop(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, V vertex)
    • getOffsetFromCenterForPointInViewSpace

      public static <V, E> Point2D.Double getOffsetFromCenterForPointInViewSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point2D point)
    • getOffsetFromCenterInLayoutSpace

      public static <V, E> Point2D.Double getOffsetFromCenterInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Point pointInLayoutSpace)
    • getGraphScale

      public static <V, E> Double getGraphScale(edu.uci.ics.jung.visualization.VisualizationServer<V,E> vv)
    • isScaledPastVertexInteractionThreshold

      public static <V, E> boolean isScaledPastVertexInteractionThreshold(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • getGraphCenterInLayoutSpace

      public static <V extends VisualVertex, E extends VisualEdge<V>> Point getGraphCenterInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • getTotalGraphSizeInLayoutSpace

      public static <V extends VisualVertex, E extends VisualEdge<V>> Rectangle getTotalGraphSizeInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer)
    • getTotalGraphSizeInLayoutSpace

      public static <V extends VisualVertex, E extends VisualEdge<V>> Rectangle getTotalGraphSizeInLayoutSpace(Collection<V> vertices, Collection<E> edges, com.google.common.base.Function<V,Rectangle> vertexToBounds, com.google.common.base.Function<E,List<Point2D>> edgeToArticulations)
    • getBoundsForVerticesInLayoutSpace

      public static <V, E> Rectangle getBoundsForVerticesInLayoutSpace(edu.uci.ics.jung.visualization.VisualizationServer<V,E> viewer, Collection<V> vertices)
      Returns a rectangle that contains all give vertices
      Parameters:
      viewer - the viewer containing the UI
      vertices - the vertices
      Returns:
      a rectangle that contains all give vertices
    • getBoundsForVerticesInLayoutSpace

      public static <V, E> Rectangle getBoundsForVerticesInLayoutSpace(Collection<V> vertices, com.google.common.base.Function<V,Rectangle> vertexToBounds)
      Returns a rectangle that contains all vertices, in the layout space
      Parameters:
      vertices - the vertices for which to calculate the bounds
      vertexToBounds - a function that can turn a single vertex into a rectangle
      Returns:
      the bounds
    • addPaddingToRectangle

      public static void addPaddingToRectangle(int padding, Rectangle rectangle)
    • layoutUsesEdgeArticulations

      public static <V extends VisualVertex, E extends VisualEdge<V>> boolean layoutUsesEdgeArticulations(edu.uci.ics.jung.algorithms.layout.Layout<V,E> graphLayout)
    • getVisualGraphLayout

      public static <V extends VisualVertex, E extends VisualEdge<V>> VisualGraphLayout<V,E> getVisualGraphLayout(edu.uci.ics.jung.algorithms.layout.Layout<V,E> graphLayout)
    • getVerticesOfHoveredEdges

      public static <V extends VisualVertex, E extends VisualEdge<V>> Collection<V> getVerticesOfHoveredEdges(edu.uci.ics.jung.graph.Graph<V,E> graph)
    • getVerticesOfSelectedEdges

      public static <V extends VisualVertex, E extends VisualEdge<V>> Collection<V> getVerticesOfSelectedEdges(edu.uci.ics.jung.graph.Graph<V,E> graph)
      Returns a collection of vertices that are incident to selected edges.
      Parameters:
      graph - the graph from which to retrieve vertices
      Returns:
      a collection of vertices that are incident to selected edges.