Example usage for javax.media.j3d J3DGraphics2D setFont

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

Introduction

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

Prototype

public abstract void setFont(Font font);

Source Link

Document

Sets this graphics context's font to the specified font.

Usage

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

public void newOffScreen(int w, int h) {
    if (w * h == 0) {
        logger.error("bad window size");
        return;//from ww  w.  ja v  a  2  s  .c om
    }
    im = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    imC = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, im, true, false);
    imC.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);
    offScreenCanvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration(), true) {
        @Override
        public void postRender() {
            int stdEffectiveWidth = effectiveWidth;
            int stdEffectiveHeight = effectiveHeight;
            effectiveWidth = offScreenCanvas.getWidth();
            effectiveHeight = offScreenCanvas.getHeight();
            J3DGraphics2D vGraphics = super.getGraphics2D();
            vGraphics.setFont(new Font("sans-serif", Font.PLAIN, 10));
            vGraphics.setColor(Color.YELLOW);
            offScreenLocToWin = new LocalToWindow(objScene, offScreenCanvas);
            offScreenLocToWin.update();
            fireProjectionChanged(new ProjectionEvent(this, offScreenLocToWin));
            draw2D(vGraphics, offScreenLocToWin, effectiveWidth, effectiveHeight);
            vGraphics.flush(false);
            effectiveWidth = stdEffectiveWidth;
            effectiveHeight = stdEffectiveHeight;
            offScreenRenderDone = true;
        }
    };
    offScreenView = offScreenCanvas.getView();
    offScreen = offScreenCanvas.getScreen3D();
    offScreenCanvas.setOffScreenLocation(0, 0);
    offScreenCanvas.setOffScreenBuffer(imC);
    offScreen.setSize(w, h);
    double width = 0.0254 / 90.0 * w;
    double height = 0.0254 / 90.0 * h;
    offScreen.setPhysicalScreenWidth(width);
    offScreen.setPhysicalScreenHeight(height);
    universe.getViewer().getView().addCanvas3D(offScreenCanvas);
    if (offScreenView != null)
        if (perspective)
            offScreenView.setProjectionPolicy(View.PERSPECTIVE_PROJECTION);
        else
            offScreenView.setProjectionPolicy(View.PARALLEL_PROJECTION);
}

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;/* w ww  .  j  a  v a2  s. 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);
}