| MagnifierViewModeDemo.java |
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.view.viewmode;
15
16 import demo.view.DemoBase;
17 import y.view.EditMode;
18 import y.view.MagnifierViewMode;
19
20 import javax.swing.JToggleButton;
21 import javax.swing.JToolBar;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24
25 /**
26 * Demonstrates how to use a magnifying glass effect to zoom view regions locally.
27 *
28 * Usage: to activate the magnifier select the "Use Magnifier" button. Move the mouse over the
29 * view canvas to move the magnifier. Note that you can even edit the graph while the magnifier is active.
30 * Use the mouse wheel to change the zoom factor of the magnifier. To change the radius of the magnifier
31 * with the mouse wheel, additionally keep the CTRL key pressed. To deactivate the magnifier again, deselect
32 * the "Use Magnifier" button.
33 */
34 public class MagnifierViewModeDemo extends DemoBase
35 {
36 MagnifierViewMode magnifierMode;
37 JToggleButton magnifierButton;
38
39 protected void initialize() {
40 super.initialize();
41
42
43 magnifierMode = new MagnifierViewMode();
44 magnifierMode.setMagnifierRadius(100);
45 magnifierMode.setMagnifierZoomFactor(2.0);
46
47 loadGraph(getClass(), "resource/5.gml");
48
49 }
50
51 protected JToolBar createToolBar() {
52 JToolBar toolBar = super.createToolBar();
53 magnifierButton = new JToggleButton("Use Magnifier");
54 magnifierButton.addActionListener(new ActionListener() {
55 public void actionPerformed(ActionEvent e) {
56 if(magnifierButton.isSelected()) {
57 view.addViewMode(magnifierMode);
58 } else {
59 view.removeViewMode(magnifierMode);
60 }
61 }
62 });
63
64 toolBar.add(magnifierButton);
65 return toolBar;
66 }
67
68 protected void registerViewModes() {
69 EditMode editMode = new EditMode();
70 view.addViewMode(editMode);
71 }
72
73 public static void main(String args[])
74 {
75 initLnF();
76 MagnifierViewModeDemo demo = new MagnifierViewModeDemo();
77 demo.start();
78 }
79 }
80