View Javadoc

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 zooming. This class has been initially implemented within
7    * the <a href="http://www.touchgraph.com/">TouchGraph</a> library.
8    */
9   public class ZoomLens extends AbstractLens {
10      /*** The zoom factor. */
11      protected double m_zoomFactor;
12  
13      /***
14       * Creates a lens for zooming.
15       */
16      public ZoomLens() {
17          setZoomFactor(1.0);
18      }
19      /***
20       * Returns the current zoom factor.
21       *
22       * @return                  the current zoom factor
23       */
24      public double getZoomFactor() {
25          return m_zoomFactor;
26      }
27      /***
28       * Sets the new zoom factor.
29       *
30       * @param zoomFactor        the new zoom factor
31       */
32      public void setZoomFactor(double zoomFactor) {
33          m_zoomFactor=zoomFactor;
34          fireLensUpdated();
35      }
36      /***
37       * Applies the lens to the point and modifies it according to the lens equations.
38       *
39       * @param point             the point that will be modified
40       */
41      public void applyLens(Point2D point) {
42          point.setLocation(point.getX()*m_zoomFactor,point.getY()*m_zoomFactor);
43      }
44      /***
45       * Undoes the lens effect on the point.
46       *
47       * @param point             the point that will be modified
48       */
49      public void undoLens(Point2D point) {
50          point.setLocation(point.getX()/m_zoomFactor,point.getY()/m_zoomFactor);
51      }
52  }