private static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right, final double coef) { final double coef1 = coef; final double coef2 = 1 - coef; final double centerxA = src.getCtrlX1() * coef1 + src.getCtrlX2() * coef2; final double centeryA = src.getCtrlY1() * coef1 + src.getCtrlY2() * coef2; final double x1 = src.getX1(); final double y1 = src.getY1(); final double x2 = src.getX2(); final double y2 = src.getY2(); final double ctrlx1 = x1 * coef1 + src.getCtrlX1() * coef1; final double ctrly1 = y1 * coef1 + src.getCtrlY1() * coef1; final double ctrlx2 = x2 * coef1 + src.getCtrlX2() * coef1; final double ctrly2 = y2 * coef1 + src.getCtrlY2() * coef1; final double ctrlx12 = ctrlx1 * coef1 + centerxA * coef1; final double ctrly12 = ctrly1 * coef1 + centeryA * coef1; final double ctrlx21 = ctrlx2 * coef1 + centerxA * coef1; final double ctrly21 = ctrly2 * coef1 + centeryA * coef1; final double centerxB = ctrlx12 * coef1 + ctrlx21 * coef1; final double centeryB = ctrly12 * coef1 + ctrly21 * coef1; left.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx12, ctrly12, centerxB, centeryB); right.setCurve(centerxB, centeryB, ctrlx21, ctrly21, ctrlx2, ctrly2, x2, y2); }
private CubicCurve2D createCubicCurve2D(Point startPoint, Point startPoint2, Point endPoint2, Point endPoint) { final CubicCurve2D arrowLinkCurve = new CubicCurve2D.Double(); if (startPoint != null && endPoint != null) { arrowLinkCurve.setCurve(startPoint, startPoint2, endPoint2, endPoint); } else if (startPoint != null) { arrowLinkCurve.setCurve(startPoint, startPoint2, startPoint, startPoint2); } else if (endPoint != null) { arrowLinkCurve.setCurve(endPoint, endPoint2, endPoint, endPoint2); } return arrowLinkCurve; }
public CubicCurve2D getRepresentedCubic() { CubicCurve2D toRet=new CubicCurve2D.Double(); toRet.setCurve(this.p0, this.c0, this.c1, this.p1); return toRet; }
/** * Get the shape for this edge, returning either the shared instance or, in the case of * self-loop edges, the Loop shared instance. */ public Shape apply(Context<Network<N, E>, E> context) { Network graph = context.graph; E e = context.element; if (isLoop(graph, e)) { return loop.apply(context); } int index = getIndex(context, edgeIndexFunction); float controlY = control_offset_increment + control_offset_increment * index; CUBIC_CURVE.setCurve(0.0f, 0.0f, 0.33f, 2 * controlY, .66f, -controlY, 1.0f, 0.0f); return CUBIC_CURVE; } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); CubicCurve2D c = new CubicCurve2D.Double(); int x1 = 150, y1 = 150; //p1 int x2 = 350, y2 = 300;//p3 int ctrlx1, ctrly1, ctrlx2, ctrly2; int delta = 10; ctrlx1 = x1; // curve start x ctrly1 = y2 - delta; // curve start y ctrlx2 = x1 + delta; // curve end x ctrly2 = y2; g2d.drawRect(x1-50, y1-100, 100, 100); c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); g2d.drawRect(x2, y2-50, 100, 100); g2d.draw(c); }
public CubicCurveEdgeEffects() { this.rawEdge.setCurve(0.0f, 0.0f, 0.33f, 100, 0.66f, -50, 1.0f, 0.0f); rawArrowShape = ArrowFactory.getNotchedArrow(20, 16, 8); this.edgePaintable = new EdgePaintable(); this.arrowPaintable = new ArrowPaintable(); }
public CubicCurveEdgeEffects() { this.rawEdge.setCurve(0.0f, 0.0f, 0.33f, 100, 0.66f, -50, 1.0f, 0.0f); rawArrowShape = ArrowFactory.getNotchedArrow(20, 16, 8); this.edgePaintable = new EdgePaintable(); this.arrowPaintable = new ArrowPaintable(); }
private Path2D.Double createArrow() { int length = 80; Path2D.Double path = new Path2D.Double(); Rectangle2D.Double rect = new Rectangle2D.Double(-1, -length, 2, length); path.append(rect, true); Rectangle2D.Double rect2 = new Rectangle2D.Double(0, -length, 2, length); path.append(rect2, true); CubicCurve2D c = new CubicCurve2D.Double(); c.setCurve(0, -length, length / 4, -length - 20, length / 2, -length + 10, length, -length); path.append(c, true); Line2D line = new Line2D.Double(length, -length, length, -length / 3); path.append(line, true); c = new CubicCurve2D.Double(); c.setCurve(length, -length / 3, length / 2, -length / 3 + 10, length / 4, -length / 3 - 20, 0, -length / 3); path.append(c, true); return path; }
curve.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
return quad; case CUBIC: cubic.setCurve(0.0f, 0.0f, 0.33f, 2 * controlY, .66f, -controlY, 1.0f, 0.0f); return cubic; case BENT:
c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY, linkX, linkY); g2.draw(c);
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
protected void paintEdges(Graphics g, Tree parent) { if (!getTree().isLeaf(parent)) { BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); ((Graphics2D)g).setStroke(stroke); Rectangle2D.Double parentBounds = getBoundsOfNode(parent); double x1 = parentBounds.getCenterX(); double y1 = parentBounds.getMaxY(); for (Tree child : getTree().getChildren(parent)) { Rectangle2D.Double childBounds = getBoundsOfNode(child); double x2 = childBounds.getCenterX(); double y2 = childBounds.getMinY(); if (getUseCurvedEdges()) { CubicCurve2D c = new CubicCurve2D.Double(); double ctrlx1 = x1; double ctrly1 = (y1+y2)/2; double ctrlx2 = x2; double ctrly2 = y1; c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2); ((Graphics2D) g).draw(c); } else { g.drawLine((int) x1, (int) y1, (int) x2, (int) y2); } paintEdges(g, child); } } }
final float dx = x2 - x1; final float dy = y2 - y1; _cubic_curve.setCurve( x1, y1, x1 + ( dx * 0.4f ), y1 + ( dy * 0.2f ), x1 + ( dx * 0.6f ), y1 + ( dy * 0.8f ), x2, y2 ); ( g ).draw( _cubic_curve );
private static void subdivide(CubicCurve2D src, CubicCurve2D left, CubicCurve2D right, final double coef) { final double coef1 = coef; final double coef2 = 1 - coef; final double centerxA = src.getCtrlX1() * coef1 + src.getCtrlX2() * coef2; final double centeryA = src.getCtrlY1() * coef1 + src.getCtrlY2() * coef2; final double x1 = src.getX1(); final double y1 = src.getY1(); final double x2 = src.getX2(); final double y2 = src.getY2(); final double ctrlx1 = x1 * coef1 + src.getCtrlX1() * coef1; final double ctrly1 = y1 * coef1 + src.getCtrlY1() * coef1; final double ctrlx2 = x2 * coef1 + src.getCtrlX2() * coef1; final double ctrly2 = y2 * coef1 + src.getCtrlY2() * coef1; final double ctrlx12 = ctrlx1 * coef1 + centerxA * coef1; final double ctrly12 = ctrly1 * coef1 + centeryA * coef1; final double ctrlx21 = ctrlx2 * coef1 + centerxA * coef1; final double ctrly21 = ctrly2 * coef1 + centeryA * coef1; final double centerxB = ctrlx12 * coef1 + ctrlx21 * coef1; final double centeryB = ctrly12 * coef1 + ctrly21 * coef1; left.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx12, ctrly12, centerxB, centeryB); right.setCurve(centerxB, centeryB, ctrlx21, ctrly21, ctrlx2, ctrly2, x2, y2); }
/** * Constructor that allows to set the modifiers to activate both * 'add unidirectional link' and 'add bidirectional link' modes. * * @param callback Topology callback * @param modifiers Modifier to activate the plugin to add unidirectional links * @param modifiersBidirectional Modifier to activate the plugin to add bidirectional links * @since 0.2.0 */ public AddLinkGraphPlugin(GUINetworkDesign callback, ITopologyCanvas canvas , int modifiers, int modifiersBidirectional) { setModifiers(modifiers); setModifiersBidirectional(modifiersBidirectional); this.callback = callback; down = null; startVertex = null; rawEdge = new CubicCurve2D.Float(); rawEdge.setCurve(0.0f, 0.0f, 0.33f, 100, .66f, -50, 1.0f, 0.0f); rawArrowShape = ArrowFactory.getNotchedArrow(20, 16, 8); edgePaintable = new EdgePaintable(); arrowPaintable = new ArrowPaintable(); this.canvas = canvas; }