View Javadoc
1   /*
2    * Copyright (c) 2003, The JUNG Authors
3    * All rights reserved.
4    * 
5    * This software is open-source under the BSD license; see either "license.txt"
6    * or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
7    * 
8    */
9   package edu.uci.ics.jung.visualization.control;
10  
11  import java.awt.geom.Point2D;
12  
13  import edu.uci.ics.jung.visualization.Layer;
14  import edu.uci.ics.jung.visualization.VisualizationServer;
15  import edu.uci.ics.jung.visualization.transform.MutableTransformer;
16  
17  /**
18   * Scales to the absolute value passed as an argument.
19   * It first resets the scaling Functions, then uses
20   * the relative CrossoverScalingControl to achieve the
21   * absolute value.
22   * 
23   * @author Tom Nelson 
24   *
25   */
26  public class AbsoluteCrossoverScalingControl extends CrossoverScalingControl
27          implements ScalingControl {
28  
29  	/**
30       * Scale to the absolute value passed as 'amount'.
31  	 * 
32  	 * @param vv the VisualizationServer used for rendering; provides the layout and view transformers.
33  	 * @param amount the amount by which to scale
34  	 * @param at the point of reference for scaling
35  	 */
36  	public void scale(VisualizationServer<?,?> vv, float amount, Point2D at) {
37          MutableTransformer layoutTransformer
38          	= vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT);
39          MutableTransformer viewTransformer
40          	= vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW);
41          double modelScale = layoutTransformer.getScale();
42          double viewScale = viewTransformer.getScale();
43          double inverseModelScale = Math.sqrt(crossover)/modelScale;
44          double inverseViewScale = Math.sqrt(crossover)/viewScale;
45          
46          Point2D transformedAt
47          	= vv.getRenderContext().getMultiLayerTransformer().inverseTransform(Layer.VIEW, at);
48          
49          // return the Functions to 1.0
50          layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt);
51          viewTransformer.scale(inverseViewScale, inverseViewScale, at);
52  
53          super.scale(vv, amount, at);
54      }
55  }