Example #1
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();
  }