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