public Point2D apply(V arg0) { return layout.apply(arg0); }
public Point2D transform(V v) { return delegate.apply(v); }
public void step() { Graph<V,E> g = transitionLayout.getGraph(); for(V v : g.getVertices()) { Point2D tp = transitionLayout.apply(v); Point2D fp = endLayout.apply(v); double dx = (fp.getX()-tp.getX())/(count-counter); double dy = (fp.getY()-tp.getY())/(count-counter); transitionLayout.setLocation(v, new Point2D.Double(tp.getX()+dx,tp.getY()+dy)); } counter++; if(counter >= count) { done = true; vv.setGraphLayout(endLayout); } vv.repaint(); } }
/** * Returns the location of the vertex. The location is specified first * by the sublayouts, and then by the base layout if no sublayouts operate * on this vertex. * @return the location of the vertex */ public Point2D apply(V v) { boolean wasInSublayout = false; for(Layout<V,E> layout : layouts.keySet()) { if(layout.getGraph().getVertices().contains(v)) { wasInSublayout = true; Point2D center = layouts.get(layout); // transform by the layout itself, but offset to the // center of the sublayout Dimension d = layout.getSize(); AffineTransform at = AffineTransform.getTranslateInstance(center.getX()-d.width/2, center.getY()-d.height/2); return at.transform(layout.apply(v),null); } } if(wasInSublayout == false) { return delegate.apply(v); } return null; }
/** * This method calls <tt>initialize_local_vertex</tt> for each vertex, and * also adds initial coordinate information for each vertex. (The vertex's * initial location is set by calling <tt>initializeLocation</tt>. */ protected void initializeLocations() { for(V v : getGraph().getVertices()) { Point2D coord = delegate.apply(v); if (!dontmove.contains(v)) initializeLocation(v, coord); } }
public Collection<V> getVertices(Layout<V,E> layout, Shape rectangle) { Set<V> pickedVertices = new HashSet<V>(); while(true) { try { for(V v : layout.getGraph().getVertices()) { Point2D p = layout.apply(v); if(rectangle.contains(p)) { pickedVertices.add(v); } } break; } catch(ConcurrentModificationException cme) {} } return pickedVertices; }
/** * Returns the vertex shape in view coordinates. * @param rc the render context used for rendering the vertex * @param v the vertex whose shape is to be returned * @param layout the layout algorithm that provides coordinates for the vertex * @param coords the x and y view coordinates * @return the vertex shape in view coordinates */ protected Shape prepareFinalVertexShape(RenderContext<V,E> rc, V v, Layout<V,E> layout, int[] coords) { // get the shape to be rendered Shape shape = rc.getVertexShapeTransformer().apply(v); Point2D p = layout.apply(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); float x = (float)p.getX(); float y = (float)p.getY(); coords[0] = (int)x; coords[1] = (int)y; // create a transform that translates to the location of // the vertex to be rendered AffineTransform xform = AffineTransform.getTranslateInstance(x,y); // transform the vertex shape with xtransform shape = xform.createTransformedShape(shape); return shape; }
private void checkVertex(V v) { // get the shape to be rendered Shape shape = rc.getVertexShapeTransformer().apply(v); Point2D p = layout.apply(v); p = rc.getMultiLayerTransformer().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); // transform the vertex shape with xtransform shape = xform.createTransformedShape(shape); for(Rectangle2D r : bounds) { if(shape.intersects(r)) { vertices.add(v); } } }
for(V v : layout.getGraph().getVertices()) { Point2D p = layout.apply(v); double dx = p.getX() - x; double dy = p.getY() - y;
Point2D q = layout.apply(vertex); Point2D lvc = vvMaster.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.LAYOUT, vvMaster.getCenter());
public Collection<V> getVertices(Layout<V, E> layout, Shape rectangle) { Set<V> pickedVertices = new HashSet<V>(); while(true) { try { for(V v : getFilteredVertices(layout)) { Point2D p = layout.apply(v); if(p == null) continue; p = vv.getRenderContext().getMultiLayerTransformer().transform(p); if(rectangle.contains(p)) { pickedVertices.add(v); } } break; } catch(ConcurrentModificationException cme) {} } return pickedVertices; }
public void paintVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v) { Graph<V,E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v))) { boolean vertexHit = true; // get the shape to be rendered Shape shape = rc.getVertexShapeTransformer().apply(v); Point2D p = layout.apply(v); p = rc.getMultiLayerTransformer().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); // transform the vertex shape with xtransform shape = xform.createTransformedShape(shape); vertexHit = vertexHit(rc, shape); //rc.getViewTransformer().transform(shape).intersects(deviceRectangle); if (vertexHit) { paintShapeForVertex(rc, v, shape); } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) public void collapse(Layout layout, Forest tree, Object subRoot) throws InstantiationException, IllegalAccessException { // get a sub tree from subRoot Forest subTree = TreeUtils.getSubTree(tree, subRoot); Object parent = null; Object edge = null; if(tree.getPredecessorCount(subRoot) > 0) { parent = tree.getPredecessors(subRoot).iterator().next(); edge = tree.getInEdges(subRoot).iterator().next(); } tree.removeVertex(subRoot); if(parent != null) { tree.addEdge(edge, parent, subTree); } else { tree.addVertex(subTree); } layout.setLocation(subTree, (Point2D)layout.apply(subRoot)); }
public Paint apply(E e) { Layout<V, E> layout = vv.getGraphLayout(); Pair<V> p = layout.getGraph().getEndpoints(e); V b = p.getFirst(); V f = p.getSecond(); Point2D pb = transformer.transform(layout.apply(b)); Point2D pf = transformer.transform(layout.apply(f)); float xB = (float) pb.getX(); float yB = (float) pb.getY(); float xF = (float) pf.getX(); float yF = (float) pf.getY(); if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) { xF = (xF + xB) / 2; yF = (yF + yB) / 2; } if(selfLoop.apply(Context.<Graph<V,E>,E>getInstance(layout.getGraph(), e))) { yF += 50; xF += 50; } return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true); }
try { for(V v : getFilteredVertices(layout)) { Point2D p = layout.apply(v); if(p == null) continue;
/** * Labels the specified vertex with the specified label. * Uses the font specified by this instance's * <code>VertexFontFunction</code>. (If the font is unspecified, the existing * font for the graphics context is used.) If vertex label centering * is active, the label is centered on the position of the vertex; otherwise * the label is offset slightly. */ public void labelVertex(RenderContext<V,E> rc, Layout<V,E> layout, V v, String label) { Graph<V,E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v)) == false) { return; } GraphicsDecorator g = rc.getGraphicsContext(); Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); Dimension d = component.getPreferredSize(); int h_offset = -d.width / 2; int v_offset = -d.height / 2; Point2D p = layout.apply(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); int x = (int)p.getX(); int y = (int)p.getY(); g.draw(component, rc.getRendererPane(), x+h_offset, y+v_offset, d.width, d.height, true); Dimension size = component.getPreferredSize(); Rectangle bounds = new Rectangle(-size.width/2 -2, -size.height/2 -2, size.width+4, size.height); shapes.put(v, bounds); }
public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if(picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); collapsedGraph = g; double sumx = 0; double sumy = 0; for(Object v : picked) { Point2D p = (Point2D)layout.apply(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx/picked.size(), sumy/picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } }});
public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if(picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); double sumx = 0; double sumy = 0; for(Object v : picked) { Point2D p = (Point2D)layout.apply(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx/picked.size(), sumy/picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } }});
/** * Returns the vertices whose layout coordinates are contained in * <code>Shape</code>. * The shape is in screen coordinates, and the graph vertices * are transformed to screen coordinates before they are tested * for inclusion. * @return the <code>Collection</code> of vertices whose <code>layout</code> * coordinates are contained in <code>shape</code>. */ public Collection<V> getVertices(Layout<V, E> layout, Shape shape) { Set<V> pickedVertices = new HashSet<V>(); // remove the view transform from the rectangle shape = vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, shape); while(true) { try { for(V v : getFilteredVertices(layout)) { Point2D p = layout.apply(v); if(p == null) continue; p = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p); if(shape.contains(p)) { pickedVertices.add(v); } } break; } catch(ConcurrentModificationException cme) {} } return pickedVertices; }
public void paint(Graphics g) { if(mPred == null) return; // for all edges, paint edges that are in shortest path for (Number e : layout.getGraph().getEdges()) { if(isBlessed(e)) { String v1 = mGraph.getEndpoints(e).getFirst(); String v2 = mGraph.getEndpoints(e).getSecond(); Point2D p1 = layout.apply(v1); Point2D p2 = layout.apply(v2); p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p1); p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p2); Renderer<String,Number> renderer = vv.getRenderer(); renderer.renderEdge( vv.getRenderContext(), layout, e); } } } });