Java Code Examples for edu.uci.ics.jung.algorithms.layout.Layout#apply()
The following examples show how to use
edu.uci.ics.jung.algorithms.layout.Layout#apply() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisualGraphPickingGraphMousePlugin.java From ghidra with Apache License 2.0 | 6 votes |
private void dragVertices(MouseEvent e, GraphViewer<V, E> viewer) { Point p = e.getPoint(); RenderContext<V, E> context = viewer.getRenderContext(); MultiLayerTransformer xformer = context.getMultiLayerTransformer(); Point2D layoutPoint = xformer.inverseTransform(p); Point2D layoutDown = xformer.inverseTransform(down); Layout<V, E> layout = viewer.getGraphLayout(); double dx = layoutPoint.getX() - layoutDown.getX(); double dy = layoutPoint.getY() - layoutDown.getY(); PickedState<V> ps = viewer.getPickedVertexState(); for (V v : ps.getPicked()) { Point2D vertexPoint = layout.apply(v); vertexPoint.setLocation(vertexPoint.getX() + dx, vertexPoint.getY() + dy); layout.setLocation(v, vertexPoint); updatedArticulatedEdges(viewer, v); } down = p; e.consume(); }
Example 2
Source File: GroupHistoryInfo.java From ghidra with Apache License 2.0 | 6 votes |
public GroupHistoryInfo(FunctionGraph functionGraph, GroupedFunctionGraphVertex groupVertex) { this.groupVertices = new HashSet<>(groupVertex.getVertices()); if (groupVertices.isEmpty()) { throw new IllegalArgumentException( "Cannot create a group history entry with no vertices!"); } this.groupDescription = groupVertex.getUserText(); if (groupDescription == null) { throw new IllegalArgumentException("Group description cannot be null"); } Layout<FGVertex, FGEdge> graphLayout = functionGraph.getLayout(); Point2D location = graphLayout.apply(groupVertex); locationInfo = new PointInfo(location); addressInfo = new AddressInfo(groupVertex); }
Example 3
Source File: GroupedFunctionGraphVertex.java From ghidra with Apache License 2.0 | 6 votes |
private Map<FGVertex, Point2D> getCurrentVertexLocations() { FGController fgController = getController(); FGView view = fgController.getView(); VisualizationViewer<FGVertex, FGEdge> viewer = view.getPrimaryGraphViewer(); Layout<FGVertex, FGEdge> graphLayout = viewer.getGraphLayout(); Graph<FGVertex, FGEdge> graph = graphLayout.getGraph(); Collection<FGVertex> currentVertices = graph.getVertices(); Map<FGVertex, Point2D> map = new HashMap<>(); for (FGVertex vertex : currentVertices) { if (vertex == this) { // not sure if we need to do this, but, conceptually, we are getting the locations // in the graph before this group node is installed continue; } Point2D point2D = graphLayout.apply(vertex); map.put(vertex, new Point((int) point2D.getX(), (int) point2D.getY())); } return map; }
Example 4
Source File: FcgExpandingVertexCollection.java From ghidra with Apache License 2.0 | 6 votes |
private int compareVerticesByLayoutPosition(FcgVertex v1, FcgVertex v2) { Layout<FcgVertex, FcgEdge> layout = viewer.getGraphLayout(); FcgLevel l1 = v1.getLevel(); FcgLevel l2 = v2.getLevel(); int result = l1.compareTo(l2); if (result != 0) { // prefer the parent level over all if (l1.equals(parentLevel)) { return -1; } else if (l2.equals(parentLevel)) { return 1; } return result; } Point2D p1 = layout.apply(v1); Point2D p2 = layout.apply(v2); return (int) (p1.getX() - p2.getX()); }
Example 5
Source File: BowTieExpandVerticesJob.java From ghidra with Apache License 2.0 | 6 votes |
private Rectangle getBounds(List<FcgVertex> vertices) { RenderContext<FcgVertex, FcgEdge> renderContext = viewer.getRenderContext(); Function<? super FcgVertex, Shape> shaper = renderContext.getVertexShapeTransformer(); Layout<FcgVertex, FcgEdge> layout = viewer.getGraphLayout(); Rectangle area = null; for (FcgVertex v : vertices) { Rectangle bounds = shaper.apply(v).getBounds(); Point2D loc = layout.apply(v); int x = (int) loc.getX(); int y = (int) loc.getY(); // do we need to compensate for vertex centering (like is done in the default layout)? // x -= (bounds.width / 2); // y -= (bounds.height / 2); bounds.setLocation(x, y); if (area == null) { area = bounds; // initialize } area.add(bounds); } return area; }
Example 6
Source File: VisualEdgeRenderer.java From ghidra with Apache License 2.0 | 5 votes |
protected Shape transformFromLayoutToView(RenderContext<V, E> rc, Layout<V, E> layout, V vertex, Shape shape) { Point2D p = layout.apply(vertex); MultiLayerTransformer multiLayerTransformer = rc.getMultiLayerTransformer(); p = multiLayerTransformer.transform(Layer.LAYOUT, p); float x = (float) p.getX(); float y = (float) p.getY(); // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x, y); return xform.createTransformedShape(shape); }
Example 7
Source File: AbstractVisualVertexRenderer.java From ghidra with Apache License 2.0 | 5 votes |
/** * Takes the given shape and translates its coordinates to the view space * * @param rc the render context * @param layout the model space layout * @param vertex the vertex * @param shape the shape to translate * @return the new shape */ protected Shape transformFromLayoutToView(RenderContext<V, E> rc, Layout<V, E> layout, V vertex, Shape shape) { Point2D p = layout.apply(vertex); MultiLayerTransformer multiLayerTransformer = rc.getMultiLayerTransformer(); p = multiLayerTransformer.transform(Layer.LAYOUT, p); float x = (float) p.getX(); float y = (float) p.getY(); // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x, y); return xform.createTransformedShape(shape); }
Example 8
Source File: TestLayoutProvider.java From ghidra with Apache License 2.0 | 5 votes |
@Override public TestGraphLayout getLayout(TestVisualGraph g, TaskMonitor monitor) throws CancelledException { Layout<AbstractTestVertex, TestEdge> jungLayout = new DAGLayout<>(g); Collection<AbstractTestVertex> vertices = g.getVertices(); for (AbstractTestVertex v : vertices) { Point2D p = jungLayout.apply(v); v.setLocation(p); } return new TestGraphLayout(jungLayout); }
Example 9
Source File: VertexInfo.java From ghidra with Apache License 2.0 | 5 votes |
VertexInfo(FGVertex vertex, FunctionGraph functionGraph) { vertexAddressInfo = new AddressInfo(vertex); Layout<FGVertex, FGEdge> graphLayout = functionGraph.getLayout(); Point2D location = graphLayout.apply(vertex); locationInfo = new PointInfo(location); }
Example 10
Source File: AbstractFunctionGraphTest.java From ghidra with Apache License 2.0 | 5 votes |
protected Point2D getLocation(FGVertex vertex) { FGController controller = getFunctionGraphController(); FGView view = controller.getView(); VisualizationViewer<FGVertex, FGEdge> primaryGraphViewer = view.getPrimaryGraphViewer(); VisualizationModel<FGVertex, FGEdge> model = primaryGraphViewer.getModel(); Layout<FGVertex, FGEdge> graphLayout = model.getGraphLayout(); return graphLayout.apply(vertex); }
Example 11
Source File: SampleGraphLayoutProvider.java From ghidra with Apache License 2.0 | 5 votes |
protected void initVertexLocations(SampleGraph g, Layout<SampleVertex, SampleEdge> layout) { Collection<SampleVertex> vertices = g.getVertices(); for (SampleVertex v : vertices) { Point2D p = layout.apply(v); v.setLocation(p); } }
Example 12
Source File: ArticulatedEdgeRouter.java From ghidra with Apache License 2.0 | 4 votes |
private void moveArticulationsAroundVertices(Set<V> vertices, E edge, boolean goLeft) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Pair<V> endpoints = graph.getEndpoints(edge); V start = endpoints.getFirst(); V end = endpoints.getSecond(); Point2D startPoint = layout.apply(start); Point2D endPoint = layout.apply(end); // Rectangle bounds = getBoundsForVerticesInLayoutSpace(viewer, vertices); // paint the shape // Color color = getIntersectingBoxColor(edge); // String name = goLeft ? "Left" : "Right"; // DebugShape<V, E> debugShape = // new DebugShape<V, E>(viewer, debugCounter, name, // translateShapeFromLayoutSpaceToGraphSpace(bounds, viewer), color); // viewer.addPostRenderPaintable(debugShape); Rectangle bounds = spaceBetweenEndPointsShape.getBounds(); int padding = 20; int x = goLeft ? bounds.x : bounds.x + bounds.width; x += goLeft ? -padding : padding; Point2D top = new Point2D.Double(x, bounds.y - padding); Point2D bottom = new Point2D.Double(x, bounds.y + bounds.height + padding); if (startPoint.getY() > endPoint.getY()) { // swap the top and bottom points, as our source vertex is below the destination Point2D newTop = bottom; bottom = top; top = newTop; } List<Point2D> articulationPoints = new ArrayList<>(); articulationPoints.add(top); articulationPoints.add(bottom); edge.setArticulationPoints(articulationPoints); }
Example 13
Source File: BasicEdgeRouter.java From ghidra with Apache License 2.0 | 4 votes |
protected List<Point2D> removeBadlyAngledArticulations(E edge, List<Point2D> articulations) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Pair<V> endpoints = graph.getEndpoints(edge); V start = endpoints.getFirst(); V end = endpoints.getSecond(); Point2D startPoint = layout.apply(start); Point2D endPoint = layout.apply(end); if (startPoint.getY() > endPoint.getY()) { // swap the top and bottom points, as our source vertex is below the destination Point2D newStart = endPoint; endPoint = startPoint; startPoint = newStart; } List<Point2D> newList = new ArrayList<>(); for (Point2D articulation : articulations) { double deltaY = articulation.getY() - startPoint.getY(); double deltaX = articulation.getX() - startPoint.getX(); double theta = Math.atan2(deltaY, deltaX); double degrees = theta * 180 / Math.PI; if (degrees < 0 || degrees > 180) { continue; } deltaY = endPoint.getY() - articulation.getY(); deltaX = endPoint.getX() - articulation.getX(); theta = Math.atan2(deltaY, deltaX); degrees = theta * 180 / Math.PI; if (degrees < 0 || degrees > 180) { continue; } newList.add(articulation); } return newList; }
Example 14
Source File: AbstractVisualVertexRenderer.java From ghidra with Apache License 2.0 | 4 votes |
/** * Creates a copy of the given {@link GraphicsDecorator} that may have scaling tweaked to * handle {@link VisualVertex#getEmphasis()} emphasized vertices. */ protected GraphicsDecorator getEmphasisGraphics(GraphicsDecorator g, V vertex, RenderContext<V, E> rc, Layout<V, E> layout) { Graphics2D graphicsCopy = (Graphics2D) g.create(); GraphicsDecorator decoratorCopy = new GraphicsDecorator(graphicsCopy); double alpha = vertex.getAlpha(); if (alpha < 1D) { decoratorCopy.setComposite( AlphaComposite.getInstance(AlphaComposite.SrcOver.getRule(), (float) alpha)); } double emphasis = vertex.getEmphasis(); if (emphasis == 0) { return decoratorCopy; } AffineTransform transform = graphicsCopy.getTransform(); double scaleX = transform.getScaleX(); if (((int) scaleX) == 1) { return decoratorCopy; } Point2D p = layout.apply(vertex); MultiLayerTransformer multiLayerTransformer = rc.getMultiLayerTransformer(); p = multiLayerTransformer.transform(Layer.LAYOUT, p); double vertexX = p.getX(); double vertexY = p.getY(); AffineTransform xf = AffineTransform.getTranslateInstance(vertexX, vertexY); emphasis = adjustValueForCurrentScale(rc, emphasis, .5); double newScale = 1.0 + emphasis; xf.scale(newScale, newScale); xf.translate(-vertexX, -vertexY); transform.concatenate(xf); graphicsCopy.setTransform(transform); return decoratorCopy; }
Example 15
Source File: AbstractLayoutProvider.java From ghidra with Apache License 2.0 | 3 votes |
/** * Gives all vertices of the graph an initial, non-null location. This only works if the * graph has been built before this method is called. * * <P>Some graphs that have a layout will perform this same function as vertices are added. * * @param g the graph * @param layout the graph layout */ protected void initVertexLocations(G g, Layout<V, E> layout) { Collection<V> vertices = g.getVertices(); for (V v : vertices) { Point2D p = layout.apply(v); v.setLocation(p); } }