1
14 package demo.layout.withoutview;
15
16 import y.base.Edge;
17 import y.base.Node;
18 import y.base.NodeMap;
19 import y.base.ListCell;
20 import y.layout.BufferedLayouter;
21 import y.layout.CopiedLayoutGraph;
22 import y.layout.DefaultLayoutGraph;
23 import y.layout.LayoutGraph;
24 import y.layout.hierarchic.IncrementalHierarchicLayouter;
25 import y.layout.hierarchic.incremental.PartitionGrid;
26 import y.layout.hierarchic.incremental.ColumnDescriptor;
27 import y.util.D;
28 import y.util.DataProviders;
29
30 import java.awt.Graphics2D;
31 import java.awt.Rectangle;
32 import java.awt.Color;
33 import java.awt.EventQueue;
34 import java.awt.geom.Line2D;
35
36
49 public class SwimlaneLayoutWithoutAView
50 {
51
52 public static void main(String[] args) {
53 EventQueue.invokeLater(new Runnable() {
54 public void run() {
55 SwimlaneLayoutWithoutAView lwv = new SwimlaneLayoutWithoutAView();
56 lwv.doit();
57 }
58 });
59 }
60
61
64 public void doit()
65 {
66 DefaultLayoutGraph graph = new DefaultLayoutGraph();
67
68 Node v1 = graph.createNode();
70 graph.setSize(v1,30,30);
71 Node v2 = graph.createNode();
72 graph.setSize(v2,30,30);
73 Node v3 = graph.createNode();
74 graph.setSize(v3,30,30);
75 Node v4 = graph.createNode();
76 graph.setSize(v4,30,30);
77
78 Edge e1 = graph.createEdge(v1,v2);
80 Edge e2 = graph.createEdge(v1,v3);
81 Edge e3 = graph.createEdge(v2,v4);
82
83 final PartitionGrid grid = new PartitionGrid(1, 2);
86
87 NodeMap cellMap = graph.createNodeMap();
89
90 cellMap.set(v1, grid.createCellId(0, 0));
93 cellMap.set(v2, grid.createCellId(0, 1));
94 cellMap.set(v3, grid.createCellId(0, 1));
95 cellMap.set(v4, grid.createCellId(0, 0));
96
97 graph.addDataProvider(PartitionGrid.PARTITION_CELL_DPKEY, cellMap);
99 graph.addDataProvider(PartitionGrid.PARTITION_GRID_DPKEY, DataProviders.createConstantDataProvider(grid));
100
101 IncrementalHierarchicLayouter layouter = new IncrementalHierarchicLayouter();
103
104 new BufferedLayouter(layouter).doLayout(graph);
106
107 LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph)) {
109 Line2D.Double line = new Line2D.Double();
110 protected void paint( final Graphics2D g, final LayoutGraph graph ) {
111 final Color oldColor = g.getColor();
112 g.setColor(Color.white);
113
114 final Rectangle bbx = graph.getBoundingBox();
115 line.y1 = Math.floor(bbx.getY()) - 10;
116 line.y2 = Math.ceil(bbx.getMaxY()) + 10;
117 for (ListCell cell = grid.getColumns().firstCell(); cell != null; cell = cell.succ()) {
118 final ColumnDescriptor lane = (ColumnDescriptor) cell.getInfo();
119 line.x1 = lane.getComputedPosition();
120 line.x2 = line.x1;
121 g.draw(line);
122 }
123 {
124 final ColumnDescriptor lane = grid.getColumn(grid.getColumns().size() - 1);
125 line.x1 += lane.getComputedWidth();
126 line.x2 = line.x1;
127 g.draw(line);
128 }
129
130 g.setColor(oldColor);
131 }
132 };
133 lpp1.createFrame("Swimlanes").setVisible(true);
134
135 D.bug("\n\nGRAPH LAID OUT HIERARCHICALLY IN SWIMLANES");
136 D.bug("v1 center position = " + graph.getCenter(v1));
137 D.bug("v2 center position = " + graph.getCenter(v2));
138 D.bug("v3 center position = " + graph.getCenter(v3));
139 D.bug("v4 center position = " + graph.getCenter(v4));
140 D.bug("e1 path = " + graph.getPath(e1));
141 D.bug("e2 path = " + graph.getPath(e2));
142 D.bug("e3 path = " + graph.getPath(e3));
143 D.bug("Column 0 index = " + grid.getColumn(0).getIndex());
144 D.bug("Column 0 position = " + grid.getColumn(0).getComputedPosition());
145 D.bug("Column 0 width = " + grid.getColumn(0).getComputedWidth());
146 D.bug("Column 1 index = " + grid.getColumn(1).getIndex());
147 D.bug("Column 1 position = " + grid.getColumn(1).getComputedPosition());
148 D.bug("Column 1 width = " + grid.getColumn(1).getComputedWidth());
149 }
150 }
151