/**
   * Paints the thumb for a vertical scroll bar.
   *
   * @param g the graphics device.
   * @param c the scroll bar component.
   * @param thumbBounds the thumb bounds.
   */
  private void paintThumbVertical(Graphics g, JComponent c, Rectangle thumbBounds) {
    int x = thumbBounds.x;
    int y = thumbBounds.y;
    int w = thumbBounds.width;
    int h = thumbBounds.height;

    // First we fill the background.
    MetalTheme theme = MetalLookAndFeel.getCurrentTheme();
    if (theme instanceof OceanTheme && UIManager.get("ScrollBar.gradient") != null) {
      MetalUtils.paintGradient(
          g, x + 2, y + 2, w - 2, h - 4, SwingConstants.HORIZONTAL, "ScrollBar.gradient");
    } else {
      g.setColor(thumbColor);
      if (isFreeStanding) g.fillRect(x, y, w - 1, h);
      else g.fillRect(x, y, w, h);
    }

    // then draw the dark box
    g.setColor(thumbLightShadowColor);
    if (isFreeStanding) g.drawRect(x, y, w - 2, h - 1);
    else {
      g.drawLine(x, y, x + w - 1, y);
      g.drawLine(x, y, x, y + h - 1);
      g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
    }

    // then the highlight
    g.setColor(thumbHighlightColor);
    if (isFreeStanding) {
      g.drawLine(x + 1, y + 1, x + w - 3, y + 1);
      g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
    } else {
      g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
      g.drawLine(x + 1, y + 1, x + 1, y + h - 3);
    }

    // draw the shadow line
    g.setColor(UIManager.getColor("ScrollBar.shadow"));
    g.drawLine(x + 1, y + h, x + w - 2, y + h);

    // For the OceanTheme, draw the 3 lines in the middle.
    if (theme instanceof OceanTheme) {
      g.setColor(thumbLightShadowColor);
      int middle = y + h / 2;
      g.drawLine(x + 4, middle - 2, x + w - 5, middle - 2);
      g.drawLine(x + 4, middle, x + w - 5, middle);
      g.drawLine(x + 4, middle + 2, x + w - 5, middle + 2);
      g.setColor(UIManager.getColor("ScrollBar.highlight"));
      g.drawLine(x + 5, middle - 1, x + w - 4, middle - 1);
      g.drawLine(x + 5, middle + 1, x + w - 4, middle + 1);
      g.drawLine(x + 5, middle + 3, x + w - 4, middle + 3);
    }
  }
  /**
   * Paints the slider button of the ScrollBar.
   *
   * @param g the Graphics context to use
   * @param c the JComponent on which we paint
   * @param thumbBounds the rectangle that is the slider button
   */
  protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    // a disabled scrollbar has no thumb in the metal look and feel
    if (!c.isEnabled()) return;
    if (scrollbar.getOrientation() == HORIZONTAL) paintThumbHorizontal(g, c, thumbBounds);
    else paintThumbVertical(g, c, thumbBounds);

    // Draw the pattern when the theme is not Ocean.
    if (!(MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)) {
      MetalUtils.fillMetalPattern(
          c,
          g,
          thumbBounds.x + 3,
          thumbBounds.y + 3,
          thumbBounds.width - 6,
          thumbBounds.height - 6,
          thumbHighlightColor,
          thumbLightShadowColor);
    }
  }
Exemple #3
0
  /**
   * Paints the track along which the thumb control moves.
   *
   * @param g the graphics device.
   */
  public void paintTrack(Graphics g) {
    Color shadowColor = MetalLookAndFeel.getControlShadow();
    if (slider.getOrientation() == JSlider.HORIZONTAL) {
      int trackX = trackRect.x;
      int trackY = trackRect.y + (trackRect.height - getTrackWidth()) / 2;
      int trackW = trackRect.width;
      int trackH = getTrackWidth();

      // draw border
      if (slider.isEnabled())
        BasicGraphicsUtils.drawEtchedRect(
            g,
            trackX,
            trackY,
            trackW,
            trackH,
            darkShadowColor,
            shadowColor,
            darkShadowColor,
            highlightColor);
      else {
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
      }

      // fill track (if required)
      if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) {
        if (slider.isEnabled()) {
          int xPos = xPositionForValue(slider.getValue());
          int x = slider.getInverted() ? xPos : trackRect.x;
          int w = slider.getInverted() ? trackX + trackW - xPos : xPos - trackRect.x;
          g.setColor(MetalLookAndFeel.getWhite());
          g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
          g.setColor(UIManager.getColor("Slider.altTrackColor"));
          g.drawLine(x + 1, trackY + 2, x + w - 3, trackY + 2);
          g.setColor(MetalLookAndFeel.getControlShadow());
          g.drawLine(x + 1, trackY + 3, x + w - 3, trackY + 3);
          g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
          g.drawLine(x + 1, trackY + 4, x + w - 3, trackY + 4);
        }
      } else if (filledSlider) {
        int xPos = xPositionForValue(slider.getValue());
        int x = slider.getInverted() ? xPos : trackRect.x;
        int w = slider.getInverted() ? trackX + trackW - xPos : xPos - trackRect.x;
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.fillRect(x + 1, trackY + 1, w - 3, getTrackWidth() - 3);
        if (slider.isEnabled()) {
          g.setColor(MetalLookAndFeel.getControl());
          g.drawLine(x + 1, trackY + 1, x + w - 3, trackY + 1);
          g.drawLine(x + 1, trackY + 1, x + 1, trackY + getTrackWidth() - 3);
        }
      }
    } else {
      int trackX = trackRect.x + (trackRect.width - getTrackWidth()) / 2;
      int trackY = trackRect.y;
      int trackW = getTrackWidth();
      int trackH = trackRect.height;
      if (slider.isEnabled())
        BasicGraphicsUtils.drawEtchedRect(
            g,
            trackX,
            trackY,
            trackW,
            trackH,
            darkShadowColor,
            shadowColor,
            darkShadowColor,
            highlightColor);
      else {
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.drawRect(trackX, trackY, trackW - 2, trackH - 2);
      }

      // Fill track if necessary.
      if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) {
        if (slider.isEnabled()) {
          int yPos = yPositionForValue(slider.getValue());
          int y = slider.getInverted() ? trackY : yPos;
          int h = slider.getInverted() ? yPos - trackY : trackY + trackH - yPos;

          g.setColor(MetalLookAndFeel.getWhite());
          g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
          g.setColor(UIManager.getColor("Slider.altTrackColor"));
          g.drawLine(trackX + 2, y + 1, trackX + 2, y + h - 3);
          g.setColor(MetalLookAndFeel.getControlShadow());
          g.drawLine(trackX + 3, y + 1, trackX + 3, y + h - 3);
          g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
          g.drawLine(trackX + 4, y + 1, trackX + 4, y + h - 3);
        }
      } else if (filledSlider) {
        int yPos = yPositionForValue(slider.getValue());
        int y = slider.getInverted() ? trackY : yPos;
        int h = slider.getInverted() ? yPos - trackY : trackY + trackH - yPos;
        g.setColor(MetalLookAndFeel.getControlShadow());
        g.fillRect(trackX + 1, y + 1, getTrackWidth() - 3, h - 3);
        if (slider.isEnabled()) {
          g.setColor(MetalLookAndFeel.getControl());
          g.drawLine(trackX + 1, y + 1, trackX + trackW - 3, y + 1);
          g.drawLine(trackX + 1, y + 1, trackX + 1, y + h - 3);
        }
      }
    }
  }