コード例 #1
0
ファイル: SynthButtonUI.java プロジェクト: FauxFaux/jdk9-jdk
  /** {@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;
  }
コード例 #2
0
ファイル: SynthButtonUI.java プロジェクト: FauxFaux/jdk9-jdk
  /** {@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;
  }
コード例 #3
0
ファイル: SynthButtonUI.java プロジェクト: FauxFaux/jdk9-jdk
  /**
   * 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));
  }