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-2007 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
19 |
|
20 |
package test.routing; |
21 |
|
22 |
import org.netbeans.api.visual.action.ActionFactory; |
23 |
import org.netbeans.api.visual.anchor.AnchorFactory; |
24 |
import org.netbeans.api.visual.anchor.AnchorShape; |
25 |
import org.netbeans.api.visual.anchor.PointShape; |
26 |
import org.netbeans.api.visual.border.BorderFactory; |
27 |
import org.netbeans.api.visual.router.RouterFactory; |
28 |
import org.netbeans.api.visual.widget.*; |
29 |
import test.SceneSupport; |
30 |
|
31 |
import javax.swing.*; |
32 |
import java.awt.*; |
33 |
import java.awt.event.ActionEvent; |
34 |
|
35 |
/** |
36 |
* @author David Kaspar |
37 |
*/ |
38 |
public class RoutingPolicyTest extends Scene { |
39 |
|
40 |
private LayerWidget mainLayer; |
41 |
private ConnectionWidget connection; |
42 |
|
43 |
public RoutingPolicyTest () { |
44 |
mainLayer = new LayerWidget (this); |
45 |
addChild (mainLayer); |
46 |
LayerWidget connLayer = new LayerWidget (this); |
47 |
addChild (connLayer); |
48 |
|
49 |
createLabel ("Buttons in toolbar", 200, 100, Color.YELLOW); |
50 |
createLabel ("allows you to switch", 200, 130, Color.YELLOW); |
51 |
createLabel ("routing policy of the connection widget.", 200, 160, Color.YELLOW); |
52 |
|
53 |
createLabel ("Try double-clicking on the connection widget.", 200, 250, Color.CYAN); |
54 |
createLabel ("Try dragging control points of the connection widget.", 200, 280, Color.CYAN); |
55 |
createLabel ("Try force re-routing of the connection widget.", 200, 310, Color.CYAN); |
56 |
|
57 |
Widget source = createLabel ("Source", 50, 200, Color.GREEN); |
58 |
Widget target = createLabel ("Target", 450, 200, Color.GREEN); |
59 |
|
60 |
connection = new ConnectionWidget (this); |
61 |
connection.setSourceAnchor (AnchorFactory.createDirectionalAnchor (source, AnchorFactory.DirectionalAnchorKind.HORIZONTAL)); |
62 |
connection.setTargetAnchor (AnchorFactory.createDirectionalAnchor (target, AnchorFactory.DirectionalAnchorKind.HORIZONTAL)); |
63 |
connection.setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED); |
64 |
connection.setPaintControlPoints (true); |
65 |
connection.setControlPointShape (PointShape.SQUARE_FILLED_BIG); |
66 |
connection.setRouter (RouterFactory.createOrthogonalSearchRouter (mainLayer)); |
67 |
connection.getActions ().addAction (ActionFactory.createAddRemoveControlPointAction ()); |
68 |
connection.getActions ().addAction (ActionFactory.createFreeMoveControlPointAction ()); |
69 |
connLayer.addChild (connection); |
70 |
} |
71 |
|
72 |
private Widget createLabel (String text, int x, int y, Color color) { |
73 |
LabelWidget label = new LabelWidget (this, text); |
74 |
label.setOpaque (true); |
75 |
label.setBackground (color); |
76 |
label.setBorder (BorderFactory.createLineBorder (5)); |
77 |
label.setPreferredLocation (new Point (x, y)); |
78 |
label.getActions ().addAction (ActionFactory.createMoveAction ()); |
79 |
mainLayer.addChild (label); |
80 |
return label; |
81 |
} |
82 |
|
83 |
private JComponent createPanel () { |
84 |
JPanel panel = new JPanel (); |
85 |
panel.setLayout (new BorderLayout ()); |
86 |
|
87 |
JToolBar bar = new JToolBar (); |
88 |
bar.add (new AbstractAction("Force Rerouting") { |
89 |
public void actionPerformed (ActionEvent e) { |
90 |
connection.reroute (); |
91 |
validate (); |
92 |
} |
93 |
}); |
94 |
bar.addSeparator (); |
95 |
bar.add (new JLabel ("Switch routing policy:")); |
96 |
bar.add (new AbstractAction("Always Route") { |
97 |
public void actionPerformed (ActionEvent e) { |
98 |
connection.setRoutingPolicy (ConnectionWidget.RoutingPolicy.ALWAYS_ROUTE); |
99 |
validate (); |
100 |
} |
101 |
}); |
102 |
bar.add (new AbstractAction("Update End Points Only") { |
103 |
public void actionPerformed (ActionEvent e) { |
104 |
connection.setRoutingPolicy (ConnectionWidget.RoutingPolicy.UPDATE_END_POINTS_ONLY); |
105 |
validate (); |
106 |
} |
107 |
}); |
108 |
bar.add (new AbstractAction("Disable Routing Until End Point is Moved") { |
109 |
public void actionPerformed (ActionEvent e) { |
110 |
connection.setRoutingPolicy (ConnectionWidget.RoutingPolicy.DISABLE_ROUTING_UNTIL_END_POINT_IS_MOVED); |
111 |
validate (); |
112 |
} |
113 |
}); |
114 |
bar.add (new AbstractAction("Disable Routing") { |
115 |
public void actionPerformed (ActionEvent e) { |
116 |
connection.setRoutingPolicy (ConnectionWidget.RoutingPolicy.DISABLE_ROUTING); |
117 |
validate (); |
118 |
} |
119 |
}); |
120 |
panel.add (bar, BorderLayout.NORTH); |
121 |
|
122 |
panel.add (createView (), BorderLayout.CENTER); |
123 |
return panel; |
124 |
} |
125 |
|
126 |
public static void main (String[] args) { |
127 |
SceneSupport.show (new RoutingPolicyTest ().createPanel ()); |
128 |
} |
129 |
|
130 |
} |