Пример #1
0
  private static int getLabelBaseline(JLabel label, int height) {
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    FontMetrics fm = label.getFontMetrics(label.getFont());

    resetRects(label, height);

    SwingUtilities.layoutCompoundLabel(
        label,
        fm,
        "a",
        icon,
        label.getVerticalAlignment(),
        label.getHorizontalAlignment(),
        label.getVerticalTextPosition(),
        label.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        label.getIconTextGap());

    return textRect.y + fm.getAscent();
  }
Пример #2
0
  /**
   * {@inheritDoc}
   *
   * @since 1.7
   */
  public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
    if (!isShowing()) {
      return false;
    }

    // Check that there is a label with such image
    Enumeration elements = labelTable.elements();

    while (elements.hasMoreElements()) {
      Component component = (Component) elements.nextElement();

      if (component instanceof JLabel) {
        JLabel label = (JLabel) component;

        if (SwingUtilities.doesIconReferenceImage(label.getIcon(), img)
            || SwingUtilities.doesIconReferenceImage(label.getDisabledIcon(), img)) {
          return super.imageUpdate(img, infoflags, x, y, w, h);
        }
      }
    }

    return false;
  }
Пример #3
0
  public void paint(final Graphics graphics, final JComponent comp) {

    final JLabel label = (JLabel) comp;

    if (label.getWidth() > label.getHeight() && !alwaysVertical) {
      super.paint(graphics, comp);
    } else {
      final String text = label.getText();
      final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

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

      final FontMetrics fontMetrics = graphics.getFontMetrics();
      paintViewInsets = comp.getInsets(paintViewInsets);

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

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

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

      final String clippedText =
          layoutCL(label, fontMetrics, text, icon, paintViewR, paintIconR, paintTextR);

      final Graphics2D g2D = (Graphics2D) graphics;
      final AffineTransform oldTransform = g2D.getTransform();
      if (clockwise) {
        g2D.rotate(Math.PI / 2);
        g2D.translate(0, -comp.getWidth());
      } else {
        g2D.rotate(-Math.PI / 2);
        g2D.translate(-comp.getHeight(), 0);
      }

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

      if (text != null) {
        final View view = (View) comp.getClientProperty(BasicHTML.propertyKey);

        if (view == null) {
          final int textX = paintTextR.x;
          final int textY = paintTextR.y + fontMetrics.getAscent();

          if (label.isEnabled()) {
            paintEnabledText(label, graphics, clippedText, textX, textY);
          } else {
            paintDisabledText(label, graphics, clippedText, textX, textY);
          }
        } else {
          view.paint(graphics, paintTextR);
        }
      }

      g2D.setTransform(oldTransform);
    }
  }