1 package de.fzi.wim.guibase.graphview.lens;
2
3 import java.awt.geom.Point2D;
4
5 /***
6 * An implementation of the lens that allows rotation. This class has been initially implemented within
7 * the <a href="http://www.touchgraph.com/">TouchGraph</a> library.
8 */
9 public class RotateLens extends AbstractLens {
10 /*** The rotation angle. */
11 protected double m_rotationAngle;
12 /*** The sine of the angle. */
13 protected double m_sine;
14 /*** The cosine of the angle. */
15 protected double m_cosine;
16
17 /***
18 * Creates a lens for rotation.
19 */
20 public RotateLens() {
21 setRotationAngle(0.0);
22 }
23 /***
24 * Returns the current rotation angle in degrees.
25 *
26 * @return the current rotation angle in degrees
27 */
28 public double getRotationAngle() {
29 return m_rotationAngle;
30 }
31 /***
32 * Sets the new rotation angle in degrees.
33 *
34 * @param rotationAngle the new rotation angle in degrees
35 */
36 public void setRotationAngle(double rotationAngle) {
37 m_rotationAngle=rotationAngle;
38 double rotationAngleRadian=m_rotationAngle*Math.PI/180.0;
39 m_sine=Math.sin(rotationAngleRadian);
40 m_cosine=Math.cos(rotationAngleRadian);
41 fireLensUpdated();
42 }
43 /***
44 * Applies the lens to the point and modifies it according to the lens equations.
45 *
46 * @param point the point that will be modified
47 */
48 public void applyLens(Point2D point) {
49 double newX=point.getX()*m_cosine+point.getY()*m_sine;
50 double newY=-point.getX()*m_sine+point.getY()*m_cosine;
51 point.setLocation(newX,newY);
52 }
53 /***
54 * Undoes the lens effect on the point.
55 *
56 * @param point the point that will be modified
57 */
58 public void undoLens(Point2D point) {
59 double newX=point.getX()*m_cosine-point.getY()*m_sine;
60 double newY=point.getX()*m_sine+point.getY()*m_cosine;
61 point.setLocation(newX,newY);
62 }
63 }