Example #1
0
  /**
   * As of Java 2 platform v 1.4 this method should not be used or overriden. Use the paintText
   * method which takes the AbstractButton argument.
   */
  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    FontMetrics fm = SwingUtilities2.getFontMetrics(c, g);
    int mnemonicIndex = b.getDisplayedMnemonicIndex();

    /* Draw the Text */
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
      /** * paint the text disabled ** */
      g.setColor(b.getBackground().brighter());
      SwingUtilities2.drawStringUnderlineCharAt(
          c, g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
      g.setColor(b.getBackground().darker());
      SwingUtilities2.drawStringUnderlineCharAt(
          c, g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
  /**
   * Method which renders the text of the current button.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   * @since 1.4
   */
  @Override
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1);
    boolean borderHasPressedCue = borderHasPressedCue(b);

    /* Draw the Text */
    if (model.isPressed() && model.isArmed() && !borderHasPressedCue) {
      g.setColor(new Color(0xa0000000, true));
      QuaquaUtilities.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset() + 1);
    }

    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground");
      g.setColor((c != null) ? c : b.getForeground());
    }
    QuaquaUtilities.drawStringUnderlineCharAt(
        g,
        text,
        mnemonicIndex,
        textRect.x + getTextShiftOffset(),
        textRect.y + fm.getAscent() + getTextShiftOffset());
  }
Example #3
0
  @Override
  protected void paintText(
      final Graphics g, final JComponent c, final Rectangle textRect, final String text) {
    final AbstractButton b = (AbstractButton) c;
    final ButtonModel model = b.getModel();
    final FontMetrics fm = SwingUtils.getFontMetrics(c, g);
    final int mnemonicIndex = b.getDisplayedMnemonicIndex();

    // Drawing text
    if (model.isEnabled()) {
      // Normal text
      g.setColor(b.getForeground());
      SwingUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset());
    } else {
      // Disabled text
      g.setColor(b.getBackground().brighter());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
      g.setColor(b.getBackground().darker());
      SwingUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
  /**
   * Renders a text String in Windows without the mnemonic. This is here because the WindowsUI
   * hiearchy doesn't match the Component heirarchy. All the overriden paintText methods of the
   * ButtonUI delegates will call this static method.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   */
  public static void paintText(
      Graphics g, AbstractButton b, Rectangle textRect, String text, int textShiftOffset) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();

    int mnemIndex = b.getDisplayedMnemonicIndex();
    // W2K Feature: Check to see if the Underscore should be rendered.
    if (WindowsLookAndFeel.isMnemonicHidden() == true) {
      mnemIndex = -1;
    }

    /* Draw the Text */
    Color color = b.getForeground();
    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemIndex,
          textRect.x + textShiftOffset,
          textRect.y + fm.getAscent() + textShiftOffset);
    } else {
        /** * paint the text disabled ** */
      color = UIManager.getColor("Button.disabledForeground");
      Color shadow = UIManager.getColor("Button.disabledShadow");

      XPStyle xp = XPStyle.getXP();
      if (xp != null) {
        color = xp.getColor("button.pushbutton(disabled).textcolor", color);
      } else {
        // Paint shadow only if not XP
        if (shadow == null) {
          shadow = b.getBackground().darker();
        }
        g.setColor(shadow);
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
      }
      if (color == null) {
        color = b.getBackground().brighter();
      }
      g.setColor(color);
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
    }
  }
Example #5
0
  protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) {
    AbstractButton button = (AbstractButton) c;
    ButtonModel model = button.getModel();
    Color fg = button.getForeground();
    if (fg instanceof UIResource
        && button instanceof JButton
        && ((JButton) button).isDefaultButton()) {
      final Color selectedFg = UIManager.getColor("Button.darcula.selectedButtonForeground");
      if (selectedFg != null) {
        fg = selectedFg;
      }
    }
    g.setColor(fg);

    FontMetrics metrics = SwingUtilities2.getFontMetrics(c, g);
    int mnemonicIndex = button.getDisplayedMnemonicIndex();
    if (model.isEnabled()) {

      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + metrics.getAscent() + getTextShiftOffset());
    } else {
      g.setColor(UIManager.getColor("Button.darcula.disabledText.shadow"));
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          -1,
          textRect.x + getTextShiftOffset() + 1,
          textRect.y + metrics.getAscent() + getTextShiftOffset() + 1);
      g.setColor(UIManager.getColor("Button.disabledText"));
      SwingUtilities2.drawStringUnderlineCharAt(
          c,
          g,
          text,
          -1,
          textRect.x + getTextShiftOffset(),
          textRect.y + metrics.getAscent() + getTextShiftOffset());
    }
  }
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
    int mnemIndex;
    if (JTattooUtilities.getJavaVersion() >= 1.4) {
      mnemIndex = b.getDisplayedMnemonicIndex();
    } else {
      mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
    }
    int offs = 0;
    if (model.isArmed() && model.isPressed()) {
      offs = 1;
    }

    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
    g2D.setComposite(alpha);
    Color foreground = b.getForeground();
    Color background = b.getBackground();
    if (background instanceof ColorUIResource) {
      if (model.isPressed() && model.isArmed()) {
        foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor();
      } else if (model.isRollover()) {
        foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor();
      }
    }
    if (!model.isEnabled()) {
      foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
    }
    if (ColorHelper.getGrayValue(foreground) > 64) {
      g2D.setColor(Color.black);
    } else {
      g2D.setColor(Color.white);
    }
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1);
    g2D.setComposite(composite);
    g2D.setColor(foreground);
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent());
  }
 protected void paintText(Graphics g, JComponent c, String text, Rectangle textRect) {
   View v = (View) c.getClientProperty(BasicHTML.propertyKey);
   if (v != null) {
     v.paint(g, textRect);
   } else {
     AbstractButton b = (AbstractButton) c;
     ButtonModel model = b.getModel();
     int mnemIndex = -1;
     if (JTattooUtilities.getJavaVersion() >= 1.4) {
       mnemIndex = b.getDisplayedMnemonicIndex();
     } else {
       mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
     }
     Font f = c.getFont();
     g.setFont(f);
     FontMetrics fm = g.getFontMetrics();
     if (model.isEnabled()) {
       Color fc = b.getForeground();
       if (AbstractLookAndFeel.getTheme().isTextShadowOn() && ColorHelper.getGrayValue(fc) > 128) {
         g.setColor(Color.black);
         JTattooUtilities.drawStringUnderlineCharAt(
             c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent());
       }
       g.setColor(fc);
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
     } else {
       g.setColor(Color.black);
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x + 1, textRect.y + 1 + fm.getAscent());
       g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
       JTattooUtilities.drawStringUnderlineCharAt(
           c, g, text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
     }
   }
 }