1
28
29 package demo.layout.withoutview;
30
31 import y.geom.YRectangle;
32 import y.geom.YPoint;
33 import y.geom.OrientedRectangle;
34 import y.layout.*;
35 import y.layout.DefaultLayoutGraph;
36 import y.layout.EdgeLabelModel;
37 import y.layout.LayoutGraph;
38 import y.layout.EdgeLabelLayout;
39 import y.layout.FreeEdgeLabelModel;
40 import y.layout.BufferedLayouter;
41 import y.layout.SliderEdgeLabelModel;
42 import y.layout.EdgeLabelLayoutImpl;
43 import y.layout.hierarchic.IncrementalHierarchicLayouter;
44 import y.layout.labeling.GreedyMISLabeling;
45 import y.util.D;
46 import y.base.Edge;
47 import y.base.EdgeMap;
48 import y.base.Node;
49 import y.layout.PortConstraint;
50 import y.layout.PortConstraintKeys;
51
52 import java.awt.EventQueue;
53
54
75 public class LayoutWithoutAView
76 {
77
78
81 public static void main(String[] args) {
82 EventQueue.invokeLater(new Runnable() {
83 public void run() {
84 LayoutWithoutAView lwv = new LayoutWithoutAView();
85 lwv.doit();
86 }
87 });
88 }
89
90
98 public void doit()
99 {
100 DefaultLayoutGraph graph = new DefaultLayoutGraph();
101
102 Node v1 = graph.createNode();
104 graph.setSize(v1,30,30);
105 Node v2 = graph.createNode();
106 graph.setSize(v2,30,30);
107 Node v3 = graph.createNode();
108 graph.setSize(v3,30,30);
109
110 Edge e1 = graph.createEdge(v1,v2);
111 Edge e2 = graph.createEdge(v2,v3);
112 Edge e3 = graph.createEdge(v1,v3);
113
114 EdgeMap spc = graph.createEdgeMap();
116 EdgeMap tpc = graph.createEdgeMap();
117 spc.set(e1, PortConstraint.create(PortConstraint.EAST));
119 tpc.set(e1, PortConstraint.create(PortConstraint.EAST, true));
121 graph.setTargetPointRel(e1, new YPoint(15, -15));
125
126 spc.set(e2, PortConstraint.create(PortConstraint.NORTH));
128 tpc.set(e2, PortConstraint.create(PortConstraint.NORTH));
129 graph.addDataProvider(PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, spc);
131 graph.addDataProvider(PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, tpc);
132
133
134 EdgeLabelLayoutImpl ell1 = new EdgeLabelLayoutImpl();
139 ell1.setBox(new YRectangle(0,0,80,20));
140 ell1.setEdgeLabelModel(new SliderEdgeLabelModel(SliderEdgeLabelModel.CENTER_SLIDER));
143
144 EdgeLabelLayoutImpl ell2 = new EdgeLabelLayoutImpl();
145 ell2.setBox(new YRectangle(0,0,80,20));
146 ell2.setEdgeLabelModel(new SliderEdgeLabelModel(SliderEdgeLabelModel.SIDE_SLIDER));
149
150 EdgeLabelLayout[] ells = new EdgeLabelLayout[]{ell1, ell2};
151 graph.setLabelLayout(e1, ells);
152
153 IncrementalHierarchicLayouter layouter = new IncrementalHierarchicLayouter();
154 layouter.setLabelLayouterEnabled(true);
155 layouter.setLabelLayouter(new GreedyMISLabeling());
156
157 new BufferedLayouter(layouter).doLayout(graph);
158
159 LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph));
161 lpp1.createFrame("Hierarchical with general edge labeling").setVisible(true);
162
163 D.bug("\n\nGRAPH LAID OUT USING GENERAL EDGE LABELING");
164 D.bug("v1 center position = " + graph.getCenter(v1));
165 D.bug("v2 center position = " + graph.getCenter(v2));
166 D.bug("v3 center position = " + graph.getCenter(v3));
167 D.bug("e1 path = " + graph.getPath(e1));
168 D.bug("e2 path = " + graph.getPath(e2));
169 D.bug("e3 path = " + graph.getPath(e3));
170 D.bug("ell1 upper left location = " + getEdgeLabelLocation(graph,e1,ell1).getBoundingBox().getLocation());
171 D.bug("ell2 upper left location = " + getEdgeLabelLocation(graph,e1,ell2).getBoundingBox().getLocation());
172
173 EdgeLabelModel freeModel = new FreeEdgeLabelModel();
174 ell1.setEdgeLabelModel(freeModel);
175 ell1.setModelParameter(freeModel.getDefaultParameter());
176 ell2.setEdgeLabelModel(freeModel);
177 ell2.setModelParameter(freeModel.getDefaultParameter());
178
179 layouter = new IncrementalHierarchicLayouter();
180 layouter.setIntegratedEdgeLabelingEnabled(true);
181
182 new BufferedLayouter(layouter).doLayout(graph);
183
184 LayoutPreviewPanel lpp2 = new LayoutPreviewPanel(graph);
186 lpp2.createFrame("Hierarchical with internal labeling").setVisible(true);
187
188 D.bug("\n\nGRAPH LAID OUT USING HIERARCHIC LAYOUTER WITH INTERNAL EDGE LABELING");
189 D.bug("v1 center position = " + graph.getCenter(v1));
190 D.bug("v2 center position = " + graph.getCenter(v2));
191 D.bug("v3 center position = " + graph.getCenter(v3));
192 D.bug("e1 path = " + graph.getPath(e1));
193 D.bug("e2 path = " + graph.getPath(e2));
194 D.bug("e3 path = " + graph.getPath(e3));
195 D.bug("ell1 upper left location = " + getEdgeLabelLocation(graph,e1,ell1).getBoundingBox().getLocation());
196 D.bug("ell2 upper left location = " + getEdgeLabelLocation(graph,e1,ell2).getBoundingBox().getLocation());
197 }
198
199
202 OrientedRectangle getEdgeLabelLocation(LayoutGraph graph, Edge e, EdgeLabelLayout ell)
203 {
204 OrientedRectangle orientedRectangle = ell.getLabelModel().getLabelPlacement(
205 ell.getOrientedBox().getSize(),
206 graph.getEdgeLayout(e),
207 graph.getNodeLayout(e.source()),
208 graph.getNodeLayout(e.target()),
209 ell.getModelParameter());
210 return orientedRectangle;
211 }
212 }
213