Example usage for javax.media.j3d Text3D setString

List of usage examples for javax.media.j3d Text3D setString

Introduction

In this page you can find the example usage for javax.media.j3d Text3D setString.

Prototype

public void setString(String string) 

Source Link

Document

Copies the character string from the supplied parameter into the Text3D node.

Usage

From source file:ExText.java

public void checkboxChanged(CheckboxMenu menu, int check) {
    if (menu == fontMenu) {
        // Change the 2D font used to build a 3D font
        currentFont = check;/*  ww w  . j ava  2 s  .  com*/
        String fontName = (String) fonts[currentFont].name;
        Font font = (Font) fonts[currentFont].value;
        Font3D font3d = new Font3D(font, extrusion);

        Text3D tex = new Text3D();
        tex.setFont3D(font3d);
        tex.setString(fontName);
        tex.setAlignment(Text3D.ALIGN_CENTER);

        scene.removeChild(0);
        shape.setGeometry(tex);
        scene.addChild(textGroup);

        if (debug)
            System.err.println("Font set to " + fontName);
        return;
    }

    // Handle all other checkboxes
    super.checkboxChanged(menu, check);
}

From source file:ExText.java

public Group buildScene() {
    // Get the current font attributes
    Font font = (Font) fonts[currentFont].value;
    String textString = (String) fonts[currentFont].name;

    // Turn on the example headlight
    setHeadlightEnable(true);//from w  w  w  . j  av a  2  s  . co  m

    // Build the scene group
    scene = new Group();
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // Build a branch group to hold the text shape
    // (this allows us to remove the text shape later,
    // change it, then put it back, all under menu control)
    textGroup = new BranchGroup();
    textGroup.setCapability(BranchGroup.ALLOW_DETACH);
    scene.addChild(textGroup);

    // BEGIN EXAMPLE TOPIC
    // Create a font extrusion with a default extrusion shape
    extrusion = new FontExtrusion();

    // Define a 3D font with a default extrusion path
    Font3D font3d = new Font3D(font, extrusion);

    // Build 3D text geometry using the 3D font
    Text3D tex = new Text3D();
    tex.setFont3D(font3d);
    tex.setString(textString);
    tex.setAlignment(Text3D.ALIGN_CENTER);

    // Define a generic shaded appearance
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    app.setMaterial(mat);

    // Assemble geometry and appearance into a shape
    // and add it to the scene
    shape = new Shape3D(tex, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    textGroup.addChild(shape);
    // END EXAMPLE TOPIC

    return scene;
}