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.view.viewmode;
29  
30  import demo.view.DemoBase;
31  import demo.view.DemoDefaults;
32  
33  import y.view.EditMode;
34  import y.view.MagnifierViewMode;
35  
36  import javax.swing.AbstractAction;
37  import javax.swing.JToggleButton;
38  import javax.swing.JToolBar;
39  import java.awt.event.ActionEvent;
40  import java.awt.EventQueue;
41  import java.util.Locale;
42  
43  /**
44   * Demonstrates how to use a magnifying glass effect to zoom view regions locally.
45   * <p>
46   * Usage: To activate the magnifier select the "Use Magnifier" button. Move the mouse over the
47   * view canvas to move the magnifier. Note that you can even edit the graph while the magnifier is active.
48   * Use the mouse wheel to change the zoom factor of the magnifier. To change the radius of the magnifier
49   * with the mouse wheel, additionally keep the CTRL key pressed. To deactivate the magnifier again, deselect
50   * the "Use Magnifier" button.
51   * </p>
52   * @see <a href="http://docs.yworks.com/yfiles/doc/api/index.html#/dguide/mvc_controller#cls_MagnifierViewMode" target="_blank">Section User Interaction</a> in the yFiles for Java Developer's Guide
53   */
54  public class MagnifierViewModeDemo extends DemoBase
55  {
56    MagnifierViewMode magnifierMode;
57    JToggleButton magnifierButton;
58  
59    public MagnifierViewModeDemo() {
60      magnifierButton.doClick();
61    }
62  
63    protected void initialize() {
64      super.initialize();
65  
66  //    // turn off the magnifier's double-buffering
67  //    view.putClientProperty("MagnifierViewMode.noDoubleBuffering", Boolean.TRUE);
68  
69      magnifierMode = new MagnifierViewMode();
70      magnifierMode.setMagnifierRadius(100);
71      magnifierMode.setMagnifierZoomFactor(2.0);
72  
73      loadGraph(getClass(), "resource/5.graphml");
74      DemoDefaults.applyRealizerDefaults(view.getGraph2D(), true, true);
75  
76    }
77  
78    protected JToolBar createToolBar() {
79      magnifierButton = new JToggleButton(new AbstractAction("Magnifier") {
80        public void actionPerformed(ActionEvent e) {
81          if (magnifierButton.isSelected()) {
82            view.addViewMode(magnifierMode);
83          } else {
84            view.removeViewMode(magnifierMode);
85          }
86        }
87      });
88      magnifierButton.setIcon(getIconResource("resource/magnifier.png"));
89  
90      JToolBar toolBar = super.createToolBar();
91      toolBar.addSeparator();
92      toolBar.add(magnifierButton);
93      return toolBar;
94    }
95  
96    protected void registerViewModes() {
97      EditMode editMode = new EditMode();
98      view.addViewMode(editMode);
99    }
100 
101   public static void main(String[] args) {
102     EventQueue.invokeLater(new Runnable() {
103       public void run() {
104         Locale.setDefault(Locale.ENGLISH);
105         initLnF();
106         (new MagnifierViewModeDemo()).start();
107       }
108     });
109   }
110 }
111