~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to graph/examples/src/test/router/OSRComputeControlPointsTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2007 Sun
 
17
 * Microsystems, Inc. All Rights Reserved.
 
18
 */
 
19
package test.router;
 
20
 
 
21
import org.netbeans.api.visual.action.ActionFactory;
 
22
import org.netbeans.api.visual.anchor.Anchor;
 
23
import org.netbeans.api.visual.router.Router;
 
24
import org.netbeans.api.visual.router.RouterFactory;
 
25
import org.netbeans.api.visual.widget.ConnectionWidget;
 
26
import org.netbeans.api.visual.widget.LayerWidget;
 
27
import org.netbeans.api.visual.widget.Scene;
 
28
import test.SceneSupport;
 
29
 
 
30
import java.awt.*;
 
31
 
 
32
/**
 
33
 * This test describes issue #96460. It should route the connection correctly. The bug happens when the connection is router as directly (not orthogonally).
 
34
 * 
 
35
 * @author David Kaspar
 
36
 */
 
37
public class OSRComputeControlPointsTest {
 
38
 
 
39
    public static void main (String[] args) {
 
40
        Scene scene = new Scene ();
 
41
        scene.getActions ().addAction (ActionFactory.createZoomAction (2.0, false));
 
42
        scene.getActions ().addAction (ActionFactory.createPanAction ());
 
43
 
 
44
        LayerWidget connectionLayer = new LayerWidget (scene);
 
45
        scene.addChild (connectionLayer);
 
46
 
 
47
        Router router = RouterFactory.createOrthogonalSearchRouter (connectionLayer);
 
48
 
 
49
        ConnectionWidget conn1 = new ConnectionWidget (scene);
 
50
        conn1.setForeground (new Color (0, 255, 0, 128));
 
51
        conn1.setSourceAnchor (new DirAnchor (new Point (100, 200), Anchor.Direction.LEFT));
 
52
        conn1.setTargetAnchor (new DirAnchor (new Point (400, 300), Anchor.Direction.RIGHT));
 
53
        conn1.setRouter (router);
 
54
        connectionLayer.addChild (conn1);
 
55
 
 
56
        ConnectionWidget conn3 = new ConnectionWidget (scene);
 
57
        conn3.setForeground (new Color (0, 0, 255, 128));
 
58
        conn3.setSourceAnchor (new DirAnchor (new Point (100, 300), Anchor.Direction.LEFT));
 
59
        conn3.setTargetAnchor (new DirAnchor (new Point (400, 200), Anchor.Direction.RIGHT));
 
60
        conn3.setRouter (router);
 
61
        connectionLayer.addChild (conn3);
 
62
 
 
63
        SceneSupport.show (scene);
 
64
    }
 
65
 
 
66
    static class DirAnchor extends Anchor {
 
67
 
 
68
        private Point location;
 
69
        private Direction direction;
 
70
 
 
71
        public DirAnchor (Point location, Direction direction) {
 
72
            super (null);
 
73
            this.location = location;
 
74
            this.direction = direction;
 
75
        }
 
76
 
 
77
        public Point getRelatedSceneLocation () {
 
78
            return location;
 
79
        }
 
80
 
 
81
        public Result compute (Entry entry) {
 
82
            return new Result (location, direction);
 
83
        }
 
84
 
 
85
    }
 
86
 
 
87
}