Example usage for javax.media.j3d J3DGraphics2D getFontMetrics

List of usage examples for javax.media.j3d J3DGraphics2D getFontMetrics

Introduction

In this page you can find the example usage for javax.media.j3d J3DGraphics2D getFontMetrics.

Prototype

public FontMetrics getFontMetrics() 

Source Link

Document

Gets the font metrics of the current font.

Usage

From source file:pl.edu.icm.visnow.geometries.viewer3d.Display3DPanel.java

public void drawLocal2D(J3DGraphics2D vGraphics, LocalToWindow ltw, int w, int h) {
    if (titles == null || titles.isEmpty()) {
        return;/*ww w  .  j  a va2s.com*/
    }
    Font f = vGraphics.getFont();
    Color c = vGraphics.getColor();
    for (Title title : titles) {
        float fh = h * title.getFontHeight();
        if (fh < 5) {
            fh = 5;
        }
        Font actualFont = title.getFont().deriveFont(fh);
        vGraphics.setFont(actualFont);
        FontMetrics fm = vGraphics.getFontMetrics();
        int strWidth = fm.stringWidth(title.getTitle());
        vGraphics.setColor(title.getColor());
        int xPos = w / 50;
        if (title.getHorizontalPosition() == Title.CENTER) {
            xPos = (w - strWidth) / 2;
        }
        if (title.getHorizontalPosition() == Title.RIGHT) {
            xPos = w - strWidth - getWidth() / 50;
        }
        vGraphics.drawString(title.getTitle(), xPos,
                (int) (effectiveHeight * title.getVerticalPosition()) + actualFont.getSize());
    }
    vGraphics.setFont(f);
    vGraphics.setColor(c);
}