Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
 @Override
 public synchronized void paint(final Graphics g, final JComponent c) {
   final Map hints = SwingUtils.setupTextAntialias(g);
   super.paint(g, c);
   SwingUtils.restoreTextAntialias(g, hints);
 }