Edit Boxes problem

Problem :

Using the UI test thing in jmetest as the base,

I got a big problem with _Edit Boxes. I put 2 of them on a screen, each with its own buffered and normal input handler, but whatever I write,it only displays in 1 box, even if I click the other box?




 public class StartUI extends BaseGame {

    /*
     * Base application objects
     */

    protected Camera cam;

    protected Node rootNode;

    protected InputHandler input;

    protected InputHandler bufferedInput;
   
    protected InputHandler input2;
   
    protected InputHandler bufferedInput2;

    /*
     * Things to change the rootNode rendering
     */
    protected WireframeState wireState;

    protected LightState lightState;

    protected boolean showBounds = false;

    /*
     * Node for the text outputs fps and mouse location
     */
    protected Node debugNode;

    protected Timer timer;

    protected Text fpsText;

    protected float tpf;

    protected Text mouseText;

    /*
     * The Mouse and it's node
     */
    protected Node mouseNode;

    protected AbsoluteMouse mouse;

    /*
     * The UI component's node
     */
    protected Node uiNode;

    /*
     * UI Components
     */

    UIColorScheme _scheme = new UIColorScheme();

    UIButton _button1 = null;

    UIButton _button2 = null;

    UICheck _check1 = null;

    UICheck _check2 = null;

    UIBillboard _bill1 = null;

    UIBillboard _bill2 = null;

    UIText _text = null;

    UIEditBox _edit = null;

    UIEditBox _edit2 = null;   
    /*
     * used by a bunch of stuff
     */
    public static String fontLocation = "jmetest/data/font/new32.bmp";

    /**
     * initializes the display and camera.
     * 
     */
    protected void initSystem() {

        /*
         * Setup display system and create the main window
         */
        try {
            display = DisplaySystem.getDisplaySystem(properties.getRenderer());
            display.createWindow(properties.getWidth(), properties.getHeight(),
                    properties.getDepth(), properties.getFreq(), properties
                            .getFullscreen());

            cam = display.getRenderer().createCamera(properties.getWidth(),
                    properties.getHeight());
        } catch (JmeException e) {
            e.printStackTrace();
            System.exit(1);
        }

        /*
         * Create the input system
         */
        InputSystem.createInputSystem(properties.getRenderer());

        /*
         * Set the background color for the window
         */
        display.getRenderer().setBackgroundColor(ColorRGBA.black);

        /*
         * Create an input handler This is a specialized input handler for
         * interacting with UI... you may of course add other input handlers
         *
         * Be sure to call the update method of the input handler during the
         * update phase
         */
        input = new InputHandler();
        bufferedInput = new InputHandler();

        input2 = new InputHandler();
        bufferedInput2 = new InputHandler();

        /*
         * really the camera settings for this whole app really shouldn't
         * matter. Everything is set as ortho
         */
        cam.setFrustum(1.0f, 1000.0f, -0.55f, 0.55f, 0.4125f, -0.4125f);
        Vector3f loc = new Vector3f(4.0f, 0.0f, 0.0f);
        Vector3f left = new Vector3f(0.0f, -1.0f, 0.0f);
        Vector3f up = new Vector3f(0.0f, 0.0f, 1.0f);
        Vector3f dir = new Vector3f(-1.0f, 0f, 0.0f);
        cam.setFrame(loc, left, up, dir);

        display.getRenderer().setCamera(cam);

        /*
         * setup the timer for fps checking
         */
        timer = Timer.getTimer(properties.getRenderer());

        /*
         * Setup Display
         */
        display.setTitle("Test");
        display.getRenderer().enableStatistics(true);

    }

    /**
     * initializes the scene
     *
     * @see com.jme.app.SimpleGame#initGame()
     */
    protected void initGame() {

        LoggingSystem.getLogger().setLevel(Level.SEVERE);

        /*
         * Init the nodes
         */

        rootNode = new Node("rootNode");
        debugNode = new Node("debugNode");
        mouseNode = new Node("mouseNode");
        uiNode = new Node("uiNode");

        /*
         * Setup Render States
         */

        /*
         * Wire State
         */
        wireState = display.getRenderer().createWireframeState();
        wireState.setEnabled(false);

        /*
         * ZBuffer
         */
        ZBufferState bufState = display.getRenderer().createZBufferState();
        bufState.setEnabled(true);
        bufState.setFunction(ZBufferState.CF_LEQUAL);

        /*
         * Light State
         */
        PointLight light = new PointLight();
        light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
        light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
        light.setLocation(new Vector3f(100, 100, 100));
        light.setEnabled(true);

        lightState = display.getRenderer().createLightState();
        /*
         * Turn it off for right now
         */
        lightState.setEnabled(false);
        lightState.attach(light);

        /*
         * Alpha states for allowing 'black' to be transparent. This one is for
         * the text font texture
         */
        AlphaState as1 = display.getRenderer().createAlphaState();
        as1.setBlendEnabled(true);
        as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as1.setDstFunction(AlphaState.DB_ONE);
        as1.setTestEnabled(true);
        as1.setTestFunction(AlphaState.TF_GREATER);

        /*
         * This one is for the mouse cursor
         */
        AlphaState as2 = display.getRenderer().createAlphaState();
        as2.setBlendEnabled(true);
        as2.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as2.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        as2.setTestEnabled(true);
        as2.setTestFunction(AlphaState.TF_GREATER);

        /*
         * The absolute mouse
         */
        mouse = new AbsoluteMouse("Mouse Input", display.getWidth(), display
                .getHeight());
        TextureState cursor = display.getRenderer().createTextureState();
        cursor.setEnabled(true);
        cursor.setTexture(TextureManager.loadTexture(TestAbsoluteMouse.class
                .getClassLoader()
                .getResource("jmetest/data/cursor/cursor1.png"),
                Texture.MM_LINEAR, Texture.FM_LINEAR));

        /*
         * Add the cursor texture to the mouse
         */
        mouse.setRenderState(cursor);
        /*
         * Add the alpha state to the mouse
         */
        mouse.setRenderState(as2);
        mouse.setMouseInput(InputSystem.getMouseInput());

        /*
         * Set the speed of the mouse
         */
        mouse.setSpeed(2.0f);
        /*
         * Set the mouse that the inputHandler is using so the UIObjects can
         * retrieve it
         */
        input.setMouse(mouse);
        input2.setMouse(mouse);

        /*
         * The texture for the font
         */
        TextureState font = display.getRenderer().createTextureState();
        font.setTexture(TextureManager.loadTexture(SimpleGame.class
                .getClassLoader().getResource(fontLocation), Texture.MM_LINEAR,
                Texture.FM_LINEAR));
        font.setEnabled(true);

        /*
         * The Frames Per Second text
         */
        fpsText = new Text("FPS Label", "");
        fpsText.setForceView(true);
        fpsText.setRenderState(font);
        fpsText.setRenderState(as1);
        fpsText.setLocalTranslation(new Vector3f(1, 0, 0));

        /*
         * Mouse location text
         */
        mouseText = new Text("Text Label", "Testing Mouse");
        mouseText.setForceView(true);
        mouseText.setRenderState(font);
        mouseText.setRenderState(as1);
        mouseText.setLocalTranslation(new Vector3f(1, 15, 0));

        // Default is the standard grey 'windoze' look
        // the following sets up a cool neon blue theme
        //You Can Comment
                _scheme._backgroundcolor = new ColorRGBA(0.0f, 0.0f, 0.3f, 0.5f);
                _scheme._borderdarkcolor = new ColorRGBA(0.0f, 0.0f, 0.5f, 0.8f);
                _scheme._borderlightcolor = new ColorRGBA(0.3f, 0.3f, 1.0f, 0.8f);
                _scheme._foregroundcolor = ColorRGBA.white;//new ColorRGBA( 1.0f, 1.0f, 1.0f, 0.5f); //
                _scheme._highlightbackgroundcolor = new ColorRGBA(0.1f, 0.1f, 0.6f, 0.5f);
                _scheme._highlightforegroundcolor = ColorRGBA.blue;

        String[] names = { "main", "nice" };
        String[] locs = { fontLocation, "jmetest/data/font/conc_font.png" };

        UIFonts _fonts = new UIFonts(names, locs);

        /*
         * UI Objects
         */

        /*
         * Billboard
         */

        _bill1 = new UIBillboard("billboard with borders", 50, 50, ((display
                .getWidth() - 100) / 2) - 10, display.getHeight() - 100,
                _scheme);

        _bill2 = new UIBillboard("logo",
               (display.getWidth())/display.getWidth() , display.getHeight() - display.getHeight()/2 + display.getHeight()/6 , display.getWidth() ,display.getHeight()/3,
                "image.PNG");

        /*
         * Button
         */
        _button1 = new UIButton("button with textures",
                ((display.getWidth() - 100) / 2) + 0, 100, 128, 32, input,
                "buttonup.png",
                "buttonover.png",
                "buttondown.png", UIActiveObject.TEXTURE
                        | UIActiveObject.DRAW_DOWN | UIActiveObject.DRAW_OVER);

        _button2 = new UIButton("button with borders", 100, 200, 135, 30,
                input, _scheme, UIActiveObject.BORDER
                        | UIActiveObject.DRAW_DOWN | UIActiveObject.DRAW_OVER);
        _button2.setText(_fonts, "nice", "Button");

        /*
         * Check mark
         */

        _check1 = new UICheck("check with textures",
                ((display.getWidth() - 100) / 2) + 100, 300, 256, 64, input,
                _scheme, "jmetest/data/images/checkup.png",
                "jmetest/data/images/checkover.png",
                "jmetest/data/images/checkdown.png",
                "jmetest/data/images/checked.png", UIActiveObject.TEXTURE
                        | UIActiveObject.DRAW_OVER | UIActiveObject.DRAW_DOWN,
                true);

        _check2 = new UICheck("check with borders", 100, 300, 270, 60, input,
                _scheme, null, null, null, null, UIActiveObject.BORDER
                        | UIActiveObject.DRAW_DOWN | UIActiveObject.DRAW_OVER,
                true);
        _check2.setText(_fonts, "nice", "Check");

        /*
         * Static Text
         */

        _text = new UIText("text", _fonts, "nice", "User Name: ", 15, 304,
                60.0f, 0.0f, 30, 180, _scheme, UIObject.BORDER);

        _edit = new UIEditBox("edit", 200, 304, 400, 20, input, bufferedInput, _scheme,
                _fonts, "nice", "", 60.0f, 0.0f, UIObject.INVERSE_BORDER);

        _edit2 = new UIEditBox("edit2", 200, 204, 400, 20, input2, bufferedInput2, _scheme,
                _fonts, "nice", "", 60.0f, 0.0f, UIObject.INVERSE_BORDER);

        /*
         * Put everything together
         */

        /*
         * Debug Node
         */
        debugNode.attachChild(fpsText);
        debugNode.attachChild(mouseText);

        /*
         * Mouse Node
         */
        mouseNode.attachChild(mouse);

        /*
         * UI Node
         */

//        uiNode.attachChild(_bill1);
//       uiNode.attachChild(_bill2);
//        uiNode.attachChild(_check1);
//        uiNode.attachChild(_check2);
        uiNode.attachChild(_button1);
//        uiNode.attachChild(_button2);
       uiNode.attachChild(_text);
        uiNode.attachChild(_edit);
        uiNode.attachChild(_edit2);

        /*
         * root Node
         */

        rootNode.setRenderState(wireState);
        rootNode.setRenderState(bufState);
        rootNode.setRenderState(lightState);

        /*
         * Attach the mouse after the ui to make sure the mouse cursor is over
         * everything else
         */
        rootNode.attachChild(mouseNode);
        rootNode.attachChild(uiNode);

        /*
         * Get it going via final updates
         */
        debugNode.updateGeometricState(0.0f, true);
        debugNode.updateRenderState();

        rootNode.updateGeometricState(0.0f, true);
        rootNode.updateRenderState();

        /*
         * Key bindings
         */

       input.addKeyboardAction("exit", KeyInput.KEY_ESCAPE, new KeyExitAction(
                this));
/*         input.addKeyboardAction("toggle_wire", KeyInput.KEY_T,
                new KeyToggleRenderState(wireState, rootNode));
        input.addKeyboardAction("toggle_lights", KeyInput.KEY_L,
                new KeyToggleRenderState(lightState, rootNode));
        input.addKeyboardAction("toggle_bounds", KeyInput.KEY_B,
                new KeyToggleBoolean(showBounds));
*/
        /*
         * tester for doing the bufferered reader, This is only for testing.. you cannot use
         * standard named keyboard actions and buffered actions at the same time in the same
         * InputHandler.
         *
         * This is important to remember, if you want to use both in your
         * application you'll need a separate input handler.
         *
         * Note that this will only be fired for key presses.
         *
         */

       bufferedInput.addBufferedKeyAction(new KeyInputAction() {
           public void performAction(InputActionEvent event) {
                //System.out.println("KeyInputAction.key = " + this.key);
           
            }
        });
       

        /*
         * Set up logging filtering
         */

        LoggingSystem.getLogger().setLevel(java.util.logging.Level.SEVERE);
    }

    /**
     * Not used.
     *
     * @see com.jme.app.SimpleGame#update()
     */
    protected final void update(float interpolation) {
        /*
         * update the timer and the fps text
         */
        timer.update();
        tpf = timer.getTimePerFrame();
        input.update(tpf);
        bufferedInput.update(tpf);
        input2.update(tpf);
        bufferedInput2.update(tpf);

//        fpsText.print("FPS: " + (int) timer.getFrameRate() + " - "
 //               + display.getRenderer().getStatistics());

        /*
         * Update the mouse and the mouse location text This call updates the
         * location of the mouse cursor
         */
        mouse.update();
        mouseText.print("Position: " + mouse.getLocalTranslation().x + " , "
                + mouse.getLocalTranslation().y);

        /*
         * UI Object Updates, only need to call this for objects that interact
         * with the mouse
         */
        _button1.update(tpf);
        _button2.update(tpf);
        _check1.update(tpf);
        _check2.update(tpf);
        _edit.update(tpf);
        _edit2.update(tpf);
           
        }
       
   

    /**
     * draws the scene graph
     *
     * @see com.jme.app.SimpleGame#render()
     */
    protected void render(float interpolation) {

        /*
         * Clear, getting ready for render
         */
        display.getRenderer().clearStatistics();
        display.getRenderer().clearBuffers();

        display.getRenderer().draw(rootNode);
        if (showBounds)
            display.getRenderer().drawBounds(rootNode);
        /*
         * Draw the debug node after everything else to make sure it's on top
         */
        display.getRenderer().draw(debugNode);
    }

    /**
     * not used.
     *
     * @see com.jme.app.SimpleGame#reinit()
     */
    protected void reinit() {

    }

    /**
     *
     * @see com.jme.app.SimpleGame#cleanup()
     */
    protected void cleanup() {
        InputSystem.getMouseInput().destroy();
        display.close();
        System.exit(0);
    }

    /**
     * Entry point for the test,
     *
     * @param args
     */
    public static void main(String[] args) {
        StartUI app = new StartUI();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
    }

}

I’ve never used the UI stuff so I can’t really help but I do know an entirely new UI system is in the works if you’re able to wait.



I did notice that if you switch the input update calls



i.e.


input2.update(tpf);
input.update(tpf);



That the second box becomes the one that gets all the text. I imagine the UI system should handle setting the active box for you though.

I'll mess around with it a little bit more and post if I figure anything out.

Never knew the update thing. Still trying to make it work properly. If anyone knows the solution, please post!

Sounds like you need to start with a simpler task. Spend some more time reading through the SimpleGame code and the user guide.

I dissected the Edit Box code and made a custom one. I made all the un-needed keys igonred when I press them, and special keys show up. Except 2, It shows the letters after the lower case in Conc Font, the russian g and its upside down version for brackets, help please? It doesnt work for [] and {}







        _inputHandler.addKeyboardAction( this.name + "LeftBracket_action", KeyInput.KEY_LBRACKET, new EditBoxKeyInputAction() {
            public void performAction( InputActionEvent event) {                         

                Cchar("{");
               
               buffignore = true;
            }});
        _inputHandler.addKeyboardAction( this.name + "RightBracket_action", KeyInput.KEY_RBRACKET, new EditBoxKeyInputAction() {
            public void performAction( InputActionEvent event) {                         

                Cchar("}");
               
               buffignore = true;
            }});
       
        }
    public void Cchar(String character)
{
            String before1 = _textBuffer.substring(0, _cursorPos);
             String after1 = character;
            _textBuffer = before1 + after1;
            _text.setText(_textBuffer);
            _cursorPos += 1;
            setCursorLocation();
 

    }



[EDIT] NVM, making another smaller font for this, hopefully that will work, because this font contains more chars then needed, and doesnt contain some needed ones like [] and {}.