1 package prefuse.controls; 2 3 import java.awt.Cursor ; 4 import java.awt.event.MouseEvent ; 5 import java.awt.geom.Point2D ; 6 7 import prefuse.Display; 8 import prefuse.util.ui.UILib; 9 import prefuse.visual.VisualItem; 10 11 12 22 public class ZoomControl extends AbstractZoomControl { 23 24 private int yLast; 25 private Point2D down = new Point2D.Float (); 26 private int button = RIGHT_MOUSE_BUTTON; 27 28 31 public ZoomControl() { 32 } 34 35 41 public ZoomControl(int mouseButton) { 42 button = mouseButton; 43 } 44 45 48 public void mousePressed(MouseEvent e) { 49 if ( UILib.isButtonPressed(e, button) ) { 50 Display display = (Display)e.getComponent(); 51 if (display.isTranformInProgress()) { 52 yLast = -1; 53 System.err.println("can't move"); 54 return; 55 } 56 display.setCursor( 57 Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); 58 display.getAbsoluteCoordinate(e.getPoint(), down); 59 yLast = e.getY(); 60 } 61 } 62 63 66 public void mouseDragged(MouseEvent e) { 67 if ( UILib.isButtonPressed(e, button) ) { 68 Display display = (Display)e.getComponent(); 69 if (display.isTranformInProgress() || yLast == -1) { 70 yLast = -1; 71 return; 72 } 73 74 int y = e.getY(); 75 int dy = y-yLast; 76 double zoom = 1 + ((double)dy) / 100; 77 78 int status = zoom(display, down, zoom, true); 79 int cursor = Cursor.N_RESIZE_CURSOR; 80 if ( status == NO_ZOOM ) 81 cursor = Cursor.WAIT_CURSOR; 82 display.setCursor(Cursor.getPredefinedCursor(cursor)); 83 84 yLast = y; 85 } 86 } 87 88 91 public void mouseReleased(MouseEvent e) { 92 if ( UILib.isButtonPressed(e, button) ) { 93 e.getComponent().setCursor(Cursor.getDefaultCursor()); 94 } 95 } 96 97 100 public void itemPressed(VisualItem item, MouseEvent e) { 101 if ( m_zoomOverItem ) 102 mousePressed(e); 103 } 104 105 108 public void itemDragged(VisualItem item, MouseEvent e) { 109 if ( m_zoomOverItem ) 110 mouseDragged(e); 111 } 112 113 116 public void itemReleased(VisualItem item, MouseEvent e) { 117 if ( m_zoomOverItem ) 118 mouseReleased(e); 119 } 120 121 } | Popular Tags |