/** * 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); } } }
/** Event handler for {@link AdjustmentEvent}s */ @Override public void adjustmentValueChanged(AdjustmentEvent e) { if (!enabledMap.get(e.getAdjustable())) return; for (Adjustable a : synchronizedAdjustables) { if (a != e.getAdjustable() && isParticipatingInSynchronizedScrolling(a)) { a.setValue(e.getValue()); } } }