This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 106508
Collapse All | Expand All

(-)graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java (+1 lines)
Lines 108-113 Link Here
108
        "test.vmd.VMDCollisionTest",
108
        "test.vmd.VMDCollisionTest",
109
        "test.vmd.VMDTest",
109
        "test.vmd.VMDTest",
110
        "test.widget.AnimatedImageTest",
110
        "test.widget.AnimatedImageTest",
111
        "test.widget.ConnectionWidgetCutDistanceTest",
111
        "test.zoom.FitToViewTest",
112
        "test.zoom.FitToViewTest",
112
    };
113
    };
113
114
(-)graph/examples/src/test/widget/ConnectionWidgetCutDistanceTest.java (+67 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
20
package test.widget;
21
22
import org.netbeans.api.visual.anchor.AnchorFactory;
23
import org.netbeans.api.visual.router.RouterFactory;
24
import org.netbeans.api.visual.widget.ConnectionWidget;
25
import org.netbeans.api.visual.widget.Scene;
26
import org.netbeans.api.visual.widget.LabelWidget;
27
import org.netbeans.api.visual.layout.LayoutFactory;
28
import test.SceneSupport;
29
30
import java.awt.*;
31
32
/**
33
 * @author David Kaspar
34
 */
35
public class ConnectionWidgetCutDistanceTest {
36
37
    public static void main (String[] args) {
38
        Scene scene = new Scene ();
39
40
        ConnectionWidget conn1 = new ConnectionWidget (scene);
41
        conn1.setControlPointCutDistance (8);
42
        conn1.setRouter (RouterFactory.createOrthogonalSearchRouter ());
43
        conn1.setSourceAnchor (AnchorFactory.createFixedAnchor (new Point (50, 50)));
44
        conn1.setTargetAnchor (AnchorFactory.createFixedAnchor (new Point (450, 150)));
45
        conn1.getActions ().addAction (scene.createWidgetHoverAction ());
46
        scene.addChild (conn1);
47
48
        LabelWidget label1 = new LabelWidget (scene, "Control Point Cut Distance = 8");
49
        conn1.addChild (label1);
50
        conn1.setConstraint (label1, LayoutFactory.ConnectionWidgetLayoutAlignment.BOTTOM_RIGHT, 0);
51
52
        ConnectionWidget conn2 = new ConnectionWidget (scene);
53
        conn2.setControlPointCutDistance (0);
54
        conn2.setRouter (RouterFactory.createOrthogonalSearchRouter ());
55
        conn2.setSourceAnchor (AnchorFactory.createFixedAnchor (new Point (50, 250)));
56
        conn2.setTargetAnchor (AnchorFactory.createFixedAnchor (new Point (450, 350)));
57
        conn2.getActions ().addAction (scene.createWidgetHoverAction ());
58
        scene.addChild (conn2);
59
60
        LabelWidget label2 = new LabelWidget (scene, "Control Point Cut Distance = 0");
61
        conn2.addChild (label2);
62
        conn2.setConstraint (label2, LayoutFactory.ConnectionWidgetLayoutAlignment.BOTTOM_RIGHT, 0);
63
        
64
        SceneSupport.show (scene);
65
    }
66
67
}
(-)graph/lib/apichanges.xml (+16 lines)
Lines 299-304 Link Here
299
            <class package="org.netbeans.api.visual.layout" name="LayoutFactory" link="yes"/>
299
            <class package="org.netbeans.api.visual.layout" name="LayoutFactory" link="yes"/>
300
            <issue number="105390"/>
300
            <issue number="105390"/>
301
        </change>
301
        </change>
302
303
        <change>
304
            <api name="general"/>
305
            <summary>ConnectionWidget.controlPointCutDistance property introduced to render smoother corners of the path</summary>
306
            <version major="2" minor="5"/>
307
            <date day="13" month="6" year="2007"/>
308
            <author login="dkaspar"/>
309
            <compatibility addition="yes"/>
310
            <description>
311
                ConnectionWidget.controlPointCutDistance property allows you to specify a distance where the path should be cut
312
                at each control point.
313
		See test.widget.ConnectionWidgetCutDistanceTest for example.
314
            </description>
315
            <class package="org.netbeans.api.visual.widget" name="ConnectionWidget" link="yes"/>
316
            <issue number="106508"/>
317
        </change>
302
    </changes>
318
    </changes>
303
319
304
    <htmlcontents>
320
    <htmlcontents>
(-)graph/lib/src/org/netbeans/api/visual/widget/ConnectionWidget.java (-7 / +80 lines)
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 {
(-)graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html (+6 lines)
Lines 1145-1150 Link Here
1145
<p>
1145
<p>
1146
There is a <code>controlPointsCursor</code> property which defines a mouse cursor when the mouse is over a visible control point.
1146
There is a <code>controlPointsCursor</code> property which defines a mouse cursor when the mouse is over a visible control point.
1147
1147
1148
<p>
1149
There is a <code>controlPointCutDistance</code> property. If set to positive number (by default 0), then the connection path is cut at each control point to make smoother corners. The smooth corners are not used during calculation whether a mouse-cursor hits the path.
1150
1148
<h3><a name="Router">Router</a></h3>
1151
<h3><a name="Router">Router</a></h3>
1149
1152
1150
<p>
1153
<p>
Lines 1198-1203 Link Here
1198
<tr>
1201
<tr>
1199
<td>getEndPointShape<br>setEndPointShape
1202
<td>getEndPointShape<br>setEndPointShape
1200
<td>Controls a shape of end points (source and target). Shape is defined by <code>PointShape</code> interface. The end points are painted only if <code>isPaintControlPoints</code> returns true.
1203
<td>Controls a shape of end points (source and target). Shape is defined by <code>PointShape</code> interface. The end points are painted only if <code>isPaintControlPoints</code> returns true.
1204
<tr>
1205
<td>getControlPointCutDistance<br>setControlPointCutDistance
1206
<td>Controls a cut distance where the line cut with half-angle line at every control point. See <code>test.widget.ConnectionWidgetCutDistanceTest</code> example.
1201
<tr>
1207
<tr>
1202
<td>getRouter<br>setRouter
1208
<td>getRouter<br>setRouter
1203
<td>Controls a router assigned to the connection widget. The routers is calculating a path and sets a new one using <code>setControlPoints</code> method.
1209
<td>Controls a router assigned to the connection widget. The routers is calculating a path and sets a new one using <code>setControlPoints</code> method.
(-)graph/www/documentation.html (+1 lines)
Lines 179-184 Link Here
179
<li><strong>test.vmd.VMDCollisionTest</strong> - test of <code>WidgetCollisionCollector</code>
179
<li><strong>test.vmd.VMDCollisionTest</strong> - test of <code>WidgetCollisionCollector</code>
180
<li><strong>test.vmd.VMDTest</strong> - how to use <strong>VMD</strong> plug-in
180
<li><strong>test.vmd.VMDTest</strong> - how to use <strong>VMD</strong> plug-in
181
<li><strong>test.widget.AnimatedImageTest</strong> - test of animated image in ImageWidget
181
<li><strong>test.widget.AnimatedImageTest</strong> - test of animated image in ImageWidget
182
<li><strong>test.widget.ConnectionWidgetCutDistanceTest</strong> - how to use control point cut distance in <code>ConnectionWidget</code>
182
<li><strong>test.zoom.CenteredZoomTest</strong> - how to use <code>CenteredZoomAction</code>
183
<li><strong>test.zoom.CenteredZoomTest</strong> - how to use <code>CenteredZoomAction</code>
183
<li><strong>test.zoom.FitToViewTest</strong> - how to implement fit-to-view feature
184
<li><strong>test.zoom.FitToViewTest</strong> - how to implement fit-to-view feature
184
<li><strong>test.zoom.MouseCenteredZoomTest</strong> - how to use <code>MouseCenteredZoomAction</code>
185
<li><strong>test.zoom.MouseCenteredZoomTest</strong> - how to use <code>MouseCenteredZoomAction</code>

Return to bug 106508