Coverage details for edu.uci.ics.jung.visualization.control.CrossoverScalingControl

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University
3  * of California
4  * All rights reserved.
5  *
6  * This software is open-source under the BSD license; see either
7  * "license.txt" or
8  * http://jung.sourceforge.net/license.txt 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.VisualizationViewer;
17 import edu.uci.ics.jung.visualization.transform.MutableTransformer;
18  
19 /**
20  * A scaling control that has a crossover point.
21  * When the overall scale of the view and
22  * model is less than the crossover point, the scaling is applied
23  * to the view's transform and the graph nodes, labels, etc grow
24  * smaller. This preserves the overall shape of the graph.
25  * When the scale is larger than the crossover, the scaling is
26  * applied to the graph layout. The graph spreads out, but the
27  * vertices and labels grow no larger than their original size.
28  *
29  * @author Tom Nelson
30  */
310public class CrossoverScalingControl implements ScalingControl {
32  
33     /**
34      * Point where scale crosses over from view to layout.
35      */
360    protected double crossover = 1.0;
37     
38     /**
39      * Sets the crossover point to the specified value.
40      */
41     public void setCrossover(double crossover) {
420        this.crossover = crossover;
430    }
44  
45     /**
46      * Returns the current crossover value.
47      */
48     public double getCrossover() {
490        return crossover;
50     }
51     
52     /**
53      * @see edu.uci.ics.jung.visualization.control.ScalingControl#scale(VisualizationViewer, float, Point2D)
54      */
55     public void scale(VisualizationViewer vv, float amount, Point2D at) {
56             
570        MutableTransformer layoutTransformer = vv.getLayoutTransformer();
580        MutableTransformer viewTransformer = vv.getViewTransformer();
590        double modelScale = layoutTransformer.getScale();
600        double viewScale = viewTransformer.getScale();
610        double inverseModelScale = Math.sqrt(crossover)/modelScale;
620        double inverseViewScale = Math.sqrt(crossover)/viewScale;
630        double scale = modelScale * viewScale;
64         
650        Point2D transformedAt = vv.inverseViewTransform(at);
66         
670        if((scale*amount - crossover)*(scale*amount - crossover) < 0.001) {
68             // close to the control point, return both transformers to a scale of 1.0
690            layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt);
700            viewTransformer.scale(inverseViewScale, inverseViewScale, at);
710        } else if(scale*amount < crossover) {
72             // scale the viewTransformer, return the layoutTransformer to 1.0
730            viewTransformer.scale(amount, amount, at);
740            layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt);
75         } else {
76             // scale the layoutTransformer, return the viewTransformer to 1.0
770            layoutTransformer.scale(amount, amount, transformedAt);
780            viewTransformer.scale(inverseViewScale, inverseViewScale, at);
79         }
800        vv.repaint();
810    }
82 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.