How does the input system work (using Canvas + AWTInput (+ FengGUI))?

Hi again.



This time, I have trouble using the input system within a Canvas. However, my question is very simple. Why doesn't my listener get called (which should also solve the question why FengGUI doesn't receive any input):



My SimpleCanvasImplementor{} is:


public class JMEAdapter extends SimpleCanvasImpl {
    final Logger logger = Logger.getLogger(this.getClass().getName());

    final VirtualWorld virtualWorld;

    final Canvas canvas;

    TextureUtils textureUtils;

    private Display fengGuiDisplay;

    private FengJMEInputHandler fengInput;

    public JMEAdapter(VirtualWorld virtualWorld, Canvas canvas, int width, int height) {
        super(width, height);

        this.canvas = canvas;
        this.virtualWorld = virtualWorld;
    }

    @Override
    public void doUpdate() {
        this.fengInput.update(this.timer.getTimePerFrame());

        //
        // Update our JME nodes according to the virtualWorld
        //

        // Next place and update the context bars and the rectangles
        GeometryUtils.updateGeometry(this.virtualWorld, getRootNode());

        // Load all required things (textures, ...) and drop the old ones.
        this.textureUtils.updateTextures(this.virtualWorld);

        // Then, update the world positions (lateInitialized.e., camera).
        CameraUtils.updateCamera(this.virtualWorld, this.cam);
    }

 
    @Override
    public void simpleSetup() {
        this.textureUtils = new TextureUtils(this.renderer);

        AWTMouseInput.setup(this.canvas, false);
        AWTKeyInput.setProvider(InputSystem.INPUT_SYSTEM_AWT);

        AWTMouseInput.get().addListener(new MouseInputListener() {

            @Override
            public void onButton(int arg0, boolean arg1, int arg2, int arg3) {
                System.out.println(".");
            }

            @Override
            public void onMove(int arg0, int arg1, int arg2, int arg3) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onWheel(int arg0, int arg1, int arg2) {
                // TODO Auto-generated method stub

            }

        });

        // Try antialiasing
        DisplaySystem.getDisplaySystem().setMinSamples(2);

        initGUI();
    }

    private void initGUI() {

        this.fengGuiDisplay = new Display(new AWTGLCanvasBinding((AWTGLCanvas) this.canvas));
        this.fengInput = new FengJMEInputHandler(this.fengGuiDisplay);

        // Create a dialog and set it to some location on the screen
        Window frame = new Window();
        frame.setX(100);
        frame.setY(100);
        frame.setSize(100, 100);
        frame.setShrinkable(true);
        frame.setTitle("Something");

        // Update the display with the newly added components
        this.fengGuiDisplay.addWidget(frame);
        this.fengGuiDisplay.layout();
    }

    @Override
    public void doRender() {
        this.renderer.setBackgroundColor(ColorRGBA.black);
        this.renderer.clearBuffers();
        this.renderer.draw(this.rootNode);

        if (this.fengGuiDisplay != null) this.fengGuiDisplay.display();

        this.renderer.displayBackBuffer();
    }
}




The FengJMEInputHandler{} is almost the same as the ones within the forum; however, I also played with the constructor (the original didn't work either):


    public FengJMEInputHandler(Display disp) {
        this.disp = disp;

        this.keyAction = new KeyAction();
        addAction(this.keyAction, DEVICE_KEYBOARD, BUTTON_ALL, AXIS_NONE, false);

        AWTMouseInput.get().addListener(new MouseListener());
    }




It took me quite a long time to figure out that I apparently had to use the AWT***Input classes to get at least rid of those very annoying "Display has to be created first", "Mouse has to be created" exceptions.  But now, I just don't know any further. What do I have to do, to properly receive input messages within my Canvas / FengGUI?

Thanks a lot!


I can plug your above input listener into AppletTestBoxColor and it works fine (remove those override annotations though.)  Probably you aren't completely initing the input and calling update on it like you think you are.  I recommend checking out the code in SimpleJMEApplet for ideas.