// Called from initIndeterminateValues to initialize the animation index.
 // This assumes that numFrames is set to a correct value.
 private void initAnimationIndex() {
   if ((progressBar.getOrientation() == JProgressBar.HORIZONTAL)
       && (BasicGraphicsUtils.isLeftToRight(progressBar))) {
     // If this is a left-to-right progress bar,
     // start at the first frame.
     setAnimationIndex(0);
   } else {
     // If we go right-to-left or vertically, start at the right/bottom.
     setAnimationIndex(numFrames / 2);
   }
 }
 protected void paintString(
     Graphics g, int x, int y, int width, int height, int amountFull, Insets b) {
   if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     if (BasicGraphicsUtils.isLeftToRight(progressBar)) {
       if (progressBar.isIndeterminate()) {
         boxRect = getBox(boxRect);
         paintString(g, x, y, width, height, boxRect.x, boxRect.width, b);
       } else {
         paintString(g, x, y, width, height, x, amountFull, b);
       }
     } else {
       paintString(g, x, y, width, height, x + width - amountFull, amountFull, b);
     }
   } else {
     if (progressBar.isIndeterminate()) {
       boxRect = getBox(boxRect);
       paintString(g, x, y, width, height, boxRect.y, boxRect.height, b);
     } else {
       paintString(g, x, y, width, height, y + height - amountFull, amountFull, b);
     }
   }
 }
Пример #3
0
 public Dimension getPreferredSize(JComponent c) {
   AbstractButton b = (AbstractButton) c;
   return BasicGraphicsUtils.getPreferredButtonSize(b, b.getIconTextGap());
 }
  /**
   * All purpose paint method that should do the right thing for almost all linear, determinate
   * progress bars. By setting a few values in the defaults table, things should work just fine to
   * paint your progress bar. Naturally, override this if you are making a circular or semi-circular
   * progress bar.
   *
   * @see #paintIndeterminate
   * @since 1.4
   */
  protected void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);

    if (barRectWidth <= 0 || barRectHeight <= 0) {
      return;
    }

    int cellLength = getCellLength();
    int cellSpacing = getCellSpacing();
    // amount of progress to draw
    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);

    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(progressBar.getForeground());

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectHeight, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectHeight,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0.f,
                new float[] {cellLength, cellSpacing},
                0.f));
      }

      if (BasicGraphicsUtils.isLeftToRight(c)) {
        g2.drawLine(
            b.left, (barRectHeight / 2) + b.top, amountFull + b.left, (barRectHeight / 2) + b.top);
      } else {
        g2.drawLine(
            (barRectWidth + b.left),
            (barRectHeight / 2) + b.top,
            barRectWidth + b.left - amountFull,
            (barRectHeight / 2) + b.top);
      }

    } else { // VERTICAL
      // draw the cells
      if (cellSpacing == 0 && amountFull > 0) {
        // draw one big Rect because there is no space between cells
        g2.setStroke(
            new BasicStroke((float) barRectWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
      } else {
        // draw each individual cell
        g2.setStroke(
            new BasicStroke(
                (float) barRectWidth,
                BasicStroke.CAP_BUTT,
                BasicStroke.JOIN_BEVEL,
                0f,
                new float[] {cellLength, cellSpacing},
                0f));
      }

      g2.drawLine(
          barRectWidth / 2 + b.left,
          b.top + barRectHeight,
          barRectWidth / 2 + b.left,
          b.top + barRectHeight - amountFull);
    }

    // Deal with possible text painting
    if (progressBar.isStringPainted()) {
      paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b);
    }
  }