View Javadoc
1   /*
2    * Copyright (c) 2005, The JUNG Authors 
3    *
4    * All rights reserved.
5    *
6    * This software is open-source under the BSD license; see either
7    * "license.txt" or
8    * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
9    * Created on Mar 8, 2005
10   *
11   */
12  package edu.uci.ics.jung.visualization.control;
13  
14  import java.awt.geom.Point2D;
15  
16  import edu.uci.ics.jung.visualization.Layer;
17  import edu.uci.ics.jung.visualization.VisualizationServer;
18  import edu.uci.ics.jung.visualization.transform.MutableTransformer;
19  
20  /** 
21   * LayoutScalingControl applies a scaling transformation to the graph layout.
22   * The Vertices get closer or farther apart, but do not themselves change
23   * size. ScalingGraphMouse uses MouseWheelEvents to apply the scaling.
24   * 
25   * @author Tom Nelson
26   */
27  public class LayoutScalingControl implements ScalingControl {
28  
29      /**
30  	 * zoom the display in or out, depending on the direction of the
31  	 * mouse wheel motion.
32  	 */
33      public void scale(VisualizationServer<?, ?> vv, float amount, Point2D from) {
34          
35          Point2D ivtfrom = vv.getRenderContext().getMultiLayerTransformer()
36          	.inverseTransform(Layer.VIEW, from);
37          MutableTransformer modelTransformer = vv.getRenderContext().getMultiLayerTransformer()
38          	.getTransformer(Layer.LAYOUT);
39          modelTransformer.scale(amount, amount, ivtfrom);
40          vv.repaint();
41      }
42  }