1
14
15 package demo.layout;
16
17 import javax.swing.JFrame;
18
19 import y.geom.YRectangle;
20 import y.geom.YPoint;
21 import y.layout.*;
22 import y.layout.DefaultLayoutGraph;
23 import y.layout.EdgeLabelModel;
24 import y.layout.LabelLayoutTranslator;
25 import y.layout.LayoutGraph;
26 import y.layout.EdgeLabelLayout;
27 import y.layout.FreeEdgeLabelModel;
28 import y.layout.BufferedLayouter;
29 import y.layout.SliderEdgeLabelModel;
30 import y.layout.EdgeLabelLayoutImpl;
31 import y.layout.hierarchic.HierarchicLayouter;
32 import y.layout.labeling.GreedyMISLabeling;
33 import y.util.D;
34 import y.base.Edge;
35 import y.base.EdgeMap;
36 import y.base.Node;
37 import y.layout.PortConstraint;
38 import y.layout.PortConstraintKeys;
39
40
58 public class LayoutWithoutAView
59 {
60
61
64 public static void main(String[] args)
65 {
66 LayoutWithoutAView lwv = new LayoutWithoutAView();
67 lwv.doit();
68 }
69
70
78 public void doit()
79 {
80 DefaultLayoutGraph graph = new DefaultLayoutGraph();
81
82 Node v1 = graph.createNode();
84 graph.setSize(v1,30,30);
85 Node v2 = graph.createNode();
86 graph.setSize(v2,30,30);
87 Node v3 = graph.createNode();
88 graph.setSize(v3,30,30);
89
90 Edge e1 = graph.createEdge(v1,v2);
91 Edge e2 = graph.createEdge(v2,v3);
92 Edge e3 = graph.createEdge(v1,v3);
93
94 EdgeMap spc = graph.createEdgeMap();
96 EdgeMap tpc = graph.createEdgeMap();
97 spc.set(e1, PortConstraint.create(PortConstraint.EAST));
99 tpc.set(e1, PortConstraint.create(PortConstraint.EAST, true));
101 graph.setTargetPointRel(e1, new YPoint(15, -15));
105
106 spc.set(e2, PortConstraint.create(PortConstraint.NORTH));
108 tpc.set(e2, PortConstraint.create(PortConstraint.NORTH));
109 graph.addDataProvider(PortConstraintKeys.SOURCE_PORT_CONSTRAINT_KEY, spc);
111 graph.addDataProvider(PortConstraintKeys.TARGET_PORT_CONSTRAINT_KEY, tpc);
112
113
114 EdgeLabelLayoutImpl ell1 = new EdgeLabelLayoutImpl();
119 ell1.setBox(new YRectangle(0,0,80,20));
120 ell1.setEdgeLabelModel(new SliderEdgeLabelModel(SliderEdgeLabelModel.CENTER_SLIDER));
123
124 EdgeLabelLayoutImpl ell2 = new EdgeLabelLayoutImpl();
125 ell2.setBox(new YRectangle(0,0,80,20));
126 ell2.setEdgeLabelModel(new SliderEdgeLabelModel(SliderEdgeLabelModel.SIDE_SLIDER));
129
130 EdgeLabelLayout[] ells = new EdgeLabelLayout[]{ell1, ell2};
131 graph.setLabelLayout(e1, ells);
132
133 HierarchicLayouter layouter = new HierarchicLayouter();
134 layouter.setLayoutStyle(HierarchicLayouter.MEDIAN_SIMPLEX);
135 layouter.setLabelLayouterEnabled(true);
136 layouter.setLabelLayouter(new GreedyMISLabeling());
137
138 new BufferedLayouter(layouter).doLayout(graph);
139
140 LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph));
142 lpp1.createFrame("Hierarchical with general edge labeling").setVisible(true);
143
144 D.bug("\n\nGRAPH LAID OUT USING GENERAL EDGE LABELING");
145 D.bug("v1 center position = " + graph.getCenter(v1));
146 D.bug("v2 center position = " + graph.getCenter(v2));
147 D.bug("v3 center position = " + graph.getCenter(v3));
148 D.bug("e1 path = " + graph.getPath(e1));
149 D.bug("e2 path = " + graph.getPath(e2));
150 D.bug("e3 path = " + graph.getPath(e3));
151 D.bug("ell1 upper left location = " + getEdgeLabelLocation(graph,e1,ell1));
152 D.bug("ell2 upper left location = " + getEdgeLabelLocation(graph,e1,ell2));
153
154 EdgeLabelModel freeModel = new FreeEdgeLabelModel();
155 ell1.setEdgeLabelModel(freeModel);
156 ell1.setModelParameter(freeModel.getDefaultParameter());
157 ell2.setEdgeLabelModel(freeModel);
158 ell2.setModelParameter(freeModel.getDefaultParameter());
159 layouter.setLabelLayouterEnabled(true);
160 layouter.setLabelLayouter(new LabelLayoutTranslator());
161
162 new BufferedLayouter(layouter).doLayout(graph);
163
164 LayoutPreviewPanel lpp2 = new LayoutPreviewPanel(graph);
166 lpp2.createFrame("Hierarchical with internal labeling").setVisible(true);
167
168 D.bug("\n\nGRAPH LAID OUT USING HIERARCHIC LAYOUTER WITH INTERNAL EDGE LABELING");
169 D.bug("v1 center position = " + graph.getCenter(v1));
170 D.bug("v2 center position = " + graph.getCenter(v2));
171 D.bug("v3 center position = " + graph.getCenter(v3));
172 D.bug("e1 path = " + graph.getPath(e1));
173 D.bug("e2 path = " + graph.getPath(e2));
174 D.bug("e3 path = " + graph.getPath(e3));
175 D.bug("ell1 upper left location = " + getEdgeLabelLocation(graph,e1,ell1));
176 D.bug("ell2 upper left location = " + getEdgeLabelLocation(graph,e1,ell2));
177 }
178
179
185 YPoint getEdgeLabelLocation(LayoutGraph graph, Edge e, EdgeLabelLayout ell)
186 {
187 YPoint ellp = ell.getLabelModel().getLabelPlacement(
188 ell.getBox(),
189 graph.getEdgeLayout(e),
190 graph.getNodeLayout(e.source()),
191 graph.getNodeLayout(e.target()),
192 ell.getModelParameter());
193 return ellp;
194 }
195 }
196