1   /****************************************************************************
2    **
3    ** This file is part of yFiles-2.9. 
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-2011 by yWorks GmbH, Vor dem Kreuzberg 28, 
11   ** 72070 Tuebingen, Germany. All rights reserved.
12   **
13   ***************************************************************************/
14  package demo.view.advanced.ports;
15  
16  import y.view.CreateEdgeMode;
17  import y.view.EditMode;
18  import y.view.MouseInputMode;
19  import y.view.MovePortMode;
20  import y.view.SelectionBoxMode;
21  import y.view.ViewMode;
22  
23  /**
24   * Customized {@link y.view.EditMode} that takes {@link y.view.NodePort}s
25   * into account (especially when deselecting elements on paper clicks).
26   *
27   */
28  class PortEditMode extends EditMode {
29    PortEditMode() {
30      setCyclicSelectionEnabled(true);
31    }
32  
33    /**
34     * Overwritten to create a {@link demo.view.advanced.ports.NodePortPopupMode}
35     * instance.
36     * @return a {@link demo.view.advanced.ports.NodePortPopupMode}
37     * instance.
38     */
39    protected ViewMode createPopupMode() {
40      return new NodePortPopupMode();
41    }
42  
43    /**
44     * Overwritten to create a {@link y.view.MovePortMode} instance that allows
45     * reassigning edges to new nodes.
46     * @return a {@link y.view.MovePortMode} instance.
47     */
48    protected ViewMode createMovePortMode() {
49      final MovePortMode mpm = new MovePortMode();
50      mpm.setChangeEdgeEnabled(true);
51      return mpm;
52    }
53  
54    /**
55     * Overwritten to create a {@link y.view.CreateEdgeMode} instance that
56     * visually indicates target nodes and ports for newly created edges.
57     * @return a {@link y.view.CreateEdgeMode} instance.
58     */
59    protected ViewMode createCreateEdgeMode() {
60      final CreateEdgeMode cem = new PortCreateEdgeMode();
61      cem.setIndicatingTargetNode(true);
62      return cem;
63    }
64  
65    /**
66     * Overwritten to create a {@link y.view.MouseInputMode} instance
67     * that supports interactive selecting/deselecting and moving of
68     * {@link y.view.NodePort} instances.
69     * @return a {@link y.view.MouseInputMode} instance.
70     */
71    protected MouseInputMode createMouseInputMode() {
72      final MouseInputMode mim = new MouseInputMode();
73      mim.setNodeSearchingEnabled(true);
74      return mim;
75    }
76  
77    /**
78     * Overwritten to create a {@link y.view.SelectionBoxMode} instance
79     * that supports selecting {@link y.view.NodePort} instances and
80     * {@link y.view.YLabel} instances as well as {@link y.base.Node},
81     * {@link y.base.Edge}, and {@link y.view.Bend} instances.
82     * @return a {@link y.view.SelectionBoxMode} instance.
83     */
84    protected ViewMode createSelectionBoxMode() {
85      final SelectionBoxMode sbm = new SelectionBoxMode();
86      sbm.setExtendedTypeSelectionEnabled(true);
87      return sbm;
88    }
89  }
90