1 package prefuse.controls; 2 3 import java.awt.geom.Point2D ; 4 5 import prefuse.Display; 6 7 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 18 protected static final int ZOOM = 0; 19 20 protected static final int MIN_ZOOM = 1; 21 22 protected static final int MAX_ZOOM = 2; 23 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 43 protected int zoom(Display display, Point2D 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 71 public double getMaxScale() { 72 return m_maxScale; 73 } 74 75 79 public void setMaxScale(double maxScale) { 80 this.m_maxScale = maxScale; 81 } 82 83 87 public double getMinScale() { 88 return m_minScale; 89 } 90 91 95 public void setMinScale(double minScale) { 96 this.m_minScale = minScale; 97 } 98 99 104 public boolean isZoomOverItem() { 105 return m_zoomOverItem; 106 } 107 108 114 public void setZoomOverItem(boolean zoomOverItem) { 115 this.m_zoomOverItem = zoomOverItem; 116 } 117 118 } | Popular Tags |