Search in sources :

Example 36 with FontMetrics

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

the class WebViewWidget method fakeUIPaint.

protected void fakeUIPaint(ViewTransform transform, Graphics2D g, int x, int y) {
    int tx = transform.getSwingX(x);
    int ty = transform.getSwingY(y);
    int w = transform.getSwingDimension(mWidget.getDrawWidth());
    int h = transform.getSwingDimension(mWidget.getDrawHeight());
    int padding = transform.getSwingDimension(mPadding);
    int originalSize = mFont.getSize();
    int scaleSize = transform.getSwingDimension(originalSize);
    g.setFont(mFont.deriveFont((float) scaleSize));
    FontMetrics fontMetrics = g.getFontMetrics();
    g.setColor(Color.WHITE);
    g.drawString("WWW", tx + padding, ty + fontMetrics.getAscent() + padding);
    String text = "WebView";
    Rectangle2D bounds = fontMetrics.getStringBounds(text, g);
    g.drawString(text, tx + (int) ((w - bounds.getWidth()) / 2f), ty + (int) ((h - bounds.getHeight()) / 2f));
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Example 37 with FontMetrics

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

the class ConnectionDraw method drawVerticalMarginIndicator.

/**
     * Utility function to draw a vertical margin indicator
     *
     * @param g    graphics context
     * @param text the text to display
     * @param x    x coordinate
     * @param y1   y1 coordinate
     * @param y2   y2 coordinate
     */
public static void drawVerticalMarginIndicator(Graphics2D g, String text, int x, int y1, int y2) {
    if (y1 > y2) {
        int temp = y1;
        y1 = y2;
        y2 = temp;
    }
    if (text == null) {
        g.drawLine(x, y1, x, y2);
        g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
        g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
        g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
        g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
        return;
    }
    Canvas c = new Canvas();
    FontMetrics fm = c.getFontMetrics(sFont);
    g.setFont(sFont);
    int padding = 4;
    Rectangle2D bounds = fm.getStringBounds(text, g);
    int th = (int) bounds.getHeight();
    int offset = 3 * CONNECTION_ARROW_SIZE;
    int h = ((y2 - y1) - (th + 2 * padding)) / 2;
    if (h <= padding) {
        g.drawLine(x, y1, x, y2);
        g.drawString(text, (int) (x - bounds.getWidth() / 2) + offset, y2 - h - padding);
        g.drawLine(x - CONNECTION_ARROW_SIZE, y1, x + CONNECTION_ARROW_SIZE, y1);
        g.drawLine(x - CONNECTION_ARROW_SIZE, y2, x + CONNECTION_ARROW_SIZE, y2);
    } else {
        g.drawLine(x, y1, x, y1 + h);
        g.drawLine(x, y2 - h, x, y2);
        g.drawString(text, (int) (x - bounds.getWidth() / 2), y2 - h - padding);
        g.drawLine(x, y1, x - CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
        g.drawLine(x, y1, x + CONNECTION_ARROW_SIZE, y1 + CONNECTION_ARROW_SIZE);
        g.drawLine(x, y2, x - CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
        g.drawLine(x, y2, x + CONNECTION_ARROW_SIZE, y2 - CONNECTION_ARROW_SIZE);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Canvas(java.awt.Canvas) Rectangle2D(java.awt.geom.Rectangle2D)

Example 38 with FontMetrics

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

the class ConnectionDraw method drawRoundRectText.

/**
     * Utility function to draw a circle text centered at coordinates (x, y)
     *  @param g    graphics context
     * @param font the font we use to draw the text
     * @param textColor
     * @param text the text to display
     * @param x    x coordinate
     * @param y    y coordinate
     */
public static void drawRoundRectText(Graphics2D g, Font font, Color textColor, String text, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics();
    int padding = 2;
    Rectangle2D bounds = fm.getStringBounds(text, g2);
    double th = bounds.getHeight() + padding * 2;
    double tw = bounds.getWidth() + padding * 2;
    int radius = (int) (Math.min(th, tw) / 3);
    g2.fillRoundRect((int) (x - tw / 2), (int) (y - th / 2), (int) tw, (int) th, radius, radius);
    g2.setColor(textColor);
    g2.drawString(text, (int) (x - tw / 2 + padding), (int) (y - th / 2 + fm.getAscent()));
    if (DEBUG) {
        g2.setColor(Color.RED);
        g2.drawLine(x - 50, y, x + 50, y);
        g2.drawLine(x, y - 50, x, y + 50);
    }
    g2.dispose();
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) Graphics2D(java.awt.Graphics2D)

Example 39 with FontMetrics

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

the class ConnectionDraw method drawHorizontalMarginIndicator.

/**
     * Utility function to draw an horizontal margin indicator
     *
     * @param g    graphics context
     * @param text the text to display
     * @param x1   x1 coordinate
     * @param x2   x2 coordinate
     * @param y    y coordinate
     */
public static void drawHorizontalMarginIndicator(Graphics2D g, String text, int x1, int x2, int y) {
    if (x1 > x2) {
        int temp = x1;
        x1 = x2;
        x2 = temp;
    }
    if (text == null) {
        g.drawLine(x1, y, x2, y);
        g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
        g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
        g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
        g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
        return;
    }
    Canvas c = new Canvas();
    FontMetrics fm = c.getFontMetrics(sFont);
    g.setFont(sFont);
    int padding = 4;
    Rectangle2D bounds = fm.getStringBounds(text, g);
    int th = (int) bounds.getHeight();
    int tw = (int) bounds.getWidth();
    int offset = 3 * CONNECTION_ARROW_SIZE;
    int w = ((x2 - x1) - (tw + 2 * padding)) / 2;
    if (w <= padding) {
        g.drawLine(x1, y, x2, y);
        g.drawString(text, x1 + w + padding, y + offset);
        g.drawLine(x1, y - CONNECTION_ARROW_SIZE, x1, y + CONNECTION_ARROW_SIZE);
        g.drawLine(x2, y - CONNECTION_ARROW_SIZE, x2, y + CONNECTION_ARROW_SIZE);
    } else {
        g.drawLine(x1, y, x1 + w, y);
        g.drawLine(x2 - w, y, x2, y);
        g.drawString(text, x1 + w + padding, (int) (y + (bounds.getHeight() / 2)));
        g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
        g.drawLine(x1, y, x1 + CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
        g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y - CONNECTION_ARROW_SIZE);
        g.drawLine(x2, y, x2 - CONNECTION_ARROW_SIZE, y + CONNECTION_ARROW_SIZE);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Canvas(java.awt.Canvas) Rectangle2D(java.awt.geom.Rectangle2D)

Example 40 with FontMetrics

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

the class ConnectionDraw method drawCircledText.

/**
     * Utility function to draw a circle text centered at coordinates (x, y)
     *
     * @param g    graphics context
     * @param font the font we use to draw the text
     * @param text the text to display
     * @param x    x coordinate
     * @param y    y coordinate
     */
public static void drawCircledText(Graphics2D g, Font font, String text, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setFont(font);
    FontMetrics fm = g2.getFontMetrics();
    int padding = 4;
    Rectangle2D bounds = fm.getStringBounds(text, g2);
    double th = bounds.getHeight();
    double tw = bounds.getWidth();
    float radius = (float) (Math.max(th, tw) / 2f + padding);
    Ellipse2D.Float circle = new Ellipse2D.Float(x - radius, y - radius, 2 * radius + 1, 2 * radius + 1);
    g2.fill(circle);
    g2.setColor(Color.BLACK);
    g2.drawString(text, (int) (x - tw / 2), (y + fm.getAscent() / 2));
    if (DEBUG) {
        g2.setColor(Color.RED);
        g2.drawLine(x - 50, y, x + 50, y);
        g2.drawLine(x, y - 50, x, y + 50);
    }
    g2.dispose();
}
Also used : FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) Ellipse2D(java.awt.geom.Ellipse2D) Graphics2D(java.awt.Graphics2D)

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