1
28
29 package demo.layout.withoutview;
30
31 import y.base.Edge;
32 import y.base.EdgeMap;
33 import y.base.Node;
34 import y.base.NodeMap;
35
36 import y.layout.BufferedLayouter;
37 import y.layout.DefaultLayoutGraph;
38 import y.layout.PortConstraintKeys;
39 import y.layout.grouping.Grouping;
40 import y.layout.hierarchic.HierarchicGroupLayouter;
41
42 import y.util.D;
43
44 import java.awt.EventQueue;
45
46
56 public class GroupingLayoutWithoutAView
57 {
58
59
62 public static void main(String[] args) {
63 EventQueue.invokeLater(new Runnable() {
64 public void run() {
65 GroupingLayoutWithoutAView lwv = new GroupingLayoutWithoutAView();
66 lwv.doit();
67 }
68 });
69 }
70
71
77 public void doit()
78 {
79 DefaultLayoutGraph graph = new DefaultLayoutGraph();
80
81 Node v1 = graph.createNode();
83 graph.setSize(v1,30,30);
84 Node v2 = graph.createNode();
85 graph.setSize(v2,30,30);
86 Node v3 = graph.createNode();
87 graph.setSize(v3,30,30);
88 Node v4 = graph.createNode();
89 graph.setSize(v4,30,30);
90
91 Node groupNode = graph.createNode();
92 graph.setSize(groupNode, 100,100);
93
94 Edge e1 = graph.createEdge(v1,v2);
95 Edge e2 = graph.createEdge(v4, groupNode);
96 Edge e3 = graph.createEdge(v1,v3);
97 Edge e4 = graph.createEdge(v1, v1);
98 Edge e5 = graph.createEdge(v2, groupNode);
99 Edge e6 = graph.createEdge(groupNode, v2);
100
101 EdgeMap spg = graph.createEdgeMap();
103 EdgeMap tpg = graph.createEdgeMap();
104
105 graph.addDataProvider(PortConstraintKeys.SOURCE_GROUPID_KEY, spg);
106 graph.addDataProvider(PortConstraintKeys.TARGET_GROUPID_KEY, tpg);
107
108 spg.set(e1, "SGroup1");
109 spg.set(e3, "SGroup1");
110 tpg.set(e1, "TGroup1");
111 tpg.set(e3, "TGroup1");
112
113 NodeMap nodeId = graph.createNodeMap();
115 NodeMap parentNodeId = graph.createNodeMap();
116 NodeMap groupKey = graph.createNodeMap();
117
118 graph.addDataProvider(Grouping.NODE_ID_DPKEY, nodeId);
119 graph.addDataProvider(Grouping.PARENT_NODE_ID_DPKEY, parentNodeId);
120 graph.addDataProvider(Grouping.GROUP_DPKEY, groupKey);
121
122 groupKey.setBool(groupNode, true);
124
125 nodeId.set(v1, "v1");
127 nodeId.set(v2, "v2");
128 nodeId.set(v3, "v3");
129 nodeId.set(v4, "v4");
130 nodeId.set(groupNode, "groupNode");
131
132 parentNodeId.set(v2, "groupNode");
134 parentNodeId.set(v3, "groupNode");
135
136 HierarchicGroupLayouter layouter = new HierarchicGroupLayouter();
137
138 layouter.setMinimalLayerDistance(0.0d);
139 layouter.setMinimalEdgeDistance(10.0d);
140
141 new BufferedLayouter(layouter).doLayout(graph);
142
143 LayoutPreviewPanel lpp = new LayoutPreviewPanel(graph);
145 lpp.createFrame("Hierarchical Group Layout").setVisible(true);
146
147 D.bug("\n\nGRAPH LAID OUT USING HIERACHIC GROUP LAYOUT");
148 D.bug("v1 center position = " + graph.getCenter(v1));
149 D.bug("v2 center position = " + graph.getCenter(v2));
150 D.bug("v3 center position = " + graph.getCenter(v3));
151 D.bug("v4 center position = " + graph.getCenter(v4));
152 D.bug("group center position = " + graph.getCenter(groupNode));
153 D.bug("group size = " + graph.getSize(groupNode));
154 D.bug("e1 path = " + graph.getPath(e1));
155 D.bug("e2 path = " + graph.getPath(e2));
156 D.bug("e3 path = " + graph.getPath(e3));
157 D.bug("e4 path = " + graph.getPath(e4));
158 D.bug("e5 path = " + graph.getPath(e5));
159 D.bug("e6 path = " + graph.getPath(e4));
160 }
161 }
162