1
14
15 package demo.layout.withoutview;
16
17 import java.util.HashMap;
18 import java.awt.EventQueue;
19
20 import y.base.DataMap;
21 import y.geom.YPoint;
22 import y.layout.*;
23 import y.layout.DefaultLayoutGraph;
24 import y.layout.BufferedLayouter;
25 import y.util.D;
26 import y.base.Edge;
27 import y.base.EdgeMap;
28 import y.base.Node;
29 import y.layout.PortConstraint;
30 import y.layout.PortConstraintKeys;
31 import y.layout.hierarchic.IncrementalHierarchicLayouter;
32 import y.layout.hierarchic.incremental.IncrementalHintsFactory;
33 import y.util.Maps;
34
35
51 public class IncrementalLayoutWithoutAView
52 {
53
54
57 public static void main(String[] args) {
58 EventQueue.invokeLater(new Runnable() {
59 public void run() {
60 IncrementalLayoutWithoutAView lwv = new IncrementalLayoutWithoutAView();
61 lwv.doit();
62 }
63 });
64 }
65
66
69 public void doit()
70 {
71 DefaultLayoutGraph graph = new DefaultLayoutGraph();
72
73 Node v1 = graph.createNode();
75 graph.setSize(v1,30,30);
76 Node v2 = graph.createNode();
77 graph.setSize(v2,30,30);
78 Node v3 = graph.createNode();
79 graph.setSize(v3,30,30);
80
81 Edge e1 = graph.createEdge(v1,v2);
82 Edge e2 = graph.createEdge(v1,v3);
83
84 EdgeMap spc = graph.createEdgeMap();
86 EdgeMap tpc = graph.createEdgeMap();
87 spc.set(e1, PortConstraint.create(PortConstraint.EAST));
89 tpc.set(e1, PortConstraint.create(PortConstraint.EAST, true));
91 graph.setTargetPointRel(e1, new YPoint(15, -15));
95
96 spc.set(e2, PortConstraint.create(PortConstraint.NORTH));
98 tpc.set(e2, PortConstraint.create(PortConstraint.NORTH));
99
100 graph.addDataProvider(PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, spc);
101 graph.addDataProvider(PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, tpc);
102
103 IncrementalHierarchicLayouter layouter = new IncrementalHierarchicLayouter();
104 layouter.setLayoutMode(IncrementalHierarchicLayouter.LAYOUT_MODE_FROM_SCRATCH);
105
106 new BufferedLayouter(layouter).doLayout(graph);
107
108 LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph));
110 lpp1.createFrame("Hierarchical").setVisible(true);
111
112 D.bug("\n\nGRAPH LAID OUT HIERARCHICALLY FROM SCRATCH");
113 D.bug("v1 center position = " + graph.getCenter(v1));
114 D.bug("v2 center position = " + graph.getCenter(v2));
115 D.bug("v3 center position = " + graph.getCenter(v3));
116 D.bug("e1 path = " + graph.getPath(e1));
117 D.bug("e2 path = " + graph.getPath(e2));
118
119 Node v4 = graph.createNode();
121 graph.setSize(v4,30,30);
122
123 Edge e3 = graph.createEdge(v1,v4);
124 Edge e4 = graph.createEdge(v4,v2);
125
126 IncrementalHintsFactory ihf = layouter.createIncrementalHintsFactory();
127 DataMap map = Maps.createDataMap(new HashMap());
128
129 map.set(v4, ihf.createLayerIncrementallyHint(v4));
130 map.set(e3, ihf.createSequenceIncrementallyHint(e3));
131 map.set(e4, ihf.createSequenceIncrementallyHint(e4));
132
133 graph.addDataProvider(IncrementalHierarchicLayouter.INCREMENTAL_HINTS_DPKEY, map);
134 layouter.setLayoutMode(IncrementalHierarchicLayouter.LAYOUT_MODE_INCREMENTAL);
135
136 new BufferedLayouter(layouter).doLayout(graph);
137
138 LayoutPreviewPanel lpp2 = new LayoutPreviewPanel(graph);
140 lpp2.createFrame("Hierarchical with incrementally added elements").setVisible(true);
141
142 D.bug("\n\nGRAPH AFTER ELEMENTS HAVE BEEN ADDED INCREMENTALLY");
143 D.bug("v1 center position = " + graph.getCenter(v1));
144 D.bug("v2 center position = " + graph.getCenter(v2));
145 D.bug("v3 center position = " + graph.getCenter(v3));
146 D.bug("v4 center position = " + graph.getCenter(v4));
147 D.bug("e1 path = " + graph.getPath(e1));
148 D.bug("e2 path = " + graph.getPath(e2));
149 D.bug("e3 path = " + graph.getPath(e3));
150 D.bug("e4 path = " + graph.getPath(e4));
151 }
152 }
153