1
14
15 package demo.layout.withoutview;
16
17 import y.base.Edge;
18 import y.base.EdgeMap;
19 import y.base.Node;
20 import y.base.NodeMap;
21
22 import y.layout.BufferedLayouter;
23 import y.layout.DefaultLayoutGraph;
24 import y.layout.PortConstraintKeys;
25 import y.layout.grouping.Grouping;
26 import y.layout.hierarchic.HierarchicGroupLayouter;
27
28 import y.util.D;
29
30 import java.awt.EventQueue;
31
32
42 public class GroupingLayoutWithoutAView
43 {
44
45
48 public static void main(String[] args) {
49 EventQueue.invokeLater(new Runnable() {
50 public void run() {
51 GroupingLayoutWithoutAView lwv = new GroupingLayoutWithoutAView();
52 lwv.doit();
53 }
54 });
55 }
56
57
63 public void doit()
64 {
65 DefaultLayoutGraph graph = new DefaultLayoutGraph();
66
67 Node v1 = graph.createNode();
69 graph.setSize(v1,30,30);
70 Node v2 = graph.createNode();
71 graph.setSize(v2,30,30);
72 Node v3 = graph.createNode();
73 graph.setSize(v3,30,30);
74 Node v4 = graph.createNode();
75 graph.setSize(v4,30,30);
76
77 Node groupNode = graph.createNode();
78 graph.setSize(groupNode, 100,100);
79
80 Edge e1 = graph.createEdge(v1,v2);
81 Edge e2 = graph.createEdge(v4, groupNode);
82 Edge e3 = graph.createEdge(v1,v3);
83 Edge e4 = graph.createEdge(v1, v1);
84 Edge e5 = graph.createEdge(v2, groupNode);
85 Edge e6 = graph.createEdge(groupNode, v2);
86
87 EdgeMap spg = graph.createEdgeMap();
89 EdgeMap tpg = graph.createEdgeMap();
90
91 graph.addDataProvider(PortConstraintKeys.SOURCE_GROUPID_KEY, spg);
92 graph.addDataProvider(PortConstraintKeys.TARGET_GROUPID_KEY, tpg);
93
94 spg.set(e1, "SGroup1");
95 spg.set(e3, "SGroup1");
96 tpg.set(e1, "TGroup1");
97 tpg.set(e3, "TGroup1");
98
99 NodeMap nodeId = graph.createNodeMap();
101 NodeMap parentNodeId = graph.createNodeMap();
102 NodeMap groupKey = graph.createNodeMap();
103
104 graph.addDataProvider(Grouping.NODE_ID_DPKEY, nodeId);
105 graph.addDataProvider(Grouping.PARENT_NODE_ID_DPKEY, parentNodeId);
106 graph.addDataProvider(Grouping.GROUP_DPKEY, groupKey);
107
108 groupKey.setBool(groupNode, true);
110
111 nodeId.set(v1, "v1");
113 nodeId.set(v2, "v2");
114 nodeId.set(v3, "v3");
115 nodeId.set(v4, "v4");
116 nodeId.set(groupNode, "groupNode");
117
118 parentNodeId.set(v2, "groupNode");
120 parentNodeId.set(v3, "groupNode");
121
122 HierarchicGroupLayouter layouter = new HierarchicGroupLayouter();
123
124 layouter.setMinimalLayerDistance(0.0d);
125 layouter.setMinimalEdgeDistance(10.0d);
126
127 new BufferedLayouter(layouter).doLayout(graph);
128
129 LayoutPreviewPanel lpp = new LayoutPreviewPanel(graph);
131 lpp.createFrame("Hierarchical Group Layout").setVisible(true);
132
133 D.bug("\n\nGRAPH LAID OUT USING HIERACHIC GROUP LAYOUT");
134 D.bug("v1 center position = " + graph.getCenter(v1));
135 D.bug("v2 center position = " + graph.getCenter(v2));
136 D.bug("v3 center position = " + graph.getCenter(v3));
137 D.bug("v4 center position = " + graph.getCenter(v4));
138 D.bug("group center position = " + graph.getCenter(groupNode));
139 D.bug("group size = " + graph.getSize(groupNode));
140 D.bug("e1 path = " + graph.getPath(e1));
141 D.bug("e2 path = " + graph.getPath(e2));
142 D.bug("e3 path = " + graph.getPath(e3));
143 D.bug("e4 path = " + graph.getPath(e4));
144 D.bug("e5 path = " + graph.getPath(e5));
145 D.bug("e6 path = " + graph.getPath(e4));
146 }
147 }
148