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.
6
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
* or http://www.netbeans.org/cddl.txt.
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]"
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.
21
import org.netbeans.api.visual.graph.GraphScene;
22
import org.netbeans.api.visual.widget.Widget;
23
import org.netbeans.api.visual.widget.LabelWidget;
24
import org.netbeans.api.visual.widget.LayerWidget;
25
import org.netbeans.api.visual.widget.ConnectionWidget;
26
import org.netbeans.api.visual.anchor.AnchorShape;
27
import org.netbeans.api.visual.anchor.Anchor;
28
import org.netbeans.api.visual.vmd.VMDNodeAnchor;
29
import org.netbeans.api.visual.router.RouterFactory;
30
import org.netbeans.api.visual.router.Router;
31
import org.netbeans.api.visual.action.ActionFactory;
32
import org.netbeans.api.visual.action.WidgetAction;
33
import test.SceneSupport;
36
import java.util.HashMap;
39
* @author David Kaspar
41
public class LoopEdgeTest extends GraphScene.StringGraph {
43
private LayerWidget mainLayer;
44
private LayerWidget connectionLayer;
45
private Router router;
46
private WidgetAction moveAction;
47
private HashMap<String, Anchor> anchors;
49
public LoopEdgeTest () {
50
mainLayer = new LayerWidget (this);
52
connectionLayer = new LayerWidget (this);
53
addChild (connectionLayer);
54
router = RouterFactory.createOrthogonalSearchRouter (mainLayer, connectionLayer);
55
moveAction = ActionFactory.createMoveAction ();
56
anchors = new HashMap<String, Anchor> ();
59
public static void main (String[] args) {
60
LoopEdgeTest scene = new LoopEdgeTest ();
64
scene.setEdgeSource ("e1", "n1");
65
scene.setEdgeTarget ("e1", "n1");
67
SceneSupport.show (scene);
70
protected Widget attachNodeWidget (String node) {
71
LabelWidget widget = new LabelWidget (this, "| " + node + " |");
72
widget.setOpaque (true);
73
widget.setBackground (Color.YELLOW);
74
widget.setPreferredLocation (new Point (100, 100));
75
widget.getActions ().addAction (moveAction);
76
mainLayer.addChild (widget);
77
anchors.put (node, new VMDNodeAnchor (widget));
81
protected void detachNodeWidget (String node, Widget widget) {
82
super.detachNodeWidget (node, widget);
83
anchors.remove (node);
86
protected Widget attachEdgeWidget (String edge) {
87
ConnectionWidget widget = new ConnectionWidget (this);
88
widget.setRouter (router);
89
widget.setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED);
90
connectionLayer.addChild (widget);
94
protected void attachEdgeSourceAnchor (String edge, String oldSourceNode, String sourceNode) {
95
((ConnectionWidget) findWidget (edge)).setSourceAnchor (anchors.get (sourceNode));
98
protected void attachEdgeTargetAnchor (String edge, String oldTargetNode, String targetNode) {
99
((ConnectionWidget) findWidget (edge)).setTargetAnchor (anchors.get (targetNode));