View Javadoc

1   /*
2    * Copyright (c) 2005, the JUNG Project and the Regents of the University of
3    * California All rights reserved.
4    *
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or http://jung.sourceforge.net/license.txt for a description.
7    *
8    * Created on Aug 15, 2005
9    */
10  
11  package edu.uci.ics.jung.visualization.control;
12  
13  import java.awt.event.MouseWheelEvent;
14  
15  import edu.uci.ics.jung.visualization.VisualizationViewer;
16  
17  /**
18   * Overrides ScalingGraphMousePlugin so that mouse events in the
19   * satellite view will cause scaling in the main view
20   * 
21   * @see ScalingGraphMousePlugin
22   * @author Tom Nelson 
23   *
24   */
25  public class SatelliteScalingGraphMousePlugin extends ScalingGraphMousePlugin {
26  
27      public SatelliteScalingGraphMousePlugin(ScalingControl scaler, int modifiers) {
28          super(scaler, modifiers);
29      }
30  
31      public SatelliteScalingGraphMousePlugin(ScalingControl scaler, int modifiers, float in, float out) {
32          super(scaler, modifiers, in, out);
33      }
34      
35      /**
36       * zoom the master view display in or out, depending on the direction of the
37       * mouse wheel motion.
38       */
39      public void mouseWheelMoved(MouseWheelEvent e) {
40          boolean accepted = checkModifiers(e);
41          if(accepted == true) {
42              VisualizationViewer vv = (VisualizationViewer)e.getSource();
43  
44              if(vv instanceof SatelliteVisualizationViewer) {
45                  VisualizationViewer vvMaster = 
46                      ((SatelliteVisualizationViewer)vv).getMaster();
47  
48                  int amount = e.getWheelRotation();
49                  
50                  if(amount > 0) {
51                      scaler.scale(vvMaster, in, vvMaster.getCenter());
52  
53                  } else if(amount < 0) {
54                      scaler.scale(vvMaster, out, vvMaster.getCenter());
55                  }
56                  e.consume();
57                  vv.repaint();
58              }
59          }
60      }
61  
62  
63  }