예제 #1
0
 private static int getProgressBarBaseline(JProgressBar pb, int height) {
   if (pb.isStringPainted() && pb.getOrientation() == JProgressBar.HORIZONTAL) {
     FontMetrics metrics = pb.getFontMetrics(pb.getFont());
     Insets insets = pb.getInsets();
     int y = insets.top;
     if (isWindows() && isXP()) {
       if (pb.isIndeterminate()) {
         y = -1;
         height--;
       } else {
         y = 0;
         height -= 3;
       }
     } else if (isGTK()) {
       return (height - metrics.getAscent() - metrics.getDescent()) / 2 + metrics.getAscent();
     } else if (isAqua()) {
       if (pb.isIndeterminate()) {
         // Aqua doesn't appear to support text on indeterminate
         // progress bars.
         return -1;
       }
       y -= 1;
       height -= (insets.top + insets.bottom);
     } else {
       height -= insets.top + insets.bottom;
     }
     return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2;
   }
   return -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());
  }
예제 #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);
    }
  }
예제 #4
0
  public void paintText(Graphics2D g, ButtonInfo info) {
    ButtonModel model = info.button.getModel();
    FontMetrics fm = info.button.getFontMetrics(info.button.getFont());
    int mnemonicIndex = info.button.getDisplayedMnemonicIndex();
    String text = info.button.getText();
    int textShiftOffset = 0;

    g.setComposite(AlphaComposite.SrcOver);
    /* Draw the Text */
    if (isEnabled(info.button)) {
      /** * paint the text normally */
      g.setColor(info.button.getForeground());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          info.textRect.x + textShiftOffset,
          info.textRect.y + fm.getAscent() + textShiftOffset);
    } else {
      /** * paint the text disabled ** */
      g.setColor(info.button.getBackground().brighter());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x, info.textRect.y + fm.getAscent());
      g.setColor(info.button.getBackground().darker());
      BasicGraphicsUtils.drawStringUnderlineCharAt(
          g, text, mnemonicIndex, info.textRect.x - 1, info.textRect.y + fm.getAscent() - 1);
    }
  }
예제 #5
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);
    }
  }
예제 #6
0
  /** Returns the baseline for buttons. */
  private static int getButtonBaseline(AbstractButton button, int height) {
    FontMetrics fm = button.getFontMetrics(button.getFont());

    resetRects(button, height);

    String text = button.getText();
    if (text != null && text.startsWith("<html>")) {
      return -1;
    }
    // NOTE: that we use "a" here to make sure we get a valid value, if
    // we were to pass in an empty string or null we would not get
    // back the right thing.
    SwingUtilities.layoutCompoundLabel(
        button,
        fm,
        "a",
        button.getIcon(),
        button.getVerticalAlignment(),
        button.getHorizontalAlignment(),
        button.getVerticalTextPosition(),
        button.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        text == null ? 0 : button.getIconTextGap());

    if (isAqua()) {
      return textRect.y + fm.getAscent() + 1;
    }
    return textRect.y + fm.getAscent();
  }
  private void drawSkillName(
      Graphics g, String skillText, Rectangle2D textRect, int skillBoxY, int skillBoxX) {
    // Get width and Y pos.
    int skillNameWidth = (int) textRect.getWidth();
    int skillStringY = skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent();

    // if text is 2 long for the box... Split that shit up boiii
    if (skillNameWidth > skillBoxSize) {
      // Split by whitespace
      String[] arr = skillText.split(" ");
      String curr;
      Rectangle2D textRect2;

      // Loop thru each substring from the end and draw appropriately
      for (int j = arr.length - 1; j >= 0; j--) {
        curr = arr[j];
        textRect = fm.getStringBounds(curr, g);
        // If this substring is less than half the width of the box and theres anotha substring
        if ((int) textRect.getWidth() < skillBoxSize / 2 && j != 0) {
          // Get and measure the otha 1
          String anotha1 = arr[j - 1];
          textRect2 = fm.getStringBounds(anotha1, g);

          // Draw both on the same line if can fit
          int combinedW = (int) textRect.getWidth() + (int) textRect2.getWidth() + 2;
          String combined = anotha1 + " " + curr;
          if (combinedW < skillBoxSize) {
            g.drawString(combined, skillBoxX + (skillBoxSize - combinedW) / 2, skillStringY);
            j--;
          }
          // Otherwise, draw one of those suckas
          else {
            g.drawString(
                curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY);
          }
        }
        // Otherwise, draw one of those suckas
        else {
          g.drawString(
              curr, skillBoxX + (skillBoxSize - (int) textRect.getWidth()) / 2, skillStringY);
        }

        // Decrease dat Y
        skillStringY -= (int) textRect.getHeight();
      }

    } else {
      g.drawString(
          skillText,
          skillBoxX + (skillBoxSize - skillNameWidth) / 2,
          skillBoxY + (skillRectHeight - (int) textRect.getHeight()) + fm.getAscent());
    }
  }
  public Rectangle getVisualBounds(JComponent c, int type, int width, int height) {
    Rectangle bounds = new Rectangle(0, 0, width, height);
    if (type == VisuallyLayoutable.CLIP_BOUNDS) {
      return bounds;
    }

    AbstractButton b = (AbstractButton) c;

    if (type == VisuallyLayoutable.COMPONENT_BOUNDS
        && b.getBorder() != null
        && b.isBorderPainted()) {
      Border border = b.getBorder();
      if (border instanceof BackgroundBorder) {
        border = ((BackgroundBorder) border).getBackgroundBorder();
        if (border instanceof VisualMargin) {
          InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds);
        } else if (border instanceof QuaquaButtonBorder) {
          InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds);
        }
      }
      return bounds;
    }

    String text = b.getText();
    boolean isEmpty = (text == null || text.length() == 0);
    if (isEmpty) {
      text = " ";
    }
    Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    FontMetrics fm = c.getFontMetrics(c.getFont());
    Insets insets = c.getInsets(viewInsets);

    viewR.x = insets.left;
    viewR.y = insets.top;
    viewR.width = width - (insets.left + insets.right);
    viewR.height = height - (insets.top + insets.bottom);

    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR);

    Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c);
    if (isEmpty) {
      textBounds.width = 0;
    }
    int ascent = fm.getAscent();
    textR.x += textBounds.x;
    textR.width = textBounds.width;
    textR.y += ascent + textBounds.y;
    textR.height -= fm.getHeight() - textBounds.height;

    bounds.setBounds(textR);
    return bounds;
  }
예제 #9
0
  private void drawYLabel(Graphics g) {
    g.setFont(fontBold);

    // # radians to rotate.
    double theta = -Math.PI / 2;

    Rectangle plotRect = getPlotRect();
    /*
     The y axis laabel.
    */
    String yLabel = "True Positive Fraction";
    int stringWidth = fm.stringWidth(yLabel);

    // where to begin drawing (the rotated image)
    Point translate =
        new Point(fm.getAscent(), plotRect.y + (plotRect.height / 2 + stringWidth / 2));

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform save = g2.getTransform();

    g2.translate(translate.x, translate.y);
    g2.rotate(theta);

    g2.setColor(boundaryColor);
    g2.drawString(yLabel, 0, 0);

    g2.setTransform(save);
  }
예제 #10
0
  public void paint(Graphics g) {
    m_fm = g.getFontMetrics();

    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());
    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

    g.setColor(getForeground());
    g.setFont(getFont());
    m_insets = getInsets();
    int x = m_insets.left;
    int y = m_insets.top + m_fm.getAscent();

    StringTokenizer st = new StringTokenizer(getText(), "\t");
    while (st.hasMoreTokens()) {
      String sNext = st.nextToken();
      g.drawString(sNext, x, y);
      x += m_fm.stringWidth(sNext);

      if (!st.hasMoreTokens()) break;
      int index = 0;
      while (x >= getTab(index)) index++;
      x = getTab(index);
    }
  }
 protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) {
   JButtonLinkA bn = (JButtonLinkA) com;
   ButtonModel bnModel = bn.getModel();
   Color color = bn.getForeground();
   Object obj = null;
   if (bnModel.isEnabled()) {
     if (bnModel.isPressed()) bn.setForeground(bn.getActiveLinkColor());
     else if (bn.isLinkVisited()) bn.setForeground(bn.getVisitedLinkColor());
     else bn.setForeground(bn.getLinkColor());
   } else {
     if (bn.getDisabledLinkColor() != null) bn.setForeground(bn.getDisabledLinkColor());
   }
   super.paintText(g, com, rect, s);
   int behaviour = bn.getLinkBehavior();
   boolean drawLine = false;
   if (behaviour == JButtonLinkA.HOVER_UNDERLINE) {
     if (bnModel.isRollover()) drawLine = true;
   } else if (behaviour == JButtonLinkA.ALWAYS_UNDERLINE
       || behaviour == JButtonLinkA.SYSTEM_DEFAULT) drawLine = true;
   if (!drawLine) return;
   FontMetrics fm = g.getFontMetrics();
   int x = rect.x + getTextShiftOffset();
   int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1;
   if (bnModel.isEnabled()) {
     g.setColor(bn.getForeground());
     g.drawLine(x, y, (x + rect.width) - 1, y);
   } else {
     g.setColor(bn.getBackground().brighter());
     g.drawLine(x, y, (x + rect.width) - 1, y);
   }
 }
예제 #12
0
 private static int getAquaTabbedPaneBaseline(JTabbedPane tp, int height) {
   Font font = tp.getFont();
   FontMetrics metrics = tp.getFontMetrics(font);
   int ascent = metrics.getAscent();
   int offset;
   switch (tp.getTabPlacement()) {
     case JTabbedPane.TOP:
       offset = 5;
       if (tp.getFont().getSize() > 12) {
         offset = 6;
       }
       int yOffset = 20 - metrics.getHeight();
       yOffset /= 2;
       return offset + yOffset + ascent - 1;
     case JTabbedPane.BOTTOM:
       if (tp.getFont().getSize() > 12) {
         offset = 6;
       } else {
         offset = 4;
       }
       return height - (20 - ((20 - metrics.getHeight()) / 2 + ascent)) - offset;
     case JTabbedPane.LEFT:
     case JTabbedPane.RIGHT:
       // Aqua rotates left/right text, so that there isn't a good
       // baseline.
       return -1;
   }
   return -1;
 }
  public void paintComponent(Graphics g) {
    Icon icon = getIcon();
    FontMetrics fm = getFontMetrics(getFont());
    Rectangle viewRect = new Rectangle(getSize());
    JBInsets.removeFrom(viewRect, getInsets());

    Rectangle iconRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    String text =
        SwingUtilities.layoutCompoundLabel(
            this,
            fm,
            getText(),
            icon,
            SwingConstants.CENTER,
            horizontalTextAlignment(),
            SwingConstants.CENTER,
            horizontalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            iconTextSpace());
    ActionButtonLook look = ActionButtonLook.IDEA_LOOK;
    look.paintBackground(g, this);
    look.paintIconAt(g, this, icon, iconRect.x, iconRect.y);
    look.paintBorder(g, this);

    UISettings.setupAntialiasing(g);
    g.setColor(isButtonEnabled() ? getForeground() : getInactiveTextColor());
    SwingUtilities2.drawStringUnderlineCharAt(
        this, g, text, getMnemonicCharIndex(text), textRect.x, textRect.y + fm.getAscent());
  }
예제 #14
0
  /**
   * The function prints out key to jumpshot data.
   */
  int print (Graphics g, int x, int y, int width, int height) {
    Font f = g.getFont ();
    FontMetrics fm = getToolkit ().getFontMetrics (f);
    
    int charW = fm.stringWidth (" "), charH = fm.getHeight ();
    int hgap1 = charW, hgap2 = 2 * charW, vgap = fm.getAscent ();
    int rectW = 30, rectH = charH; //Dimensions of state rectangles
    int xcord = x, ycord = y;
    
    Enumeration enum = parent.stateDefs.elements ();
    while (enum.hasMoreElements ()) {
      RecDef s = (RecDef)enum.nextElement ();
      
      if (s.stateVector.size () > 0) {
	int strW = fm.stringWidth (s.description);
	
	if ((xcord + rectW + hgap1 + strW) > (width + x)) {
          xcord = x; ycord += (charH + vgap);
        }
        
        g.setColor (s.color);
        g.fillRect (xcord, ycord, rectW, rectH);
        g.setColor (Color.black);
        g.drawRect (xcord, ycord, rectW - 1, rectH - 1);
        g.drawString( s.description,
                      xcord + rectW + hgap1,
                      ycord + rectH - fm.getDescent () - 1);
        xcord += (rectW + hgap1 + strW + hgap2);
      }
    }
    return (ycord - y + (2 * charH));
  }      
  /**
   * 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);
    }
  }
예제 #16
0
 @Override
 public int getBaseline() {
   FontMetrics fm = b.getFontMetrics(b.getFont());
   int border = (b.getPreferredSize().height - fm.getHeight()) / 2;
   int bestGuess = border + fm.getAscent();
   if (PlatformUtils.isMac()) bestGuess -= 1;
   return bestGuess;
 }
예제 #17
0
 static void paintDropShadowText(
     final Graphics g,
     final JComponent c,
     final Font font,
     final FontMetrics metrics,
     final int x,
     final int y,
     final int offsetX,
     final int offsetY,
     final Color textColor,
     final Color shadowColor,
     final String text) {
   g.setFont(font);
   g.setColor(shadowColor);
   SwingUtilities2.drawString(c, g, text, x + offsetX, y + offsetY + metrics.getAscent());
   g.setColor(textColor);
   SwingUtilities2.drawString(c, g, text, x, y + metrics.getAscent());
 }
예제 #18
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());
    }
  }
  /**
   * Designate the place where the progress string will be painted. This implementation places it at
   * the center of the progress bar (in both x and y). Override this if you want to right, left,
   * top, or bottom align the progress string or if you need to nudge it around for any reason.
   */
  protected Point getStringPlacement(
      Graphics g, String progressString, int x, int y, int width, int height) {
    FontMetrics fontSizer = SwingUtilities2.getFontMetrics(progressBar, g, progressBar.getFont());
    int stringWidth = SwingUtilities2.stringWidth(progressBar, fontSizer, progressString);

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      return new Point(
          x + Math.round(width / 2 - stringWidth / 2),
          y
              + ((height + fontSizer.getAscent() - fontSizer.getLeading() - fontSizer.getDescent())
                  / 2));
    } else { // VERTICAL
      return new Point(
          x
              + ((width - fontSizer.getAscent() + fontSizer.getLeading() + fontSizer.getDescent())
                  / 2),
          y + Math.round(height / 2 - stringWidth / 2));
    }
  }
예제 #20
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
예제 #21
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());
  }
예제 #22
0
 /**
  * Returns the baseline.
  *
  * @throws NullPointerException {@inheritDoc}
  * @throws IllegalArgumentException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public int getBaseline(JComponent c, int width, int height) {
   super.getBaseline(c, width, height);
   AbstractButton b = (AbstractButton) c;
   String text = b.getText();
   if (text == null || "".equals(text)) {
     return -1;
   }
   FontMetrics fm = b.getFontMetrics(b.getFont());
   layout(b, fm, width, height);
   return BasicHTML.getBaseline(b, textRect.y, fm.getAscent(), textRect.width, textRect.height);
 }
 /**
  * Returns the baseline.
  *
  * @throws NullPointerException {@inheritDoc}
  * @throws IllegalArgumentException {@inheritDoc}
  * @see javax.swing.JComponent#getBaseline(int, int)
  * @since 1.6
  */
 public int getBaseline(JComponent c, int width, int height) {
   super.getBaseline(c, width, height);
   if (progressBar.isStringPainted() && progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
     FontMetrics metrics = progressBar.getFontMetrics(progressBar.getFont());
     Insets insets = progressBar.getInsets();
     int y = insets.top;
     height = height - insets.top - insets.bottom;
     return y + (height + metrics.getAscent() - metrics.getLeading() - metrics.getDescent()) / 2;
   }
   return -1;
 }
 @Override
 protected void paintDisabledText(
     Graphics g, String text, JComponent c, Rectangle textRect, FontMetrics metrics) {
   int x = textRect.x + getTextShiftOffset();
   int y = textRect.y + metrics.getAscent() + getTextShiftOffset();
   if (isDefaultButton(c)) {
     g.setColor(Gray.xCC);
   } else {
     g.setColor(UIManager.getColor("Button.disabledText"));
   }
   SwingUtilities2.drawStringUnderlineCharAt(c, g, text, -1, x, y);
 }
예제 #25
0
  /** {@inheritDoc} */
  @Override
  public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
      throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
      throw new IllegalArgumentException("Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton) c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
      return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context
        .getStyle()
        .getGraphicsUtils(context)
        .layoutText(
            context,
            fm,
            b.getText(),
            b.getIcon(),
            b.getHorizontalAlignment(),
            b.getVerticalAlignment(),
            b.getHorizontalTextPosition(),
            b.getVerticalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            b.getIconTextGap());
    View view = (View) b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
      baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
      if (baseline >= 0) {
        baseline += textRect.y;
      }
    } else {
      baseline = textRect.y + fm.getAscent();
    }
    return baseline;
  }
예제 #26
0
 /**
  * This deals with a bug/peculiarity for the default Mac font: several pixels of the ascent are
  * actually empty. This screws up certain measurements which assume the font is actually a few
  * pixels taller than it really is.
  */
 private static int getUnusedAscent(FontMetrics fm, Font font) {
   Integer value = ascentTable.get(font);
   if (value == null) {
     int recordedAscent = fm.getAscent();
     FontRenderContext frc = new FontRenderContext(new AffineTransform(), false, false);
     GlyphVector gv = font.createGlyphVector(frc, "XYZ");
     Rectangle2D bounds = ShapeBounds.getBounds(gv.getOutline());
     int observedAscent = (int) (Math.ceil(bounds.getHeight()) + .5);
     value = new Integer(recordedAscent - observedAscent);
     ascentTable.put(font, value);
   }
   return value.intValue();
 }
예제 #27
0
 private void measure() {
   FontMetrics fontmetrics = getFontMetrics(getFont());
   if (fontmetrics == null) return;
   line_height = fontmetrics.getHeight();
   line_ascent = fontmetrics.getAscent();
   max_width = 0;
   for (int i = 0; i < num_lines; i++) {
     line_widths[i] = fontmetrics.stringWidth(lines[i]);
     if (line_widths[i] > max_width) max_width = line_widths[i];
   }
   max_width += 2 * btnMarginWidth;
   max_height = num_lines * line_height + 2 * btnMarginHeight;
 }
예제 #28
0
  /** {@inheritDoc} */
  @Override
  public void paint(final Graphics2D g2d, final Rectangle bounds, final E label) {
    // Applying graphics settings
    final Composite oc = LafUtils.setupAlphaComposite(g2d, transparency, transparency != null);
    final Map textHints =
        drawShade ? StyleConstants.defaultTextRenderingHints : StyleConstants.textRenderingHints;
    final Font oldFont = LafUtils.setupFont(g2d, label.getFont());
    final Map oldHints = SwingUtils.setupTextAntialias(g2d, textHints);

    // Retrieving icon & text
    final String text = label.getText();
    final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    // Painting background
    if (backgroundPainter != null) {
      backgroundPainter.paint(g2d, bounds, label);
    }

    // We don't need to go futher if there is not icon/text
    if (icon == null && text == null) {
      return;
    }

    final FontMetrics fm = label.getFontMetrics(label.getFont());
    final String clippedText = layout(label, fm, label.getWidth(), label.getHeight());

    if (icon != null) {
      icon.paintIcon(label, g2d, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      final View v = (View) label.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        // Painting HTML label view
        v.paint(g2d, paintTextR);
      } else {
        // Painting plain label view
        final int textX = paintTextR.x;
        final int textY = paintTextR.y + fm.getAscent();
        if (label.isEnabled()) {
          paintEnabledText(label, g2d, clippedText, textX, textY);
        } else {
          paintDisabledText(label, g2d, clippedText, textX, textY);
        }
      }
    }

    SwingUtils.restoreTextAntialias(g2d, oldHints);
    LafUtils.restoreFont(g2d, oldFont);
    LafUtils.restoreComposite(g2d, oc, transparency != null);
  }
예제 #29
0
 private static int getPanelBaseline(JPanel panel, int height) {
   Border border = panel.getBorder();
   if (border instanceof TitledBorder) {
     TitledBorder titledBorder = (TitledBorder) border;
     if (titledBorder.getTitle() != null && !"".equals(titledBorder.getTitle())) {
       Font font = titledBorder.getTitleFont();
       if (font == null) {
         font = panel.getFont();
         if (font == null) {
           font = new Font("Dialog", Font.PLAIN, 12);
         }
       }
       Border border2 = titledBorder.getBorder();
       Insets borderInsets;
       if (border2 != null) {
         borderInsets = border2.getBorderInsets(panel);
       } else {
         borderInsets = EMPTY_INSETS;
       }
       FontMetrics fm = panel.getFontMetrics(font);
       int fontHeight = fm.getHeight();
       int descent = fm.getDescent();
       int ascent = fm.getAscent();
       int y = EDGE_SPACING;
       int h = height - EDGE_SPACING * 2;
       int diff;
       switch (((TitledBorder) border).getTitlePosition()) {
         case TitledBorder.ABOVE_TOP:
           diff = ascent + descent + (Math.max(EDGE_SPACING, TEXT_SPACING * 2) - EDGE_SPACING);
           return y + diff - (descent + TEXT_SPACING);
         case TitledBorder.TOP:
         case TitledBorder.DEFAULT_POSITION:
           diff = Math.max(0, ((ascent / 2) + TEXT_SPACING) - EDGE_SPACING);
           return (y + diff - descent) + (borderInsets.top + ascent + descent) / 2;
         case TitledBorder.BELOW_TOP:
           return y + borderInsets.top + ascent + TEXT_SPACING;
         case TitledBorder.ABOVE_BOTTOM:
           return (y + h) - (borderInsets.bottom + descent + TEXT_SPACING);
         case TitledBorder.BOTTOM:
           h -= fontHeight / 2;
           return ((y + h) - descent) + ((ascent + descent) - borderInsets.bottom) / 2;
         case TitledBorder.BELOW_BOTTOM:
           h -= fontHeight;
           return y + h + ascent + TEXT_SPACING;
       }
     }
   }
   return -1;
 }
예제 #30
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());
     }
   }
 }