Пример #1
0
 /** 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());
     }
   }
 }
  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);
      }
    }
  }
 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);
   }
 }
Пример #5
0
 /**
  * Registers an {@link Adjustable} for participation in synchronized scrolling.
  *
  * @param adjustable the adjustable
  */
 public void participateInSynchronizedScrolling(Adjustable adjustable) {
   if (adjustable == null) return;
   if (synchronizedAdjustables.contains(adjustable)) return;
   synchronizedAdjustables.add(adjustable);
   setParticipatingInSynchronizedScrolling(adjustable, true);
   adjustable.addAdjustmentListener(this);
 }
Пример #6
0
    // This method is called whenever the value of a scrollbar is changed,
    // either by the user or programmatically.
    public void adjustmentValueChanged(AdjustmentEvent evt) {
      Adjustable source = evt.getAdjustable();

      // getValueIsAdjusting() returns true if the user is currently
      // dragging the scrollbar's knob and has not picked a final value
      if (evt.getValueIsAdjusting()) {
        // The user is dragging the knob
        return;
      }

      // Determine which scrollbar fired the event
      int orient = source.getOrientation();
      if (orient == Adjustable.HORIZONTAL) {
        // Event from horizontal scrollbar
      } else {
        // Event from vertical scrollbar
      }

      // Determine the type of event
      int type = evt.getAdjustmentType();
      switch (type) {
        case AdjustmentEvent.UNIT_INCREMENT:
          // Scrollbar was increased by one unit
          break;
        case AdjustmentEvent.UNIT_DECREMENT:
          // Scrollbar was decreased by one unit
          break;
        case AdjustmentEvent.BLOCK_INCREMENT:
          // Scrollbar was increased by one block
          break;
        case AdjustmentEvent.BLOCK_DECREMENT:
          // Scrollbar was decreased by one block
          break;
        case AdjustmentEvent.TRACK:
          // The knob on the scrollbar was dragged
          break;
      }

      // Get current value
      int value = evt.getValue();

      headerPanelLeft.setAdjustment(value);
      headerPanelRight.setAdjustment(value);
    }
Пример #7
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;
    }
  }
 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;
   }
 }