1
28
29 package demo.layout.withoutview;
30
31 import java.util.HashMap;
32 import java.awt.EventQueue;
33
34 import y.base.DataMap;
35 import y.geom.YPoint;
36 import y.layout.*;
37 import y.layout.DefaultLayoutGraph;
38 import y.layout.BufferedLayouter;
39 import y.util.D;
40 import y.base.Edge;
41 import y.base.EdgeMap;
42 import y.base.Node;
43 import y.layout.PortConstraint;
44 import y.layout.PortConstraintKeys;
45 import y.layout.hierarchic.IncrementalHierarchicLayouter;
46 import y.layout.hierarchic.incremental.IncrementalHintsFactory;
47 import y.util.Maps;
48
49
65 public class IncrementalLayoutWithoutAView
66 {
67
68
71 public static void main(String[] args) {
72 EventQueue.invokeLater(new Runnable() {
73 public void run() {
74 IncrementalLayoutWithoutAView lwv = new IncrementalLayoutWithoutAView();
75 lwv.doit();
76 }
77 });
78 }
79
80
83 public void doit()
84 {
85 DefaultLayoutGraph graph = new DefaultLayoutGraph();
86
87 Node v1 = graph.createNode();
89 graph.setSize(v1,30,30);
90 Node v2 = graph.createNode();
91 graph.setSize(v2,30,30);
92 Node v3 = graph.createNode();
93 graph.setSize(v3,30,30);
94
95 Edge e1 = graph.createEdge(v1,v2);
96 Edge e2 = graph.createEdge(v1,v3);
97
98 EdgeMap spc = graph.createEdgeMap();
100 EdgeMap tpc = graph.createEdgeMap();
101 spc.set(e1, PortConstraint.create(PortConstraint.EAST));
103 tpc.set(e1, PortConstraint.create(PortConstraint.EAST, true));
105 graph.setTargetPointRel(e1, new YPoint(15, -15));
109
110 spc.set(e2, PortConstraint.create(PortConstraint.NORTH));
112 tpc.set(e2, PortConstraint.create(PortConstraint.NORTH));
113
114 graph.addDataProvider(PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, spc);
115 graph.addDataProvider(PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, tpc);
116
117 IncrementalHierarchicLayouter layouter = new IncrementalHierarchicLayouter();
118 layouter.setLayoutMode(IncrementalHierarchicLayouter.LAYOUT_MODE_FROM_SCRATCH);
119
120 new BufferedLayouter(layouter).doLayout(graph);
121
122 LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph));
124 lpp1.createFrame("Hierarchical").setVisible(true);
125
126 D.bug("\n\nGRAPH LAID OUT HIERARCHICALLY FROM SCRATCH");
127 D.bug("v1 center position = " + graph.getCenter(v1));
128 D.bug("v2 center position = " + graph.getCenter(v2));
129 D.bug("v3 center position = " + graph.getCenter(v3));
130 D.bug("e1 path = " + graph.getPath(e1));
131 D.bug("e2 path = " + graph.getPath(e2));
132
133 Node v4 = graph.createNode();
135 graph.setSize(v4,30,30);
136
137 Edge e3 = graph.createEdge(v1,v4);
138 Edge e4 = graph.createEdge(v4,v2);
139
140 IncrementalHintsFactory ihf = layouter.createIncrementalHintsFactory();
141 DataMap map = Maps.createDataMap(new HashMap());
142
143 map.set(v4, ihf.createLayerIncrementallyHint(v4));
144 map.set(e3, ihf.createSequenceIncrementallyHint(e3));
145 map.set(e4, ihf.createSequenceIncrementallyHint(e4));
146
147 graph.addDataProvider(IncrementalHierarchicLayouter.INCREMENTAL_HINTS_DPKEY, map);
148 layouter.setLayoutMode(IncrementalHierarchicLayouter.LAYOUT_MODE_INCREMENTAL);
149
150 new BufferedLayouter(layouter).doLayout(graph);
151
152 LayoutPreviewPanel lpp2 = new LayoutPreviewPanel(graph);
154 lpp2.createFrame("Hierarchical with incrementally added elements").setVisible(true);
155
156 D.bug("\n\nGRAPH AFTER ELEMENTS HAVE BEEN ADDED INCREMENTALLY");
157 D.bug("v1 center position = " + graph.getCenter(v1));
158 D.bug("v2 center position = " + graph.getCenter(v2));
159 D.bug("v3 center position = " + graph.getCenter(v3));
160 D.bug("v4 center position = " + graph.getCenter(v4));
161 D.bug("e1 path = " + graph.getPath(e1));
162 D.bug("e2 path = " + graph.getPath(e2));
163 D.bug("e3 path = " + graph.getPath(e3));
164 D.bug("e4 path = " + graph.getPath(e4));
165 }
166 }
167