1 package prefuse.controls; 2 3 import java.awt.Cursor ; 4 import java.awt.event.MouseEvent ; 5 6 import prefuse.Display; 7 import prefuse.util.ui.UILib; 8 import prefuse.visual.VisualItem; 9 10 11 18 public class PanControl extends ControlAdapter { 19 20 private boolean m_panOverItem; 21 private int m_xDown, m_yDown; 22 private int m_button; 23 24 27 public PanControl() { 28 this(LEFT_MOUSE_BUTTON, false); 29 } 30 31 36 public PanControl(boolean panOverItem) { 37 this(LEFT_MOUSE_BUTTON, panOverItem); 38 } 39 40 46 public PanControl(int mouseButton) { 47 this(mouseButton, false); 48 } 49 50 58 public PanControl(int mouseButton, boolean panOverItem) { 59 m_button = mouseButton; 60 m_panOverItem = panOverItem; 61 } 62 63 65 68 public void mousePressed(MouseEvent e) { 69 if ( UILib.isButtonPressed(e, m_button) ) { 70 e.getComponent().setCursor( 71 Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); 72 m_xDown = e.getX(); 73 m_yDown = e.getY(); 74 } 75 } 76 77 80 public void mouseDragged(MouseEvent e) { 81 if ( UILib.isButtonPressed(e, m_button) ) { 82 Display display = (Display)e.getComponent(); 83 int x = e.getX(), y = e.getY(); 84 int dx = x-m_xDown, dy = y-m_yDown; 85 display.pan(dx,dy); 86 m_xDown = x; 87 m_yDown = y; 88 display.repaint(); 89 } 90 } 91 92 95 public void mouseReleased(MouseEvent e) { 96 if ( UILib.isButtonPressed(e, m_button) ) { 97 e.getComponent().setCursor(Cursor.getDefaultCursor()); 98 m_xDown = -1; 99 m_yDown = -1; 100 } 101 } 102 103 106 public void itemPressed(VisualItem item, MouseEvent e) { 107 if ( m_panOverItem ) 108 mousePressed(e); 109 } 110 111 114 public void itemDragged(VisualItem item, MouseEvent e) { 115 if ( m_panOverItem ) 116 mouseDragged(e); 117 } 118 119 122 public void itemReleased(VisualItem item, MouseEvent e) { 123 if ( m_panOverItem ) 124 mouseReleased(e); 125 } 126 127 } | Popular Tags |