Ejemplo n.º 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);
    }
  }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
0
  /** {@inheritDoc} */
  @Override
  public Dimension getMaximumSize(JComponent c) {
    if (c.getComponentCount() > 0 && c.getLayout() != null) {
      return null;
    }

    AbstractButton b = (AbstractButton) c;
    SynthContext ss = getContext(c);
    Dimension size =
        ss.getStyle()
            .getGraphicsUtils(ss)
            .getMaximumSize(
                ss,
                ss.getStyle().getFont(ss),
                b.getText(),
                getSizingIcon(b),
                b.getHorizontalAlignment(),
                b.getVerticalAlignment(),
                b.getHorizontalTextPosition(),
                b.getVerticalTextPosition(),
                b.getIconTextGap(),
                b.getDisplayedMnemonicIndex());

    return size;
  }
  /**
   * 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);
    }
  }
Ejemplo n.º 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());
    }
  }
Ejemplo n.º 6
0
  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());
  }
Ejemplo n.º 7
0
  /**
   * Paints the specified component.
   *
   * @param context context for the component being painted
   * @param g the {@code Graphics} object used for painting
   * @see #update(Graphics,JComponent)
   */
  protected void paint(SynthContext context, Graphics g) {
    AbstractButton b = (AbstractButton) context.getComponent();

    g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
    g.setFont(style.getFont(context));
    context
        .getStyle()
        .getGraphicsUtils(context)
        .paintText(
            context,
            g,
            b.getText(),
            getIcon(b),
            b.getHorizontalAlignment(),
            b.getVerticalAlignment(),
            b.getHorizontalTextPosition(),
            b.getVerticalTextPosition(),
            b.getIconTextGap(),
            b.getDisplayedMnemonicIndex(),
            getTextShiftOffset(context));
  }
Ejemplo n.º 8
0
 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());
     }
   }
 }