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());
    }
  }
  /**
   * 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);
      }
    }
  }
Пример #3
0
 private void scrollByUnit(Adjustable adj, int val) {
   if (adj == vAdjustable) {
     int visIdx = getCurrentIndex() + val;
     selectVisible(visIdx);
   } else if (adj == hAdjustable) {
     updateAdjValue(adj, val * adj.getUnitIncrement());
   }
 }
Пример #4
0
  /**
   * Called by ScrollPane's internal observer of the scrollpane's adjustables. This is called
   * whenever a scroll position is changed in one of adjustables, whether it was modified externally
   * or from the native scrollbars themselves.
   */
  public void setValue(Adjustable adj, int v) {
    Component c = getScrollChild();
    if (c == null) {
      return;
    }

    Point p = c.getLocation();
    switch (adj.getOrientation()) {
      case Adjustable.VERTICAL:
        setScrollPosition(-(p.x), v);
        break;
      case Adjustable.HORIZONTAL:
        setScrollPosition(v, -(p.y));
        break;
    }
  }
Пример #5
0
 private void updateAdjValue(Adjustable adj, final int increment) {
   int oldVal = adj.getValue();
   adj.setValue(oldVal + increment);
 }