コード例 #1
0
  /**
   * Paints the progress string.
   *
   * @param g Graphics used for drawing.
   * @param x x location of bounding box
   * @param y y location of bounding box
   * @param width width of bounding box
   * @param height height of bounding box
   * @param fillStart start location, in x or y depending on orientation, of the filled portion of
   *     the progress bar.
   * @param amountFull size of the fill region, either width or height depending upon orientation.
   * @param b Insets of the progress bar.
   */
  private void paintString(
      Graphics g, int x, int y, int width, int height, int fillStart, int amountFull, Insets b) {
    if (!(g instanceof Graphics2D)) {
      return;
    }

    Graphics2D g2 = (Graphics2D) g;
    String progressString = progressBar.getString();
    g2.setFont(progressBar.getFont());
    Point renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
    Rectangle oldClip = g2.getClipBounds();

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      g2.setColor(getSelectionBackground());
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(fillStart, y, amountFull, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    } else { // VERTICAL
      g2.setColor(getSelectionBackground());
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      g2.setFont(progressBar.getFont().deriveFont(rotate));
      renderLocation = getStringPlacement(g2, progressString, x, y, width, height);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
      g2.setColor(getSelectionForeground());
      g2.clipRect(x, fillStart, width, amountFull);
      SwingUtilities2.drawString(
          progressBar, g2, progressString, renderLocation.x, renderLocation.y);
    }
    g2.setClip(oldClip);
  }
コード例 #2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paint(java.awt.Graphics
   * , javax.swing.JComponent)
   */
  @Override
  public void paint(Graphics g, JComponent c) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setFont(
        FlamingoUtilities.getFont(this.commandButton, "Ribbon.font", "Button.font", "Panel.font"));

    this.layoutInfo = this.layoutManager.getLayoutInfo(this.commandButton, g);
    commandButton.putClientProperty("icon.bounds", layoutInfo.iconRect);
    commandButton.putClientProperty("icon", commandButton.getIcon());

    if (this.isPaintingBackground()) {
      this.paintButtonBackground(g2d, new Rectangle(0, 0, c.getWidth(), c.getHeight()));
    }

    // decide which command button model should be used to
    // compute the foreground color of the command button's text
    boolean useActionAreaForFg = layoutInfo.isTextInActionArea;
    StateTransitionTracker transitionTrackerForFg =
        useActionAreaForFg ? this.getActionTransitionTracker() : this.getPopupTransitionTracker();
    ModelStateInfo modelStateInfoForFg = transitionTrackerForFg.getModelStateInfo();
    ComponentState currStateForFg = modelStateInfoForFg.getCurrModelState();
    Color fgColor = this.commandButton.getForeground();

    if (fgColor instanceof UIResource) {
      float buttonAlpha =
          SubstanceColorSchemeUtilities.getAlpha(this.commandButton, currStateForFg);
      fgColor =
          SubstanceTextUtilities.getForegroundColor(
              this.commandButton, this.commandButton.getText(), modelStateInfoForFg, buttonAlpha);
    }

    if (layoutInfo.textLayoutInfoList != null) {
      for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo :
          layoutInfo.textLayoutInfoList) {
        if (mainTextLayoutInfo.text != null) {
          SubstanceTextUtilities.paintText(
              g2d,
              c,
              mainTextLayoutInfo.textRect,
              mainTextLayoutInfo.text,
              -1,
              g2d.getFont(),
              fgColor,
              g2d.getClipBounds());
        }
      }
    }

    if (layoutInfo.extraTextLayoutInfoList != null) {
      Color disabledFgColor =
          SubstanceColorSchemeUtilities.getColorScheme(
                  this.commandButton, ComponentState.DISABLED_UNSELECTED)
              .getForegroundColor();
      float buttonAlpha =
          SubstanceColorSchemeUtilities.getAlpha(
              this.commandButton, ComponentState.DISABLED_UNSELECTED);
      if (buttonAlpha < 1.0f) {
        Color bgFillColor = SubstanceColorUtilities.getBackgroundFillColor(this.commandButton);
        disabledFgColor =
            SubstanceColorUtilities.getInterpolatedColor(disabledFgColor, bgFillColor, buttonAlpha);
      }
      if (currStateForFg.isDisabled()) {
        disabledFgColor =
            SubstanceColorUtilities.getInterpolatedColor(
                disabledFgColor, SubstanceColorUtilities.getBackgroundFillColor(c), 0.5);
      }
      for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo :
          layoutInfo.extraTextLayoutInfoList) {
        if (extraTextLayoutInfo.text != null) {
          SubstanceTextUtilities.paintText(
              g2d,
              c,
              extraTextLayoutInfo.textRect,
              extraTextLayoutInfo.text,
              -1,
              g2d.getFont(),
              disabledFgColor,
              g2d.getClipBounds());
        }
      }
    }

    if (layoutInfo.iconRect != null) {
      this.paintButtonIcon(g2d, layoutInfo.iconRect);
    }
    if (layoutInfo.popupActionRect.getWidth() > 0) {
      paintPopupActionIcon(g2d, layoutInfo.popupActionRect);
    }

    if (this.isPaintingSeparators() && (layoutInfo.separatorArea != null)) {
      if (layoutInfo.separatorOrientation == CommandButtonSeparatorOrientation.HORIZONTAL) {
        this.paintButtonHorizontalSeparator(g2d, layoutInfo.separatorArea);
      } else {
        this.paintButtonVerticalSeparator(g2d, layoutInfo.separatorArea);
      }
    }

    // g2d.setColor(Color.red);
    // g2d.draw(layoutInfo.iconRect);
    // g2d.setColor(Color.blue);
    // if (layoutInfo.textLayoutInfoList != null) {
    // for (CommandButtonLayoutManager.TextLayoutInfo mainTextLayoutInfo :
    // layoutInfo.textLayoutInfoList) {
    // if (mainTextLayoutInfo.text != null) {
    // g2d.draw(mainTextLayoutInfo.textRect);
    // }
    // }
    // }
    // g2d.setColor(Color.magenta);
    // if (layoutInfo.extraTextLayoutInfoList != null) {
    // for (CommandButtonLayoutManager.TextLayoutInfo extraTextLayoutInfo :
    // layoutInfo.extraTextLayoutInfoList) {
    // if (extraTextLayoutInfo.text != null) {
    // g2d.draw(extraTextLayoutInfo.textRect);
    // }
    // }
    // }
    // g2d.setColor(Color.green);
    // g2d.draw(layoutInfo.popupActionRect);

    g2d.dispose();
  }