/** Updates the dimensions for both thumbs. */
  @Override
  protected void calculateThumbSize() {
    // Call superclass method for lower thumb size.
    super.calculateThumbSize();

    // Set upper thumb size.
    upperThumbRect.setSize(thumbRect.width, thumbRect.height);
  }
  /** Paints the track. */
  @Override
  public void paintTrack(Graphics g) {
    // Draw track.
    super.paintTrack(g);

    Rectangle trackBounds = trackRect;

    if (slider.getOrientation() == JSlider.HORIZONTAL) {
      // Determine position of selected range by moving from the middle
      // of one thumb to the other.
      int lowerX = thumbRect.x + (thumbRect.width / 2);
      int upperX = upperThumbRect.x + (upperThumbRect.width / 2);

      // Determine track position.
      int cy = (trackBounds.height / 2) - 2;

      // Save color and shift position.
      Color oldColor = g.getColor();
      g.translate(trackBounds.x, trackBounds.y + cy);

      // Draw selected range.
      g.setColor(rangeColor);
      for (int y = 0; y <= 3; y++) {
        g.drawLine(lowerX - trackBounds.x, y, upperX - trackBounds.x, y);
      }

      // Restore position and color.
      g.translate(-trackBounds.x, -(trackBounds.y + cy));
      g.setColor(oldColor);

    } else {
      // Determine position of selected range by moving from the middle
      // of one thumb to the other.
      int lowerY = thumbRect.x + (thumbRect.width / 2);
      int upperY = upperThumbRect.x + (upperThumbRect.width / 2);

      // Determine track position.
      int cx = (trackBounds.width / 2) - 2;

      // Save color and shift position.
      Color oldColor = g.getColor();
      g.translate(trackBounds.x + cx, trackBounds.y);

      // Draw selected range.
      g.setColor(rangeColor);
      for (int x = 0; x <= 3; x++) {
        g.drawLine(x, lowerY - trackBounds.y, x, upperY - trackBounds.y);
      }

      // Restore position and color.
      g.translate(-(trackBounds.x + cx), -trackBounds.y);
      g.setColor(oldColor);
    }
  }
  /**
   * Extends the {@link #calculateTrackBuffer()} to allow the extra space required to display the
   * arrows on the track.
   *
   * @see BasicSliderUI#calculateTrackBuffer()
   */
  protected void calculateTrackBuffer() {
    super.calculateTrackBuffer();
    if (showArrows)
      if (slider.getOrientation() == JSlider.HORIZONTAL) {
        if (arrowWidth > minArrowWidth) trackBuffer += arrowWidth + ARROW_SPACE;
        else trackBuffer += minArrowWidth + ARROW_SPACE;
      } else {
        if (arrowHeight > minArrowHeight) trackBuffer += arrowHeight + ARROW_SPACE;
        else trackBuffer += minArrowHeight + ARROW_SPACE;
      }

    if (showEndLabel)
      if (slider.getOrientation() == JSlider.HORIZONTAL) trackBuffer += labelWidth + TEXT_SPACE;
      else trackBuffer += labelHeight + TEXT_SPACE;
  }
  /** Updates the locations for both thumbs. */
  @Override
  protected void calculateThumbLocation() {
    // Call superclass method for lower thumb location.
    super.calculateThumbLocation();

    // Adjust upper value to snap to ticks if necessary.
    if (slider.getSnapToTicks()) {
      int upperValue = slider.getValue() + slider.getExtent();
      int snappedValue = upperValue;
      int majorTickSpacing = slider.getMajorTickSpacing();
      int minorTickSpacing = slider.getMinorTickSpacing();
      int tickSpacing = 0;

      if (minorTickSpacing > 0) {
        tickSpacing = minorTickSpacing;
      } else if (majorTickSpacing > 0) {
        tickSpacing = majorTickSpacing;
      }

      if (tickSpacing != 0) {
        // If it's not on a tick, change the value
        if ((upperValue - slider.getMinimum()) % tickSpacing != 0) {
          float temp = (float) (upperValue - slider.getMinimum()) / (float) tickSpacing;
          int whichTick = Math.round(temp);
          snappedValue = slider.getMinimum() + (whichTick * tickSpacing);
        }

        if (snappedValue != upperValue) {
          slider.setExtent(snappedValue - slider.getValue());
        }
      }
    }

    // Calculate upper thumb location.  The thumb is centered over its
    // value on the track.
    if (slider.getOrientation() == JSlider.HORIZONTAL) {
      int upperPosition = xPositionForValue(slider.getValue() + slider.getExtent());
      upperThumbRect.x = upperPosition - (upperThumbRect.width / 2);
      upperThumbRect.y = trackRect.y;

    } else {
      int upperPosition = yPositionForValue(slider.getValue() + slider.getExtent());
      upperThumbRect.x = trackRect.x;
      upperThumbRect.y = upperPosition - (upperThumbRect.height / 2);
    }
  }
  /** Paints the slider. The selected thumb is always painted on top of the other thumb. */
  @Override
  public void paint(Graphics g, JComponent c) {
    super.paint(g, c);

    Rectangle clipRect = g.getClipBounds();
    if (upperThumbSelected) {
      // Paint lower thumb first, then upper thumb.
      if (clipRect.intersects(thumbRect)) {
        paintLowerThumb(g);
      }
      if (clipRect.intersects(upperThumbRect)) {
        paintUpperThumb(g);
      }

    } else {
      // Paint upper thumb first, then lower thumb.
      if (clipRect.intersects(upperThumbRect)) {
        paintUpperThumb(g);
      }
      if (clipRect.intersects(thumbRect)) {
        paintLowerThumb(g);
      }
    }
  }
Example #6
0
 protected void scrollDueToClickInTrack(int dir) {
   // FIXME:  for what might this method be overridden?
   super.scrollDueToClickInTrack(dir);
 }
Example #7
0
 /**
  * Installs the default for this UI delegate in the supplied component.
  *
  * @param c the component.
  */
 public void installUI(JComponent c) {
   super.installUI(c);
   Boolean b = (Boolean) c.getClientProperty(SLIDER_FILL);
   if (b != null) filledSlider = b.booleanValue();
 }
 /** Installs this UI delegate on the specified component. */
 @Override
 public void installUI(JComponent c) {
   upperThumbRect = new Rectangle();
   super.installUI(c);
 }
 public void setThumbLocation(int x, int y) {
   super.setThumbLocation(x, y);
   parentSlider.repaint();
 }
 /**
  * Overridden to calculate the geometry of the slider, this calls the {@link
  * BasicSliderUI#calculateGeometry} and to add extra calculations to calculate the <code>ArrowRect
  * </code> if showArrows is <code>true</code>.
  *
  * @see BasicSliderUI#calculateGeometry()
  */
 public void calculateGeometry() {
   super.calculateGeometry();
   if (showArrows) calculateArrowRect();
   if (showEndLabel) calculateEndLabelRect();
 }