@Override public void paint(Graphics2D g) { g.setColor(Color.BLACK); for (NodeView view : nodes) { Node<String> node = view.getNode(); for (NodeView other : nodes) { Node<String> otherNode = other.getNode(); if (graph.connected(node, otherNode)) { Line2D l2d = new Line2D.Double(view.getX(), view.getY(), other.getX(), other.getY()); // stroke width asymptotically approaches 10 // 10 (1 - r^(w/k)) // w = weight // r = convergence time // k = scalar for weight // find edge Set<? extends WeightedEdge<String, Double>> neighboringEdges = graph.getNeighboringEdges(node); for (WeightedEdge<String, Double> edge : neighboringEdges) { if (edge.getTail() == otherNode) { Color headColor = mst != null && mst.contains(edge) ? Color.RED : Color.BLACK; Color tailColor = (edge instanceof DirectedEdge) ? new Color(headColor.getRGB() & 0x1FFFFFFF, true) : headColor; g.setPaint( new GradientPaint( new Point2D.Double(view.getX(), view.getY()), headColor, new Point2D.Double(other.getX(), other.getY()), tailColor)); float width = (float) (10 * (1f - Math.pow( 0.8f, Math.abs(edge.getWeight()) / (settings.useDistanceWeight ? 6f : 3f)))); if (edge.getWeight() >= 0) { g.setStroke(new BasicStroke(width)); } else { g.setStroke( new BasicStroke( width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, new float[] {width * 4}, 0)); } } } g.draw(l2d); } } super.paint(g); } }
@Override public void preparePaint(Graphics2D g) { super.preparePaint(g); GObject.antialias(g); }