Search in sources :

Example 46 with FontMetrics

use of java.awt.FontMetrics in project drmips by brunonova.

the class IOPortTip method resize.

private void resize() {
    FontMetrics fm = getFontMetrics(FONT);
    int w = fm.stringWidth(getText()) + 4;
    int h = fm.getHeight() + 4;
    setSize(w, h);
}
Also used : FontMetrics(java.awt.FontMetrics) Point(java.awt.Point)

Example 47 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class DefaultTableCellHeaderRenderer method computeIconPosition.

private Point computeIconPosition(Graphics g) {
    FontMetrics fontMetrics = g.getFontMetrics();
    Rectangle viewR = new Rectangle();
    Rectangle textR = new Rectangle();
    Rectangle iconR = new Rectangle();
    Insets i = getInsets();
    viewR.x = i.left;
    viewR.y = i.top;
    viewR.width = getWidth() - (i.left + i.right);
    viewR.height = getHeight() - (i.top + i.bottom);
    SwingUtilities.layoutCompoundLabel(this, fontMetrics, getText(), sortArrow, getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), viewR, iconR, textR, getIconTextGap());
    int x = getWidth() - i.right - sortArrow.getIconWidth();
    int y = iconR.y;
    return new Point(x, y);
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 48 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class XFramePeer method print.

/*
     * Print the native component by rendering the Motif look ourselves.
     * We also explicitly print the MenuBar since a MenuBar isn't a subclass
     * of Component (and thus it has no "print" method which gets called by
     * default).
     */
public void print(Graphics g) {
    super.print(g);
    Frame f = (Frame) target;
    Insets finsets = f.getInsets();
    Dimension fsize = f.getSize();
    Color bg = f.getBackground();
    Color fg = f.getForeground();
    Color highlight = bg.brighter();
    Color shadow = bg.darker();
    if (hasDecorations(XWindowAttributesData.AWT_DECOR_BORDER)) {
        // pure white
        if (highlight.equals(Color.white)) {
            g.setColor(new Color(230, 230, 230));
        } else {
            g.setColor(highlight);
        }
        g.drawLine(0, 0, fsize.width, 0);
        g.drawLine(0, 1, fsize.width - 1, 1);
        // left outer
        // if (highlight.equals(Color.white)) {
        //     g.setColor(new Color(230, 230, 230));
        // }
        // else {
        //     g.setColor(highlight);
        // }
        g.drawLine(0, 0, 0, fsize.height);
        g.drawLine(1, 0, 1, fsize.height - 1);
        // bottom cross-hair
        g.setColor(highlight);
        g.drawLine(CROSSHAIR_INSET + 1, fsize.height - CROSSHAIR_INSET, fsize.width - CROSSHAIR_INSET, fsize.height - CROSSHAIR_INSET);
        // right cross-hair
        // g.setColor(highlight);
        g.drawLine(fsize.width - CROSSHAIR_INSET, CROSSHAIR_INSET + 1, fsize.width - CROSSHAIR_INSET, fsize.height - CROSSHAIR_INSET);
        // bottom outer
        g.setColor(shadow);
        g.drawLine(1, fsize.height, fsize.width, fsize.height);
        g.drawLine(2, fsize.height - 1, fsize.width, fsize.height - 1);
        // right outer
        // g.setColor(shadow);
        g.drawLine(fsize.width, 1, fsize.width, fsize.height);
        g.drawLine(fsize.width - 1, 2, fsize.width - 1, fsize.height);
        // top cross-hair
        // g.setColor(shadow);
        g.drawLine(CROSSHAIR_INSET, CROSSHAIR_INSET, fsize.width - CROSSHAIR_INSET, CROSSHAIR_INSET);
        // left cross-hair
        // g.setColor(shadow);
        g.drawLine(CROSSHAIR_INSET, CROSSHAIR_INSET, CROSSHAIR_INSET, fsize.height - CROSSHAIR_INSET);
    }
    if (hasDecorations(XWindowAttributesData.AWT_DECOR_TITLE)) {
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_MENU)) {
            // system menu
            g.setColor(bg);
            g.fill3DRect(SYS_MENU_X, BUTTON_Y, BUTTON_W, BUTTON_H, true);
            g.fill3DRect(SYS_MENU_CONTAINED_X, SYS_MENU_CONTAINED_Y, SYS_MENU_CONTAINED_W, SYS_MENU_CONTAINED_H, true);
        }
        // title bar
        // g.setColor(bg);
        g.fill3DRect(TITLE_X, BUTTON_Y, fsize.width - TITLE_W_DIFF, BUTTON_H, true);
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_MINIMIZE)) {
            // minimize button
            // g.setColor(bg);
            g.fill3DRect(fsize.width - MINIMIZE_X_DIFF, BUTTON_Y, BUTTON_W, BUTTON_H, true);
            g.fill3DRect(fsize.width - MINIMIZE_CONTAINED_X_DIFF, MINIMIZE_CONTAINED_Y, MINIMIZE_CONTAINED_W, MINIMIZE_CONTAINED_H, true);
        }
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_MAXIMIZE)) {
            // maximize button
            // g.setColor(bg);
            g.fill3DRect(fsize.width - MAXIMIZE_X_DIFF, BUTTON_Y, BUTTON_W, BUTTON_H, true);
            g.fill3DRect(fsize.width - MAXIMIZE_CONTAINED_X_DIFF, MAXIMIZE_CONTAINED_Y, MAXIMIZE_CONTAINED_W, MAXIMIZE_CONTAINED_H, true);
        }
        // title bar text
        g.setColor(fg);
        Font sysfont = new Font(Font.SANS_SERIF, Font.PLAIN, 10);
        g.setFont(sysfont);
        FontMetrics sysfm = g.getFontMetrics();
        String ftitle = f.getTitle();
        g.drawString(ftitle, ((TITLE_X + TITLE_X + fsize.width - TITLE_W_DIFF) / 2) - (sysfm.stringWidth(ftitle) / 2), TITLE_MID_Y + sysfm.getMaxDescent());
    }
    if (f.isResizable() && hasDecorations(XWindowAttributesData.AWT_DECOR_RESIZEH)) {
        // add resize cross hairs
        // upper-left horiz (shadow)
        g.setColor(shadow);
        g.drawLine(1, HORIZ_RESIZE_INSET, CROSSHAIR_INSET, HORIZ_RESIZE_INSET);
        // upper-left vert (shadow)
        // g.setColor(shadow);
        g.drawLine(VERT_RESIZE_INSET, 1, VERT_RESIZE_INSET, CROSSHAIR_INSET);
        // upper-right horiz (shadow)
        // g.setColor(shadow);
        g.drawLine(fsize.width - CROSSHAIR_INSET + 1, HORIZ_RESIZE_INSET, fsize.width, HORIZ_RESIZE_INSET);
        // upper-right vert (shadow)
        // g.setColor(shadow);
        g.drawLine(fsize.width - VERT_RESIZE_INSET - 1, 2, fsize.width - VERT_RESIZE_INSET - 1, CROSSHAIR_INSET + 1);
        // lower-left horiz (shadow)
        // g.setColor(shadow);
        g.drawLine(1, fsize.height - HORIZ_RESIZE_INSET - 1, CROSSHAIR_INSET, fsize.height - HORIZ_RESIZE_INSET - 1);
        // lower-left vert (shadow)
        // g.setColor(shadow);
        g.drawLine(VERT_RESIZE_INSET, fsize.height - CROSSHAIR_INSET + 1, VERT_RESIZE_INSET, fsize.height);
        // lower-right horiz (shadow)
        // g.setColor(shadow);
        g.drawLine(fsize.width - CROSSHAIR_INSET + 1, fsize.height - HORIZ_RESIZE_INSET - 1, fsize.width, fsize.height - HORIZ_RESIZE_INSET - 1);
        // lower-right vert (shadow)
        // g.setColor(shadow);
        g.drawLine(fsize.width - VERT_RESIZE_INSET - 1, fsize.height - CROSSHAIR_INSET + 1, fsize.width - VERT_RESIZE_INSET - 1, fsize.height);
        // upper-left horiz (highlight)
        g.setColor(highlight);
        g.drawLine(2, HORIZ_RESIZE_INSET + 1, CROSSHAIR_INSET, HORIZ_RESIZE_INSET + 1);
        // upper-left vert (highlight)
        // g.setColor(highlight);
        g.drawLine(VERT_RESIZE_INSET + 1, 2, VERT_RESIZE_INSET + 1, CROSSHAIR_INSET);
        // upper-right horiz (highlight)
        // g.setColor(highlight);
        g.drawLine(fsize.width - CROSSHAIR_INSET + 1, HORIZ_RESIZE_INSET + 1, fsize.width - 1, HORIZ_RESIZE_INSET + 1);
        // upper-right vert (highlight)
        // g.setColor(highlight);
        g.drawLine(fsize.width - VERT_RESIZE_INSET, 2, fsize.width - VERT_RESIZE_INSET, CROSSHAIR_INSET);
        // lower-left horiz (highlight)
        // g.setColor(highlight);
        g.drawLine(2, fsize.height - HORIZ_RESIZE_INSET, CROSSHAIR_INSET, fsize.height - HORIZ_RESIZE_INSET);
        // lower-left vert (highlight)
        // g.setColor(highlight);
        g.drawLine(VERT_RESIZE_INSET + 1, fsize.height - CROSSHAIR_INSET + 1, VERT_RESIZE_INSET + 1, fsize.height - 1);
        // lower-right horiz (highlight)
        // g.setColor(highlight);
        g.drawLine(fsize.width - CROSSHAIR_INSET + 1, fsize.height - HORIZ_RESIZE_INSET, fsize.width - 1, fsize.height - HORIZ_RESIZE_INSET);
        // lower-right vert (highlight)
        // g.setColor(highlight);
        g.drawLine(fsize.width - VERT_RESIZE_INSET, fsize.height - CROSSHAIR_INSET + 1, fsize.width - VERT_RESIZE_INSET, fsize.height - 1);
    }
    XMenuBarPeer peer = menubarPeer;
    if (peer != null) {
        Insets insets = getInsets();
        Graphics ng = g.create();
        int menubarX = 0;
        int menubarY = 0;
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_BORDER)) {
            menubarX += CROSSHAIR_INSET + 1;
            menubarY += CROSSHAIR_INSET + 1;
        }
        if (hasDecorations(XWindowAttributesData.AWT_DECOR_TITLE)) {
            menubarY += BUTTON_H;
        }
        try {
            ng.translate(menubarX, menubarY);
            peer.print(ng);
        } finally {
            ng.dispose();
        }
    }
}
Also used : Graphics(java.awt.Graphics) Frame(java.awt.Frame) Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Dimension(java.awt.Dimension) Font(java.awt.Font)

Example 49 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class BasicLabelUI method getBaseline.

/**
     * 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);
    JLabel label = (JLabel) c;
    String text = label.getText();
    if (text == null || "".equals(text) || label.getFont() == null) {
        return -1;
    }
    FontMetrics fm = label.getFontMetrics(label.getFont());
    layout(label, fm, width, height);
    return BasicHTML.getBaseline(label, paintTextR.y, fm.getAscent(), paintTextR.width, paintTextR.height);
}
Also used : FontMetrics(java.awt.FontMetrics)

Example 50 with FontMetrics

use of java.awt.FontMetrics in project jdk8u_jdk by JetBrains.

the class SynthLabelUI method getBaseline.

/**
     * {@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");
    }
    JLabel label = (JLabel) c;
    String text = label.getText();
    if (text == null || "".equals(text)) {
        return -1;
    }
    Insets i = label.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(label);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context.getStyle().getGraphicsUtils(context).layoutText(context, fm, label.getText(), label.getIcon(), label.getHorizontalAlignment(), label.getVerticalAlignment(), label.getHorizontalTextPosition(), label.getVerticalTextPosition(), viewRect, iconRect, textRect, label.getIconTextGap());
    View view = (View) label.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();
    }
    context.dispose();
    return baseline;
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) View(javax.swing.text.View)

Aggregations

FontMetrics (java.awt.FontMetrics)179 Font (java.awt.Font)61 Graphics2D (java.awt.Graphics2D)35 Point (java.awt.Point)34 Dimension (java.awt.Dimension)29 Color (java.awt.Color)23 Rectangle (java.awt.Rectangle)21 Rectangle2D (java.awt.geom.Rectangle2D)21 Insets (java.awt.Insets)20 Graphics (java.awt.Graphics)16 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)14 GradientPaint (java.awt.GradientPaint)14 MPart (gov.sandia.n2a.eqset.MPart)13 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)12 Paint (java.awt.Paint)10 JTree (javax.swing.JTree)10 BasicStroke (java.awt.BasicStroke)9 BufferedImage (java.awt.image.BufferedImage)9 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)8 JLabel (javax.swing.JLabel)8