KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > controls > AbstractZoomControl


1 package prefuse.controls;
2
3 import java.awt.geom.Point2D JavaDoc;
4
5 import prefuse.Display;
6
7 /**
8  * Abstract base class for zoom controls.
9  *
10  * @author <a HREF="http://jheer.org">jeffrey heer</a>
11  */

12 public class AbstractZoomControl extends ControlAdapter {
13
14     public static final double DEFAULT_MIN_SCALE = 1E-3;
15     public static final double DEFAULT_MAX_SCALE = 75;
16     
17     /** Indicates a zoom operation completed successfully. */
18     protected static final int ZOOM = 0;
19     /** Indicates the minimum allowed zoom level has been reached. */
20     protected static final int MIN_ZOOM = 1;
21     /** Indicates the maximum allowed zoom level has been reached. */
22     protected static final int MAX_ZOOM = 2;
23     /** Indicates no zooming can be performed. This is often due to a
24      * transformation activity in progress. */

25     protected static final int NO_ZOOM = 3;
26     
27     protected double m_minScale = DEFAULT_MIN_SCALE;
28     protected double m_maxScale = DEFAULT_MAX_SCALE;
29     protected boolean m_zoomOverItem = true;
30     
31     /**
32      * Zoom the given display at the given point by the zoom factor,
33      * in either absolute (item-space) or screen co-ordinates.
34      * @param display the Display to zoom
35      * @param p the point to center the zoom upon
36      * @param zoom the scale factor by which to zoom
37      * @param abs if true, the point p should be assumed to be in absolute
38      * coordinates, otherwise it will be treated as scree (pixel) coordinates
39      * @return a return code indicating the status of the zoom operation.
40      * One of {@link #ZOOM}, {@link #NO_ZOOM}, {@link #MIN_ZOOM},
41      * {@link #MAX_ZOOM}.
42      */

43     protected int zoom(Display display, Point2D JavaDoc p, double zoom, boolean abs) {
44         if ( display.isTranformInProgress() )
45             return NO_ZOOM;
46         
47         double scale = display.getScale();
48         double result = scale * zoom;
49         int status = ZOOM;
50
51         if ( result < m_minScale ) {
52             zoom = m_minScale/scale;
53             status = MIN_ZOOM;
54         } else if ( result > m_maxScale ) {
55             zoom = m_maxScale/scale;
56             status = MAX_ZOOM;
57         }
58         
59         if ( abs )
60             display.zoomAbs(p,zoom);
61         else
62             display.zoom(p,zoom);
63         display.repaint();
64         return status;
65     }
66     
67     /**
68      * Gets the maximum scale value allowed by this zoom control
69      * @return the maximum scale value
70      */

71     public double getMaxScale() {
72         return m_maxScale;
73     }
74     
75     /**
76      * Sets the maximum scale value allowed by this zoom control
77      * @return the maximum scale value
78      */

79     public void setMaxScale(double maxScale) {
80         this.m_maxScale = maxScale;
81     }
82     
83     /**
84      * Gets the minimum scale value allowed by this zoom control
85      * @return the minimum scale value
86      */

87     public double getMinScale() {
88         return m_minScale;
89     }
90     
91     /**
92      * Sets the minimum scale value allowed by this zoom control
93      * @return the minimum scale value
94      */

95     public void setMinScale(double minScale) {
96         this.m_minScale = minScale;
97     }
98
99     /**
100      * Indicates if the zoom control will work while the mouse is
101      * over a VisualItem.
102      * @return true if the control still operates over a VisualItem
103      */

104     public boolean isZoomOverItem() {
105         return m_zoomOverItem;
106     }
107
108     /**
109      * Determines if the zoom control will work while the mouse is
110      * over a VisualItem
111      * @param zoomOverItem true to indicate the control operates
112      * over VisualItems, false otherwise
113      */

114     public void setZoomOverItem(boolean zoomOverItem) {
115         this.m_zoomOverItem = zoomOverItem;
116     }
117     
118 } // end of class AbstractZoomControl
119
Popular Tags