1   /****************************************************************************
2    * This demo file is part of yFiles for Java 2.14.
3    * Copyright (c) 2000-2017 by yWorks GmbH, Vor dem Kreuzberg 28,
4    * 72070 Tuebingen, Germany. All rights reserved.
5    * 
6    * yFiles demo files exhibit yFiles for Java functionalities. Any redistribution
7    * of demo files in source code or binary form, with or without
8    * modification, is not permitted.
9    * 
10   * Owners of a valid software license for a yFiles for Java version that this
11   * demo is shipped with are allowed to use the demo source code as basis
12   * for their own yFiles for Java powered applications. Use of such programs is
13   * governed by the rights and conditions as set out in the yFiles for Java
14   * license agreement.
15   * 
16   * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED
17   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19   * NO EVENT SHALL yWorks BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21   * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   *
27   ***************************************************************************/
28  package demo.layout.module;
29  
30  import demo.layout.withoutview.DiagonalLayouter;
31  import y.module.LayoutModule;
32  import y.option.OptionHandler;
33  
34  /**
35   * This module represents an interactive configurator and launcher for the demo
36   * Layouter {@link demo.layout.withoutview.DiagonalLayouter}.
37   * <br>
38   * Additionally, this class can be executed separately. In this case it shows off
39   * the internationalization and serialization features of the
40   * {@link y.option.OptionHandler} class.
41   * By launching the module class using a two letter language constant as an
42   * argument, the dialog will be internationalized in that language if the
43   * corresponding localized properties file is available. Try either 'en' for
44   * English or 'de' for German.
45   *
46   *
47   * @see <a href="http://docs.yworks.com/yfiles/doc/api/index.html#/dguide/option_basic#i18n_l10n" target="_blank">Section Internationalization and Localization</a> in the yFiles for Java Developer's Guide
48   */
49  public class DiagonalLayoutModule extends LayoutModule
50  {
51    //// Module 'Diagonal Layout'
52    protected static final String MODULE_DIAGONAL = "DIAGONAL";
53    
54    //// Section 'default' items
55    protected static final String ITEM_MINIMAL_NODE_DISTANCE = "MINIMAL_NODE_DISTANCE";
56  
57    /**
58     * Creates an instance of this module.
59     */
60    public DiagonalLayoutModule() {
61      super(MODULE_DIAGONAL);
62    }
63    
64    /**
65     * Creates an OptionHandler and adds the option items used by this module.
66     * @return the created <code>OptionHandler</code> providing module related options
67     */
68    protected OptionHandler createOptionHandler() {
69      final OptionHandler options = new OptionHandler(getModuleName());
70      // Defaults provider
71      final DiagonalLayouter defaults = new DiagonalLayouter();
72      
73      // Populate default section
74      options.addDouble(ITEM_MINIMAL_NODE_DISTANCE, defaults.getMinimalNodeDistance());
75      
76      return options;
77    }
78    
79    /**
80     * Main module execution routine.
81     * Launches the module's underlying algorithm on the module's graph based on user options.
82     */
83    protected void mainrun() {
84      final DiagonalLayouter diagonal = new DiagonalLayouter();
85      
86      final OptionHandler options = getOptionHandler();
87      configure(diagonal, options);
88      
89      launchLayouter(diagonal);
90    }
91  
92    /**
93     * Configures the module's layout algorithm according to the given options.
94     * @param diagonal the <code>DiagonalLayouter</code> to be configured
95     * @param options the layout options to set
96     */
97    protected void configure(final DiagonalLayouter diagonal, final OptionHandler options) {
98      diagonal.setMinimalNodeDistance(options.getDouble(ITEM_MINIMAL_NODE_DISTANCE));
99    }
100 }
101 
102