Beispiel #1
0
    public void run() {
      if (getScrollChild() == null) {
        return;
      }
      ScrollPane sp = (ScrollPane) WScrollPanePeer.this.target;
      ScrollPaneAdjustable adj = null;

      // ScrollPaneAdjustable made public in 1.4, but
      // get[HV]Adjustable can't be declared to return
      // ScrollPaneAdjustable because it would break backward
      // compatibility -- hence the cast

      if (orient == Adjustable.VERTICAL) {
        adj = (ScrollPaneAdjustable) sp.getVAdjustable();
      } else if (orient == Adjustable.HORIZONTAL) {
        adj = (ScrollPaneAdjustable) sp.getHAdjustable();
      } else {
        if (dbg.on) dbg.assertion(false);
      }

      if (adj == null) {
        return;
      }

      int newpos = adj.getValue();
      switch (type) {
        case AdjustmentEvent.UNIT_DECREMENT:
          newpos -= adj.getUnitIncrement();
          break;
        case AdjustmentEvent.UNIT_INCREMENT:
          newpos += adj.getUnitIncrement();
          break;
        case AdjustmentEvent.BLOCK_DECREMENT:
          newpos -= adj.getBlockIncrement();
          break;
        case AdjustmentEvent.BLOCK_INCREMENT:
          newpos += adj.getBlockIncrement();
          break;
        case AdjustmentEvent.TRACK:
          newpos = this.pos;
          break;
        default:
          if (dbg.on) dbg.assertion(false);
          return;
      }

      // keep scroll position in acceptable range
      newpos = Math.max(adj.getMinimum(), newpos);
      newpos = Math.min(adj.getMaximum(), newpos);

      // set value, this will synchronously fire an AdjustmentEvent
      adj.setValueIsAdjusting(isAdjusting);

      // Fix for 4075484 - consider type information when creating AdjustmentEvent
      // We can't just call adj.setValue() because it creates AdjustmentEvent with type=TRACK
      // Instead, we call private method setTypedValue of ScrollPaneAdjustable.
      // Because ScrollPaneAdjustable is in another package we should call it through native code.
      setTypedValue(adj, newpos, type);

      // Paint the exposed area right away.  To do this - find
      // the heavyweight ancestor of the scroll child.
      Component hwAncestor = getScrollChild();
      while (hwAncestor != null && !(hwAncestor.getPeer() instanceof WComponentPeer)) {
        hwAncestor = hwAncestor.getParent();
      }
      if (dbg.on) {
        dbg.assertion(
            hwAncestor != null, "couldn't find heavyweight ancestor of scroll pane child");
      }
      WComponentPeer hwPeer = (WComponentPeer) hwAncestor.getPeer();
      hwPeer.paintDamagedAreaImmediately();
    }