Exemple #1
0
  public void scrollByUnit(int direction) {
    float size;
    if (orientation == VERTICAL) {
      direction *= -1;
      size = scrollSpace + slider.getThumbButton().getHeight() / slider.getHeight();
    } else size = scrollSpace + slider.getThumbButton().getWidth() / slider.getWidth();

    if (direction == DECREMENT) setValue(getValue() - size);
    else setValue(getValue() + size);
  }
Exemple #2
0
  /**
   * Sets the appearance for this scroll bar. If <code>appearance</code> is not an instance of
   * ScrollBarAppearance, an <code>IllegalArgumentException</code> is thrown.
   *
   * @param appearance the new appearance to set
   */
  public void setAppearance(ComponentAppearance appearance) {
    if (appearance == null)
      throw new IllegalStateException("null appearance not allowed with ScrollBar");
    if (!(appearance instanceof ScrollBarAppearance)) {
      throw new IllegalArgumentException("appearance must be instance of ScrollBarAppearance");
    }
    super.setAppearance(appearance);

    // de-init components
    if (slider != null) {
      remove(slider);
      slider.removeMouseWheelListener(incDecListener);
      slider.getThumbButton().removeMouseWheelListener(incDecListener);
      // slider.getDelayTimer().removeActionListener(delayListener);

    }
    if (incButton != null) {
      remove(incButton);
      incButton.removeActionListener(incDecListener);
    }
    if (decButton != null) {
      remove(decButton);
      decButton.removeActionListener(incDecListener);
    }

    // re-init components

    // gets the current appearance
    ScrollBarAppearance a = (ScrollBarAppearance) this.getAppearance();
    if (a == null) {
      throw new IllegalStateException("no appearance set for this scroll bar");
    }

    // creates scroll & thumb buttons
    // skins can choose how they should be created
    incButton = a.createScrollButton(this, INCREMENT);
    decButton = a.createScrollButton(this, DECREMENT);
    slider = a.createSlider(this, orientation);

    if (incButton == null || decButton == null || slider == null)
      throw new NullPointerException("null components passed to scroll bar");
    if (slider.getOrientation() != orientation)
      throw new IllegalArgumentException("passed slider doesn't match orientation of scroll bar");

    // add scroll listeners buttons
    incButton.addActionListener(incDecListener);
    decButton.addActionListener(incDecListener);
    // slider.getDelayTimer().addActionListener(delayListener);

    // add the new components to this bar
    add(slider);
    add(incButton);
    add(decButton);

    incButton.addMouseWheelListener(incDecListener);
    decButton.addMouseWheelListener(incDecListener);
    slider.addMouseWheelListener(incDecListener);
    slider.getThumbButton().addMouseWheelListener(incDecListener);
    addMouseWheelListener(incDecListener);

    updateWidth();
    updateHeight();
  }