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  package demo.module;
15  
16  import demo.view.DemoBase;
17  import y.module.YModule;
18  import y.option.OptionHandler;
19  import y.view.Arrow;
20  import y.view.hierarchy.HierarchyManager;
21  
22  import javax.swing.AbstractAction;
23  import javax.swing.JToolBar;
24  import java.awt.event.ActionEvent;
25  
26  /**
27   * Demonstrates how layout modules can be added to the GUI of an application.
28   * A layout module is a layout algorithm combined
29   * with an option dialog, that allows to change the
30   * options of a layout algorithm interactively
31   * (only available if layout is part of distribution).
32   *
33   */
34  public class LayoutModuleDemo extends DemoBase
35  {
36  
37    public LayoutModuleDemo()
38    {
39      //use a delta arrow to make edge directions clear
40      view.getGraph2D().getDefaultEdgeRealizer().setArrow(Arrow.DELTA);
41  
42      //to enable loading of hierachically grouped graphs/
43      HierarchyManager hierarchy = new HierarchyManager(view.getGraph2D());
44      loadGraph( "resource/sample.gml" );
45    }
46  
47    /**
48     * Returns ViewActionDemo toolbar plus actions to trigger some layout algorithms
49     */
50    protected JToolBar createToolBar()
51    {
52      JToolBar bar = super.createToolBar();
53  
54      bar.addSeparator();
55  
56      bar.add(new LaunchModule(new demo.module.OrganicLayoutModule(), "Organic"));
57      bar.add(new LaunchModule(new y.module.RandomLayoutModule(), "Random" ));
58      bar.add(new LaunchModule(new demo.module.CircularLayoutModule(), "Circular" ));
59      bar.add(new LaunchModule(new demo.module.HierarchicLayoutModule(), "Hierarchic" ));
60      bar.add(new LaunchModule(new demo.module.IncrementalHierarchicLayoutModule(), "Incremental H." ));
61      bar.add(new LaunchModule(new demo.module.OrthogonalLayoutModule(), "Orthogonal" ));
62      bar.add(new LaunchModule(new demo.module.TreeLayoutModule(), "Tree" ));
63      bar.add(new LaunchModule(new demo.module.DiagonalLayoutModule(), "Diagonal" ));
64      bar.add(new LaunchModule(new demo.module.FamilyTreeLayoutModule(), "Family" ));
65  
66  
67      return bar;
68    }
69  
70    /**
71     *  Launches a generic YModule. If the modules provides
72     *  an option handler display it before the modules gets launched.
73     */
74    class LaunchModule extends AbstractAction
75    {
76      YModule module;
77  
78      LaunchModule( YModule module, String title )
79      {
80        super(title);
81        this.module = module;
82      }
83  
84      public void actionPerformed(ActionEvent e)
85      {
86        OptionHandler op = module.getOptionHandler();
87        if( op != null) {
88          if( !op.showEditor() )
89            return;
90        }
91        module.start(view.getGraph2D());
92      }
93    }
94  
95    public static void main(String args[])
96    {
97      initLnF();
98      LayoutModuleDemo demo = new LayoutModuleDemo();
99      demo.start(demo.getClass().getName());
100   }
101 }
102 
103 
104       
105