Lines 76-81
Link Here
|
76 |
private boolean paintControlPoints; |
76 |
private boolean paintControlPoints; |
77 |
private Color lineColor; |
77 |
private Color lineColor; |
78 |
private Cursor controlPointsCursor; |
78 |
private Cursor controlPointsCursor; |
|
|
79 |
private int controlPointCutDistance; |
79 |
|
80 |
|
80 |
private Anchor.Entry sourceEntry; |
81 |
private Anchor.Entry sourceEntry; |
81 |
private Anchor.Entry targetEntry; |
82 |
private Anchor.Entry targetEntry; |
Lines 96-101
Link Here
|
96 |
setLayout (connectionWidgetLayout); |
97 |
setLayout (connectionWidgetLayout); |
97 |
stroke = STROKE_DEFAULT; |
98 |
stroke = STROKE_DEFAULT; |
98 |
paintControlPoints = false; |
99 |
paintControlPoints = false; |
|
|
100 |
controlPointCutDistance = 0; |
99 |
sourceEntry = new ConnectionEntry (true); |
101 |
sourceEntry = new ConnectionEntry (true); |
100 |
targetEntry = new ConnectionEntry (false); |
102 |
targetEntry = new ConnectionEntry (false); |
101 |
} |
103 |
} |
Lines 182-187
Link Here
|
182 |
} |
184 |
} |
183 |
|
185 |
|
184 |
/** |
186 |
/** |
|
|
187 |
* Returns the cut distance at control points. |
188 |
* @return the cut distance |
189 |
* @since 2.5 |
190 |
*/ |
191 |
public int getControlPointCutDistance () { |
192 |
return controlPointCutDistance; |
193 |
} |
194 |
|
195 |
/** |
196 |
* Sets the cut distance at control points. |
197 |
* @param controlPointCutDistance if positive number, then the path is cut to render smooth corners; |
198 |
* otherwise the path is rendered using control points only |
199 |
* @since 2.5 |
200 |
*/ |
201 |
public void setControlPointCutDistance (int controlPointCutDistance) { |
202 |
this.controlPointCutDistance = controlPointCutDistance; |
203 |
repaint (); |
204 |
} |
205 |
|
206 |
/** |
185 |
* Returns a source anchor of the connection widget. |
207 |
* Returns a source anchor of the connection widget. |
186 |
* @return the source anchor |
208 |
* @return the source anchor |
187 |
*/ |
209 |
*/ |
Lines 648-661
Link Here
|
648 |
points = controlPoints; |
670 |
points = controlPoints; |
649 |
} |
671 |
} |
650 |
|
672 |
|
651 |
|
673 |
if (controlPointCutDistance > 0) { |
652 |
for (Point point : points) { |
674 |
for (int a = 0; a < points.size () - 1; a ++) { |
653 |
if (path == null) { |
675 |
Point p1 = points.get (a); |
654 |
path = new GeneralPath (); |
676 |
Point p2 = points.get (a + 1); |
655 |
path.moveTo (point.x, point.y); |
677 |
double len = p1.distance (p2); |
656 |
} else { |
678 |
|
657 |
path.lineTo (point.x, point.y); |
679 |
if (a > 0) { |
|
|
680 |
Point p0 = points.get (a - 1); |
681 |
double ll = p0.distance (p1); |
682 |
if (len < ll) |
683 |
ll = len; |
684 |
ll /= 2; |
685 |
double cll = controlPointCutDistance; |
686 |
if (cll > ll) |
687 |
cll = ll; |
688 |
double direction = Math.atan2 (p2.y - p1.y, p2.x - p1.x); |
689 |
if (!Double.isNaN (direction)) { |
690 |
path = addToPath (path, |
691 |
p1.x + (int) (cll * Math.cos (direction)), |
692 |
p1.y + (int) (cll * Math.sin (direction)) |
693 |
); |
694 |
} |
695 |
} else { |
696 |
path = addToPath (path, p1.x, p1.y); |
697 |
} |
698 |
|
699 |
if (a < points.size () - 2) { |
700 |
Point p3 = points.get (a + 2); |
701 |
double ll = p2.distance (p3); |
702 |
if (len < ll) |
703 |
ll = len; |
704 |
ll /= 2; |
705 |
double cll = controlPointCutDistance; |
706 |
if (cll > ll) |
707 |
cll = ll; |
708 |
double direction = Math.atan2 (p2.y - p1.y, p2.x - p1.x); |
709 |
if (!Double.isNaN (direction)) { |
710 |
path = addToPath (path, |
711 |
p2.x - (int) (cll * Math.cos (direction)), |
712 |
p2.y - (int) (cll * Math.sin (direction)) |
713 |
); |
714 |
} |
715 |
} else { |
716 |
path = addToPath (path, p2.x, p2.y); |
717 |
} |
658 |
} |
718 |
} |
|
|
719 |
} else { |
720 |
for (Point point : points) |
721 |
path = addToPath (path, point.x, point.y); |
659 |
} |
722 |
} |
660 |
if (path != null) { |
723 |
if (path != null) { |
661 |
Stroke previousStroke = gr.getStroke (); |
724 |
Stroke previousStroke = gr.getStroke (); |
Lines 699-704
Link Here
|
699 |
gr.setTransform (previousTransform); |
762 |
gr.setTransform (previousTransform); |
700 |
} |
763 |
} |
701 |
} |
764 |
} |
|
|
765 |
} |
766 |
|
767 |
private GeneralPath addToPath (GeneralPath path, int x, int y) { |
768 |
if (path == null) { |
769 |
path = new GeneralPath (); |
770 |
path.moveTo (x, y); |
771 |
} else { |
772 |
path.lineTo (x, y); |
773 |
} |
774 |
return path; |
702 |
} |
775 |
} |
703 |
|
776 |
|
704 |
private class ConnectionEntry implements Anchor.Entry { |
777 |
private class ConnectionEntry implements Anchor.Entry { |