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 Link icon

    • GRAPH_DECORATOR_THREAD_POOL_NAME Link icon

      public static final String GRAPH_DECORATOR_THREAD_POOL_NAME
      See Also:
    • GRAPH_BUILDER_THREAD_POOL_NAME Link icon

      public static final String GRAPH_BUILDER_THREAD_POOL_NAME
      See Also:
    • INTERACTION_ZOOM_THRESHOLD Link icon

      public static final double INTERACTION_ZOOM_THRESHOLD
      See Also:
    • PAINT_ZOOM_THRESHOLD Link icon

      public static final double PAINT_ZOOM_THRESHOLD
      See Also:
    • EDGE_ROW_SPACING Link icon

      public static final int EDGE_ROW_SPACING
      See Also:
    • EDGE_COLUMN_SPACING Link icon

      public static final int EDGE_COLUMN_SPACING
      See Also:
    • EXTRA_LAYOUT_ROW_SPACING Link icon

      public static final int EXTRA_LAYOUT_ROW_SPACING
      See Also:
    • EXTRA_LAYOUT_ROW_SPACING_CONDENSED Link icon

      public static final int EXTRA_LAYOUT_ROW_SPACING_CONDENSED
      See Also:
    • EXTRA_LAYOUT_COLUMN_SPACING Link icon

      public static final int EXTRA_LAYOUT_COLUMN_SPACING
      See Also:
    • EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED Link icon

      public static final int EXTRA_LAYOUT_COLUMN_SPACING_CONDENSED
      See Also:
  • Constructor Details Link icon

    • GraphViewerUtils Link icon

      public GraphViewerUtils()
  • Method Details Link icon

    • translatePointFromViewSpaceToVertexRelativeSpace Link icon

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      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 Link icon

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

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

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

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

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

      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 Link icon

      public static Shape createHollowEgdeLoop()
    • createHollowEgdeLoopInGraphSpace Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

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

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

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

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

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

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

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

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

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

      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.