Lines 5-11
Link Here
|
5 |
* accompanies this distribution, and is available at |
5 |
* accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: The Chisel Group, University of Victoria |
8 |
* Contributors: |
|
|
9 |
* The Chisel Group, University of Victoria |
10 |
* Mateusz Matela <mateusz.matela@gmail.com> - Adapt snippets to new layout API - https://bugs.eclipse.org/bugs/show_bug.cgi?id=283244 |
9 |
******************************************************************************/ |
11 |
******************************************************************************/ |
10 |
package org.eclipse.zest.tests.swt; |
12 |
package org.eclipse.zest.tests.swt; |
11 |
|
13 |
|
Lines 14-115
Link Here
|
14 |
import org.eclipse.zest.core.widgets.GraphContainer; |
16 |
import org.eclipse.zest.core.widgets.GraphContainer; |
15 |
import org.eclipse.zest.core.widgets.GraphNode; |
17 |
import org.eclipse.zest.core.widgets.GraphNode; |
16 |
import org.eclipse.zest.core.widgets.ZestStyles; |
18 |
import org.eclipse.zest.core.widgets.ZestStyles; |
17 |
import org.eclipse.zest.layouts.LayoutAlgorithm; |
|
|
18 |
import org.eclipse.zest.layouts.LayoutStyles; |
19 |
import org.eclipse.zest.layouts.algorithms.CompositeLayoutAlgorithm; |
20 |
import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm; |
19 |
import org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm; |
21 |
import org.eclipse.zest.layouts.algorithms.HorizontalShift; |
20 |
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm; |
22 |
import org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm; |
|
|
23 |
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm; |
24 |
import org.eclipse.swt.SWT; |
21 |
import org.eclipse.swt.SWT; |
25 |
import org.eclipse.swt.graphics.Image; |
|
|
26 |
import org.eclipse.swt.layout.FillLayout; |
22 |
import org.eclipse.swt.layout.FillLayout; |
27 |
import org.eclipse.swt.widgets.Display; |
23 |
import org.eclipse.swt.widgets.Display; |
28 |
import org.eclipse.swt.widgets.Shell; |
24 |
import org.eclipse.swt.widgets.Shell; |
29 |
|
25 |
|
30 |
public class NestedGraphSnippet { |
26 |
public class NestedGraphSnippet { |
31 |
|
27 |
|
32 |
private static Image image1; |
|
|
33 |
private static Image classImage; |
34 |
|
35 |
public static void createContainer(Graph g) { |
36 |
GraphContainer a = new GraphContainer(g, SWT.NONE, "SomeClass.java", classImage); |
37 |
int r = (int) ((Math.random() * 3) + 1); |
38 |
r = 2; |
39 |
populateContainer(a, g, r, true); |
40 |
for (int i = 0; i < 4; i++) { |
41 |
GraphContainer b = new GraphContainer(g, SWT.NONE, "SomeNestedClass.java", classImage); |
42 |
r = (int) ((Math.random() * 3) + 1); |
43 |
r = 2; |
44 |
populateContainer(b, g, r, false); |
45 |
new GraphConnection(g, SWT.NONE, a, b); |
46 |
for (int j = 0; j < 4; j++) { |
47 |
GraphContainer c = new GraphContainer(g, SWT.NONE, "DefaultAction.java", classImage); |
48 |
r = (int) ((Math.random() * 3) + 1); |
49 |
r = 2; |
50 |
populateContainer(c, g, r, true); |
51 |
new GraphConnection(g, SWT.NONE, b, c); |
52 |
} |
53 |
} |
54 |
} |
55 |
|
56 |
public static void populateContainer(GraphContainer c, Graph g, int number, boolean radial) { |
57 |
GraphNode a = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeClass.java", classImage); |
58 |
for (int i = 0; i < 4; i++) { |
59 |
GraphNode b = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "SomeNestedClass.java", classImage); |
60 |
new GraphConnection(g, SWT.NONE, a, b); |
61 |
for (int j = 0; j < 4; j++) { |
62 |
GraphNode d = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "DefaultAction.java", classImage); |
63 |
new GraphConnection(g, SWT.NONE, b, d); |
64 |
if (number > 2) { |
65 |
for (int k = 0; k < 4; k++) { |
66 |
GraphNode e = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); |
67 |
new GraphConnection(g, SWT.NONE, d, e); |
68 |
if (number > 3) { |
69 |
for (int l = 0; l < 4; l++) { |
70 |
GraphNode f = new GraphNode(c, ZestStyles.NODES_FISHEYE | ZestStyles.NODES_HIDE_TEXT, "LastAction(Hero).java", classImage); |
71 |
new GraphConnection(g, SWT.NONE, e, f); |
72 |
} |
73 |
} |
74 |
} |
75 |
} |
76 |
} |
77 |
} |
78 |
if (number == 1) { |
79 |
c.setScale(0.75); |
80 |
} else if (number == 2) { |
81 |
c.setScale(0.50); |
82 |
} else { |
83 |
c.setScale(0.25); |
84 |
} |
85 |
if (radial) { |
86 |
c.setLayoutAlgorithm(new RadialLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); |
87 |
} else { |
88 |
c.setLayoutAlgorithm(new TreeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); |
89 |
} |
90 |
} |
91 |
|
92 |
/** |
93 |
* @param args |
94 |
*/ |
95 |
public static void main(String[] args) { |
28 |
public static void main(String[] args) { |
96 |
// Create the shell |
29 |
// Create the shell |
97 |
Display d = new Display(); |
30 |
Display d = new Display(); |
98 |
|
|
|
99 |
image1 = new Image(Display.getDefault(), NestedGraphSnippet.class.getResourceAsStream("package_obj.gif")); |
100 |
classImage = new Image(Display.getDefault(), NestedGraphSnippet.class.getResourceAsStream("class_obj.gif")); |
101 |
|
102 |
Shell shell = new Shell(d); |
31 |
Shell shell = new Shell(d); |
103 |
shell.setText("GraphSnippet1"); |
32 |
shell.setText("GraphSnippet1"); |
104 |
shell.setLayout(new FillLayout()); |
33 |
shell.setLayout(new FillLayout()); |
105 |
shell.setSize(500, 800); |
34 |
shell.setSize(400, 400); |
106 |
|
35 |
|
107 |
Graph g = new Graph(shell, SWT.NONE); |
36 |
Graph g = new Graph(shell, SWT.NONE); |
108 |
createContainer(g); |
|
|
109 |
|
37 |
|
110 |
CompositeLayoutAlgorithm compositeLayoutAlgorithm = new CompositeLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING, new LayoutAlgorithm[] { new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), new HorizontalShift(LayoutStyles.NO_LAYOUT_NODE_RESIZING) }); |
38 |
/* Machines */ |
111 |
//g.setLayoutAlgorithm(new GridLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true); |
39 |
GraphContainer machine1 = new GraphContainer(g, SWT.NONE); |
112 |
g.setLayoutAlgorithm(compositeLayoutAlgorithm, true); |
40 |
machine1.setText("Machine 1 (prop:1)"); |
|
|
41 |
GraphContainer machine2 = new GraphContainer(g, SWT.NONE); |
42 |
machine2.setText("Machine 2"); |
43 |
GraphContainer machine3 = new GraphContainer(g, SWT.NONE); |
44 |
machine3.setText("Machine 3"); |
45 |
|
46 |
/* Network */ |
47 |
GraphConnection networkConnection = new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, machine1, machine2); |
48 |
networkConnection.setText("Network (bandwidth:1) "); |
49 |
new GraphConnection(g, SWT.NONE, machine2, machine3); |
50 |
|
51 |
/* Containers */ |
52 |
GraphContainer container1 = new GraphContainer(machine1, SWT.NONE); |
53 |
container1.setText("Host 1"); |
54 |
GraphContainer container2 = new GraphContainer(machine1, SWT.NONE); |
55 |
container2.setText("Host 2"); |
56 |
|
57 |
GraphContainer container3 = new GraphContainer(machine2, SWT.NONE); |
58 |
container3.setText("Host 3"); |
59 |
GraphContainer container4 = new GraphContainer(machine3, SWT.NONE); |
60 |
container4.setText("Host 4"); |
61 |
|
62 |
/* Objects */ |
63 |
GraphNode object1 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object"); |
64 |
GraphNode object2 = new GraphNode(container1, ZestStyles.NODES_FISHEYE, "JSP Object 2"); |
65 |
GraphNode object3 = new GraphNode(container2, ZestStyles.NODES_FISHEYE, "JSP Object 3"); |
66 |
GraphNode object4 = new GraphNode(container3, ZestStyles.NODES_FISHEYE, "JSP Object 4"); |
67 |
GraphNode object5 = new GraphNode(container4, ZestStyles.NODES_FISHEYE, "JSP Object 5"); |
68 |
|
69 |
/* Connections */ |
70 |
new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object1, object2); |
71 |
new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object2, object3); |
72 |
new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object3, object4); |
73 |
new GraphConnection(g, ZestStyles.CONNECTIONS_DIRECTED, object4, object5); |
74 |
|
75 |
container1.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); |
76 |
container2.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); |
77 |
container3.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); |
78 |
container3.setLayoutAlgorithm(new GridLayoutAlgorithm(), true); |
79 |
g.setLayoutAlgorithm(new SpringLayoutAlgorithm(), true); |
113 |
|
80 |
|
114 |
shell.open(); |
81 |
shell.open(); |
115 |
while (!shell.isDisposed()) { |
82 |
while (!shell.isDisposed()) { |
Lines 117-122
Link Here
|
117 |
d.sleep(); |
84 |
d.sleep(); |
118 |
} |
85 |
} |
119 |
} |
86 |
} |
120 |
image1.dispose(); |
|
|
121 |
} |
87 |
} |
122 |
} |
88 |
} |