Search in sources :

Example 1 with FontMetrics

use of java.awt.FontMetrics in project checkstyle by checkstyle.

the class TreeTable method setColumnsInitialWidth.

/**
     * Set initial value of width for columns in table.
     */
private void setColumnsInitialWidth() {
    final FontMetrics fontMetrics = getFontMetrics(getFont());
    // Six character string to contain "Column" column.
    final int widthOfSixCharacterString = fontMetrics.stringWidth("XXXXXX");
    // Padding must be added to width for columns to make them fully
    // visible in table header.
    final int padding = 10;
    final int widthOfColumnContainingSixCharacterString = widthOfSixCharacterString + padding;
    getColumn("Line").setMaxWidth(widthOfColumnContainingSixCharacterString);
    getColumn("Column").setMaxWidth(widthOfColumnContainingSixCharacterString);
    final int preferredTreeColumnWidth = Math.toIntExact(Math.round(getPreferredSize().getWidth() * 0.6));
    getColumn("Tree").setPreferredWidth(preferredTreeColumnWidth);
    // Twenty eight character string to contain "Type" column
    final int widthOfTwentyEightCharacterString = fontMetrics.stringWidth("XXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    final int preferredTypeColumnWidth = widthOfTwentyEightCharacterString + padding;
    getColumn("Type").setPreferredWidth(preferredTypeColumnWidth);
}
Also used : FontMetrics(java.awt.FontMetrics)

Example 2 with FontMetrics

use of java.awt.FontMetrics in project hackpad by dropbox.

the class RunProxy method mousePressed.

/**
     * Called when a mouse button is pressed.
     */
public void mousePressed(MouseEvent e) {
    Font font = fileWindow.textArea.getFont();
    FontMetrics metrics = getFontMetrics(font);
    int h = metrics.getHeight();
    pressLine = e.getY() / h;
}
Also used : FontMetrics(java.awt.FontMetrics) Font(java.awt.Font) Point(java.awt.Point)

Example 3 with FontMetrics

use of java.awt.FontMetrics in project hackpad by dropbox.

the class RunProxy method update.

/**
     * Updates the gutter.
     */
public void update() {
    FileTextArea textArea = fileWindow.textArea;
    Font font = textArea.getFont();
    setFont(font);
    FontMetrics metrics = getFontMetrics(font);
    int h = metrics.getHeight();
    int lineCount = textArea.getLineCount() + 1;
    String dummy = Integer.toString(lineCount);
    if (dummy.length() < 2) {
        dummy = "99";
    }
    Dimension d = new Dimension();
    d.width = metrics.stringWidth(dummy) + 16;
    d.height = lineCount * h + 100;
    setPreferredSize(d);
    setSize(d);
}
Also used : FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension) Font(java.awt.Font) Point(java.awt.Point)

Example 4 with FontMetrics

use of java.awt.FontMetrics in project hackpad by dropbox.

the class RunProxy method mouseReleased.

/**
     * Called when a mouse button is released.
     */
public void mouseReleased(MouseEvent e) {
    if (e.getComponent() == this && (e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) {
        int y = e.getY();
        Font font = fileWindow.textArea.getFont();
        FontMetrics metrics = getFontMetrics(font);
        int h = metrics.getHeight();
        int line = y / h;
        if (line == pressLine) {
            fileWindow.toggleBreakPoint(line + 1);
        } else {
            pressLine = -1;
        }
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Point(java.awt.Point) Font(java.awt.Font)

Example 5 with FontMetrics

use of java.awt.FontMetrics in project qi4j-sdk by Qi4j.

the class StackedLayout method getItemMinSize.

private Dimension getItemMinSize(NodeItem node, Dimension minSize) {
    if (minSize == null) {
        minSize = new Dimension(0, 0);
    }
    String label = node.getString("name");
    FontMetrics fm = Renderer.DEFAULT_GRAPHICS.getFontMetrics(StackedGraphDisplay.FONT);
    int width = fm.stringWidth(label);
    int height = fm.getHeight();
    minSize.setSize(width + INSET + INSET, height + INSET + INSET);
    //System.out.println(fm.getAscent());
    return minSize;
}
Also used : FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension)

Aggregations

FontMetrics (java.awt.FontMetrics)116 Font (java.awt.Font)43 Graphics2D (java.awt.Graphics2D)32 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Rectangle2D (java.awt.geom.Rectangle2D)20 Color (java.awt.Color)18 Insets (java.awt.Insets)18 Rectangle (java.awt.Rectangle)17 GradientPaint (java.awt.GradientPaint)9 BufferedImage (java.awt.image.BufferedImage)9 Graphics (java.awt.Graphics)8 BasicStroke (java.awt.BasicStroke)6 Shape (java.awt.Shape)5 JLabel (javax.swing.JLabel)5 Canvas (java.awt.Canvas)4 BadLocationException (javax.swing.text.BadLocationException)4 Polygon (java.awt.Polygon)3 FontRenderContext (java.awt.font.FontRenderContext)3 ArrayList (java.util.ArrayList)3