Example usage for javax.media.j3d J3DGraphics2D getFont

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

Introduction

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

Prototype

public abstract Font getFont();

Source Link

Document

Gets 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;//from   ww w.  ja  va 2s  .  c om
    }
    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);
}