protected int getIndex(Graph<V,E> graph, E e, V v) { Collection<E> commonEdgeSet = new HashSet<E>(); for(E another : graph.getIncidentEdges(v)) { V u = graph.getOpposite(v, another); if(u.equals(v)) { commonEdgeSet.add(another); } } int count=0; for(E other : commonEdgeSet) { if(e.equals(other) == false) { edge_index.put(Context.<Graph<V,E>,E>getInstance(graph,other), count); count++; } } edge_index.put(Context.<Graph<V,E>,E>getInstance(graph,e), count); return count; }
protected int getIndex(Graph<V, E> graph, E e, V v) { Collection<E> commonEdgeSet = new HashSet<E>(); for (E another : graph.getIncidentEdges(v)) { V u = graph.getOpposite(v, another); if (u.equals(v)) { commonEdgeSet.add(another); } } int count = 0; for (E other : commonEdgeSet) { if (e.equals(other) == false) { edge_index.put( Context.<Graph<V, E>, E> getInstance(graph, other), count); count++; } } edge_index.put(Context.<Graph<V, E>, E> getInstance(graph, e), count); return count; }
protected int getIndex(Graph<V,E> graph, E e, V v, V u) { Collection<E> commonEdgeSet = new HashSet<E>(graph.getIncidentEdges(u)); commonEdgeSet.retainAll(graph.getIncidentEdges(v)); for(Iterator<E> iterator=commonEdgeSet.iterator(); iterator.hasNext(); ) { E edge = iterator.next(); Pair<V> ep = graph.getEndpoints(edge); V first = ep.getFirst(); V second = ep.getSecond(); // remove loops if(first.equals(second) == true) { iterator.remove(); } // remove edges in opposite direction if(first.equals(v) == false) { iterator.remove(); } } int count=0; for(E other : commonEdgeSet) { if(e.equals(other) == false) { edge_index.put(Context.<Graph<V,E>,E>getInstance(graph,other), count); count++; } } edge_index.put(Context.<Graph<V,E>,E>getInstance(graph,e), count); return count; }
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))) { paintIconForVertex(rc, v, layout); } }
protected int getIndex(Graph<V, E> graph, E e, V v, V u) { Collection<E> commonEdgeSet = new HashSet<E>(graph.getIncidentEdges(u)); commonEdgeSet.retainAll(graph.getIncidentEdges(v)); for (Iterator<E> iterator = commonEdgeSet.iterator(); iterator .hasNext();) { E edge = iterator.next(); Pair<V> ep = graph.getEndpoints(edge); V first = ep.getFirst(); V second = ep.getSecond(); // remove loops if (first.equals(second) == true) { iterator.remove(); } // remove edges in opposite direction if (first.equals(v) == false) { iterator.remove(); } } int count = 0; for (E other : commonEdgeSet) { if (e.equals(other) == false) { edge_index.put( Context.<Graph<V, E>, E> getInstance(graph, other), count); count++; } } edge_index.put(Context.<Graph<V, E>, E> getInstance(graph, e), count); return count; }
/** * Returns the index for <code>e</code> in <code>graph</code>. * Calculates the indices for <code>e</code> and for all edges parallel * to <code>e</code>, if they are not already assigned. */ public int getIndex(Graph<V, E> graph, E e) { checkNotNull(graph, "graph must not be null"); checkNotNull(e, "'e' must not be null"); Integer index = edge_index.get(Context.<Graph<V,E>,E>getInstance(graph,e)); //edge_index.get(e); if(index == null) { Pair<V> endpoints = graph.getEndpoints(e); V u = endpoints.getFirst(); V v = endpoints.getSecond(); if(u.equals(v)) { index = getIndex(graph, e, v); } else { index = getIndex(graph, e, u, v); } } return index.intValue(); }
/** * Returns the index for <code>e</code> in <code>graph</code>. Calculates * the indices for <code>e</code> and for all edges parallel to * <code>e</code>, if they are not already assigned. */ @Override public int getIndex(Graph<V, E> graph, E e) { Integer index = edge_index .get(Context.<Graph<V, E>, E> getInstance(graph, e)); // edge_index.get(e); if (index == null) { Pair<V> endpoints = graph.getEndpoints(e); V u = endpoints.getFirst(); V v = endpoints.getSecond(); if (u.equals(v)) { index = getIndex(graph, e, v); } else { index = getIndex(graph, e, u, v); } } return index.intValue(); }
/** * Returns <code>true</code> if this edge and its endpoints * in this graph are all included in the collections of * elements to be rendered, and <code>false</code> otherwise. * @param context the edge and graph to be queried * @return <code>true</code> if this edge and its endpoints are all * included in the collections of elements to be rendered, <code>false</code> * otherwise. */ protected boolean isEdgeRendered(Context<Graph<V,E>,E> context) { Predicate<Context<Graph<V,E>,V>> vertexIncludePredicate = vv.getRenderContext().getVertexIncludePredicate(); Predicate<Context<Graph<V,E>,E>> edgeIncludePredicate = vv.getRenderContext().getEdgeIncludePredicate(); Graph<V,E> g = context.graph; E e = context.element; boolean edgeTest = edgeIncludePredicate == null || edgeIncludePredicate.apply(context); Pair<V> endpoints = g.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); boolean endpointsTest = vertexIncludePredicate == null || (vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v1)) && vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v2))); return edgeTest && endpointsTest; }
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); } } }
protected Collection<V> getFilteredVertices(Layout<V,E> layout) { if(verticesAreFiltered()) { Collection<V> unfiltered = layout.getGraph().getVertices(); Collection<V> filtered = new LinkedHashSet<V>(); for(V v : unfiltered) { if(isVertexRendered(Context.<Graph<V,E>,V>getInstance(layout.getGraph(),v))) { filtered.add(v); } } return filtered; } else { return layout.getGraph().getVertices(); } }
public void paintEdge(RenderContext<V,E> rc, Layout<V, E> layout, E e) { GraphicsDecorator g2d = rc.getGraphicsContext(); Graph<V,E> graph = layout.getGraph(); if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e))) return; // don't draw edge if either incident vertex is not drawn Pair<V> endpoints = graph.getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2))) return; Stroke new_stroke = rc.getEdgeStrokeTransformer().apply(e); Stroke old_stroke = g2d.getStroke(); if (new_stroke != null) g2d.setStroke(new_stroke); drawSimpleEdge(rc, layout, e); // restore paint and stroke if (new_stroke != null) g2d.setStroke(old_stroke); }
protected Collection<E> getFilteredEdges(Layout<V,E> layout) { if(edgesAreFiltered()) { Collection<E> unfiltered = layout.getGraph().getEdges(); Collection<E> filtered = new LinkedHashSet<E>(); for(E e : unfiltered) { if(isEdgeRendered(Context.<Graph<V,E>,E>getInstance(layout.getGraph(),e))) { filtered.add(e); } } return filtered; } else { return layout.getGraph().getEdges(); } }
/** * 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 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); }
V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e))) return; if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2))) return; double totalLength = Math.sqrt(distX * distX + distY * distY); double closeness = rc.getEdgeLabelClosenessTransformer().apply(Context.<Graph<V,E>,E>getInstance(graph, e)).doubleValue();
final Node v1 = endpoints.getFirst(); final Node v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Edge>getInstance(graph, e))) { return; if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v1)) || !rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v2))) { return;
V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E> getInstance(graph, e))) return; .evaluate(Context.<Graph<V, E>, V> getInstance(graph, v1)) || !rc.getVertexIncludePredicate() .evaluate(Context.<Graph<V, E>, V> getInstance(graph, v2))) return; .transform(Context.<Graph<V, E>, E> getInstance(graph, e)).doubleValue(); .transform(Context.<Graph<V, E>, E> getInstance(graph, e));
public void labelVertex(final RenderContext<ElementName, Dependency> rc, final Layout<ElementName, Dependency> layout, final ElementName v, final String label) { final Graph<ElementName, Dependency> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate( Context.<Graph<ElementName, Dependency>, ElementName> getInstance( graph, v)) == false) { return; } final GraphicsDecorator g = rc.getGraphicsContext(); final Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); final Dimension d = component.getPreferredSize(); final int h_offset = -d.width / 2; final int v_offset = -d.height / 2; Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); final int x = (int) p.getX(); final int y = (int) p.getY(); g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true); }
public void labelVertex(final RenderContext<ElementName, Dependency> rc, final Layout<ElementName, Dependency> layout, final ElementName v, final String label) { final Graph<ElementName, Dependency> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate( Context.<Graph<ElementName, Dependency>, ElementName> getInstance( graph, v)) == false) { return; } final GraphicsDecorator g = rc.getGraphicsContext(); final Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); final Dimension d = component.getPreferredSize(); final int h_offset = -d.width / 2; final int v_offset = -d.height / 2; Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); final int x = (int) p.getX(); final int y = (int) p.getY(); g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true); }
public void labelVertex(final RenderContext<ElementName, Dependency> rc, final Layout<ElementName, Dependency> layout, final ElementName v, final String label) { final Graph<ElementName, Dependency> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate( Context.<Graph<ElementName, Dependency>, ElementName> getInstance( graph, v)) == false) { return; } final GraphicsDecorator g = rc.getGraphicsContext(); final Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); final Dimension d = component.getPreferredSize(); final int h_offset = -d.width / 2; final int v_offset = -d.height / 2; Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); final int x = (int) p.getX(); final int y = (int) p.getY(); g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true); }