1   /****************************************************************************
2    **
3    ** This file is part of yFiles-2.6. 
4    ** 
5    ** yWorks proprietary/confidential. Use is subject to license terms.
6    **
7    ** Redistribution of this file or of an unauthorized byte-code version
8    ** of this file is strictly forbidden.
9    **
10   ** Copyright (c) 2000-2008 by yWorks GmbH, Vor dem Kreuzberg 28, 
11   ** 72070 Tuebingen, Germany. All rights reserved.
12   **
13   ***************************************************************************/
14  
15  package demo.layout;
16  
17  import y.base.Edge;
18  import y.base.Node;
19  import y.base.NodeMap;
20  import y.layout.BufferedLayouter;
21  import y.layout.CopiedLayoutGraph;
22  import y.layout.DefaultLayoutGraph;
23  import y.layout.hierarchic.IncrementalHierarchicLayouter;
24  import y.layout.hierarchic.incremental.SwimLaneDescriptor;
25  import y.util.D;
26  
27  /**
28   * This demo shows how to use the swim lane feature of IncrementalHierarchicLayouter
29   * without using classes that are only present in the yFiles Viewer Distribution. 
30   * In this demo, nodes will be assigned to certain regions of the diagram,
31   * the so-called swim lanes. The diagram will be arranged using hierachical layout
32   * style, while nodes remain within the bounds of their lanes.
33   * <br>
34   * This demo displays the calculated coordinates in a simple graph viewer.
35   * Additionally it outputs the calculated coordinates of the graph layout to
36   * the console.
37   */
38  public class SwimLaneLayoutWithoutAView
39  {
40    
41    /**
42     * Launcher
43     */
44    public static void main(String[] args)
45    {
46      SwimLaneLayoutWithoutAView lwv = new SwimLaneLayoutWithoutAView();
47      lwv.doit();
48    }
49  
50    /**
51     * Creates a small graph and applies a swim lane layout to it.
52     */
53    public void doit()
54    {
55      DefaultLayoutGraph graph = new DefaultLayoutGraph();
56      
57      //construct graph. assign sizes to nodes
58      Node v1 = graph.createNode();
59      graph.setSize(v1,30,30);
60      Node v2 = graph.createNode();
61      graph.setSize(v2,30,30);
62      Node v3 = graph.createNode();
63      graph.setSize(v3,30,30);
64      Node v4 = graph.createNode();
65      graph.setSize(v4,30,30);
66  
67      // create some edges...
68      Edge e1 = graph.createEdge(v1,v2);
69      Edge e2 = graph.createEdge(v1,v3);
70      Edge e3 = graph.createEdge(v2,v4);
71      
72      // create swim lane descriptors for two lanes. Lane
73      // sl1 is the first lane and sl2 is the second lane. 
74      SwimLaneDescriptor sl1 = new SwimLaneDescriptor(new Integer(1));
75      SwimLaneDescriptor sl2 = new SwimLaneDescriptor(new Integer(2));
76      
77      // create a map to store the swim lane descriptors
78      NodeMap slMap = graph.createNodeMap();
79  
80      // assign nodes to lanes 
81      slMap.set(v1, sl1);
82      slMap.set(v2, sl2);
83      slMap.set(v3, sl2);
84      slMap.set(v4, sl1);
85   
86      // register the information
87      graph.addDataProvider(IncrementalHierarchicLayouter.SWIMLANE_DESCRIPTOR_DPKEY, slMap);
88      
89      // create the layout algorithm
90      IncrementalHierarchicLayouter layouter = new IncrementalHierarchicLayouter();
91      
92      // start the layout
93      new BufferedLayouter(layouter).doLayout(graph);
94      
95      //display result
96      LayoutPreviewPanel lpp1 = new LayoutPreviewPanel(new CopiedLayoutGraph(graph));
97      lpp1.createFrame("Swimlanes").setVisible(true);
98      
99      D.bug("\n\nGRAPH LAID OUT HIERARCHICALLY IN SWIMLANES");
100     D.bug("v1 center position = " + graph.getCenter(v1));
101     D.bug("v2 center position = " + graph.getCenter(v2));
102     D.bug("v3 center position = " + graph.getCenter(v3));
103     D.bug("v4 center position = " + graph.getCenter(v4));
104     D.bug("e1 path = " + graph.getPath(e1));
105     D.bug("e2 path = " + graph.getPath(e2));
106     D.bug("e3 path = " + graph.getPath(e3));
107     D.bug("SwimLane 1 index = " + sl1.getComputedLaneIndex());
108     D.bug("SwimLane 1 position = " + sl1.getComputedLanePosition());
109     D.bug("SwimLane 1 width = " + sl1.getComputedLaneWidth());
110     D.bug("SwimLane 2 index = " + sl2.getComputedLaneIndex());
111     D.bug("SwimLane 2 position = " + sl2.getComputedLanePosition());
112     D.bug("SwimLane 2 width = " + sl2.getComputedLaneWidth());
113     
114   }
115 }
116