Line | Hits | Source |
---|---|---|
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 | */ | |
31 | 0 | public class CrossoverScalingControl implements ScalingControl { |
32 | ||
33 | /** | |
34 | * Point where scale crosses over from view to layout. | |
35 | */ | |
36 | 0 | protected double crossover = 1.0; |
37 | ||
38 | /** | |
39 | * Sets the crossover point to the specified value. | |
40 | */ | |
41 | public void setCrossover(double crossover) { | |
42 | 0 | this.crossover = crossover; |
43 | 0 | } |
44 | ||
45 | /** | |
46 | * Returns the current crossover value. | |
47 | */ | |
48 | public double getCrossover() { | |
49 | 0 | 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 | ||
57 | 0 | MutableTransformer layoutTransformer = vv.getLayoutTransformer(); |
58 | 0 | MutableTransformer viewTransformer = vv.getViewTransformer(); |
59 | 0 | double modelScale = layoutTransformer.getScale(); |
60 | 0 | double viewScale = viewTransformer.getScale(); |
61 | 0 | double inverseModelScale = Math.sqrt(crossover)/modelScale; |
62 | 0 | double inverseViewScale = Math.sqrt(crossover)/viewScale; |
63 | 0 | double scale = modelScale * viewScale; |
64 | ||
65 | 0 | Point2D transformedAt = vv.inverseViewTransform(at); |
66 | ||
67 | 0 | if((scale*amount - crossover)*(scale*amount - crossover) < 0.001) { |
68 | // close to the control point, return both transformers to a scale of 1.0 | |
69 | 0 | layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt); |
70 | 0 | viewTransformer.scale(inverseViewScale, inverseViewScale, at); |
71 | 0 | } else if(scale*amount < crossover) { |
72 | // scale the viewTransformer, return the layoutTransformer to 1.0 | |
73 | 0 | viewTransformer.scale(amount, amount, at); |
74 | 0 | layoutTransformer.scale(inverseModelScale, inverseModelScale, transformedAt); |
75 | } else { | |
76 | // scale the layoutTransformer, return the viewTransformer to 1.0 | |
77 | 0 | layoutTransformer.scale(amount, amount, transformedAt); |
78 | 0 | viewTransformer.scale(inverseViewScale, inverseViewScale, at); |
79 | } | |
80 | 0 | vv.repaint(); |
81 | 0 | } |
82 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |