/** * Mouse dragged, initiates page panning if the tool is selected. * * @param e awt mouse event */ public void mouseDragged(MouseEvent e) { if (documentViewController != null && documentViewController.getDocumentViewModel().getViewToolMode() == DocumentViewModel.DISPLAY_TOOL_PAN) { // Get data about the current view port position Adjustable verticalScrollbar = documentViewController.getVerticalScrollBar(); Adjustable horizontalScrollbar = documentViewController.getHorizontalScrollBar(); if (verticalScrollbar != null && horizontalScrollbar != null) { // calculate how much the view port should be moved Point p = new Point( (int) e.getPoint().getX() - horizontalScrollbar.getValue(), (int) e.getPoint().getY() - verticalScrollbar.getValue()); int x = (int) (horizontalScrollbar.getValue() - (p.getX() - lastMousePosition.getX())); int y = (int) (verticalScrollbar.getValue() - (p.getY() - lastMousePosition.getY())); // apply the pan horizontalScrollbar.setValue(x); verticalScrollbar.setValue(y); // update last position holder lastMousePosition.setLocation(p); } } }
public void mouseMoved(MouseEvent e) { if (documentViewController != null && documentViewController.getDocumentViewModel().getViewToolMode() == DocumentViewModel.DISPLAY_TOOL_PAN) { Adjustable verticalScrollbar = documentViewController.getVerticalScrollBar(); Adjustable horizontalScrollbar = documentViewController.getHorizontalScrollBar(); lastMousePosition.setLocation( e.getPoint().getX() - horizontalScrollbar.getValue(), e.getPoint().getY() - verticalScrollbar.getValue()); } }
public void mousePressed(MouseEvent event) { if (draggable) { smoothScroll(0, 0, null, null); Component source = (Component) event.getSource(); if (source == this) { mouseDownEvent = event.getPoint(); } else { mouseDownEvent = new Point(event.getX() + source.getX(), event.getY() + source.getY()); } Adjustable sbh = getAdjustable(Adjustable.HORIZONTAL); Adjustable sbv = getAdjustable(Adjustable.VERTICAL); mouseDownScroll = new Point(sbh.getValue(), sbv.getValue()); setCursor(CURSOR_GRABBING); } }
public void mouseDragged(MouseEvent event) { if (draggable && mouseDownEvent != null) { smoothScroll(0, 0, null, null); Point point; Component source = (Component) event.getSource(); if (source == this) { point = event.getPoint(); } else { point = new Point(event.getX() + source.getX(), event.getY() + source.getY()); } int dx = point.x - mouseDownEvent.x; int dy = point.y - mouseDownEvent.y; Adjustable sbh = getAdjustable(Adjustable.HORIZONTAL); Adjustable sbv = getAdjustable(Adjustable.VERTICAL); int sbx = sbh.getValue(); int sby = sbv.getValue(); setAdjustableValues(mouseDownScroll.x - dx, mouseDownScroll.y - dy); int sdx = sbh.getValue() - sbx; int sdy = sbv.getValue() - sby; mouseDownScroll.x += sdx; mouseDownScroll.y += sdy; } }