Search in sources :

Example 41 with FontMetrics

use of java.awt.FontMetrics in project ChatGameFontificator by GlitchCog.

the class HintTextField method paint.

@Override
public void paint(Graphics g) {
    super.paint(g);
    if (!hasFocus() && getText().length() == 0) {
        int h = getHeight();
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        Insets ins = getInsets();
        FontMetrics fm = g.getFontMetrics();
        int c0 = getBackground().getRGB();
        int c1 = getForeground().getRGB();
        int m = 0xfefefefe;
        int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
        g.setColor(new Color(c2, true));
        g.drawString(hint, ins.left, h / 2 + fm.getAscent() / 2 - 2);
    }
}
Also used : Insets(java.awt.Insets) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Graphics2D(java.awt.Graphics2D)

Example 42 with FontMetrics

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

the class AGlassPane method paintComponent.

//  actionPerformed
/**************************************************************************
	 *  Paint Component.
	 *  <pre>
	 *      image
	 *      message
	 *      progressBar
	 *  </pre>
	 *  @param g
	 */
public void paintComponent(Graphics g) {
    Dimension panelSize = getSize();
    //  .5 is a bit too light
    g.setColor(new Color(1f, 1f, 1f, 0.4f));
    g.fillRect(0, 0, panelSize.width, panelSize.height);
    //
    g.setFont(s_font);
    g.setColor(s_color);
    FontMetrics fm = g.getFontMetrics();
    Dimension messageSize = new Dimension(fm.stringWidth(m_message), fm.getAscent() + fm.getDescent());
    Dimension imageSize = new Dimension(s_image.getWidth(this), s_image.getHeight(this));
    Dimension progressSize = new Dimension(150, 15);
    //	System.out.println("Panel=" + panelSize + " - Message=" + messageSize + " - Image=" + imageSize + " - Progress=" + progressSize);
    //  Horizontal layout
    int height = imageSize.height + GAP + messageSize.height + GAP + progressSize.height;
    if (height > panelSize.height) {
        log.log(Level.SEVERE, "Panel too small - height=" + panelSize.height);
        return;
    }
    int yImage = (panelSize.height / 2) - (height / 2);
    int yMessage = yImage + imageSize.height + GAP + fm.getAscent();
    int yProgress = yMessage + fm.getDescent() + GAP;
    //  Vertical layout
    if (imageSize.width > panelSize.width || messageSize.width > panelSize.width) {
        log.log(Level.SEVERE, "Panel too small - width=" + panelSize.width);
        return;
    }
    int xImage = (panelSize.width / 2) - (imageSize.width / 2);
    int xMessage = (panelSize.width / 2) - (messageSize.width / 2);
    int xProgress = (panelSize.width / 2) - (progressSize.width / 2);
    g.drawImage(s_image, xImage, yImage, this);
    g.drawString(m_message, xMessage, yMessage);
    if (m_timermax > 0) {
        int pWidth = progressSize.width / m_timermax * m_timervalue;
        g.setColor(AdempierePLAF.getPrimary3());
        g.fill3DRect(xProgress, yProgress, pWidth, progressSize.height, true);
        g.setColor(AdempierePLAF.getPrimary2());
        g.draw3DRect(xProgress, yProgress, progressSize.width, progressSize.height, true);
    }
}
Also used : FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) Dimension(java.awt.Dimension)

Example 43 with FontMetrics

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

the class AdempiereTabbedPaneUI method paintTab.

protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) {
    Rectangle tabRect = rects[tabIndex];
    int selectedIndex = tabPane.getSelectedIndex();
    boolean isSelected = selectedIndex == tabIndex;
    Graphics2D g2 = null;
    Polygon cropShape = null;
    Shape save = null;
    int cropx = 0;
    int cropy = 0;
    if (scrollableTabLayoutEnabled()) {
        if (g instanceof Graphics2D) {
            g2 = (Graphics2D) g;
            // Render visual for cropped tab edge...
            Rectangle viewRect = tabScroller.viewport.getViewRect();
            int cropline;
            switch(tabPlacement) {
                case LEFT:
                case RIGHT:
                    cropline = viewRect.y + viewRect.height;
                    if ((tabRect.y < cropline) && (tabRect.y + tabRect.height > cropline)) {
                        cropShape = createCroppedTabClip(tabPlacement, tabRect, cropline);
                        cropx = tabRect.x;
                        cropy = cropline - 1;
                    }
                    break;
                case TOP:
                case BOTTOM:
                default:
                    cropline = viewRect.x + viewRect.width;
                    if ((tabRect.x < cropline) && (tabRect.x + tabRect.width > cropline)) {
                        cropShape = createCroppedTabClip(tabPlacement, tabRect, cropline);
                        cropx = cropline - 1;
                        cropy = tabRect.y;
                    }
            }
            if (cropShape != null) {
                save = g.getClip();
                g2.clip(cropShape);
            }
        }
    }
    paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
    paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
    String title = tabPane.getTitleAt(tabIndex);
    Font font = tabPane.getFont();
    FontMetrics metrics = g.getFontMetrics(font);
    Icon icon = getIconForTab(tabIndex);
    layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
    paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect, isSelected);
    paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
    paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
    if (cropShape != null) {
        paintCroppedTabEdge(g, tabPlacement, tabIndex, isSelected, cropx, cropy);
        g.setClip(save);
    }
}
Also used : Shape(java.awt.Shape) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Icon(javax.swing.Icon) Polygon(java.awt.Polygon) Point(java.awt.Point) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 44 with FontMetrics

use of java.awt.FontMetrics in project poi by apache.

the class TestEscherGraphics method testGetFontMetrics.

@Test
public void testGetFontMetrics() {
    Font f = graphics.getFont();
    if (f.toString().contains("dialog") || f.toString().contains("Dialog")) {
        return;
    }
    FontMetrics fontMetrics = graphics.getFontMetrics(graphics.getFont());
    assertEquals(7, fontMetrics.charWidth('X'));
    assertEquals("java.awt.Font[family=Arial,name=Arial,style=plain,size=10]", fontMetrics.getFont().toString());
}
Also used : FontMetrics(java.awt.FontMetrics) Font(java.awt.Font) Test(org.junit.Test)

Example 45 with FontMetrics

use of java.awt.FontMetrics in project chipKIT32-MAX by chipKIT32.

the class CompositionTextManager method getCaretLocation.

private Point getCaretLocation() {
    Point loc = new Point();
    TextAreaPainter painter = textArea.getPainter();
    FontMetrics fm = painter.getFontMetrics();
    int offsetY = fm.getHeight() - COMPOSING_UNDERBAR_HEIGHT;
    int lineIndex = textArea.getCaretLine();
    loc.y = lineIndex * fm.getHeight() + offsetY;
    int offsetX = textArea.getCaretPosition() - textArea.getLineStartOffset(lineIndex);
    loc.x = textArea.offsetToX(lineIndex, offsetX);
    return loc;
}
Also used : TextAreaPainter(processing.app.syntax.TextAreaPainter) FontMetrics(java.awt.FontMetrics) Point(java.awt.Point) Point(java.awt.Point)

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