1a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta/*
2a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Copyright (c) 2009-2010 jMonkeyEngine
3a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * All rights reserved.
4a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
5a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * Redistribution and use in source and binary forms, with or without
6a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * modification, are permitted provided that the following conditions are
7a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * met:
8a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
9a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions of source code must retain the above copyright
10a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   notice, this list of conditions and the following disclaimer.
11a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
12a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Redistributions in binary form must reproduce the above copyright
13a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   notice, this list of conditions and the following disclaimer in the
14a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   documentation and/or other materials provided with the distribution.
15a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
16a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   may be used to endorse or promote products derived from this software
18a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *   without specific prior written permission.
19a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta *
20a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta */
32a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapackage com.jme3.niftygui;
33a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
34a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.InputManager;
35a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.KeyInput;
36a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.RawInputListener;
37a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.SoftTextDialogInput;
38a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.controls.SoftTextDialogInputListener;
39a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.input.event.*;
40a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport com.jme3.system.JmeSystem;
41a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.Nifty;
42a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.NiftyInputConsumer;
43a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.controls.TextField;
44a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.controls.nullobjects.TextFieldNull;
45a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.elements.Element;
46a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader;
47a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
48a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport de.lessvoid.nifty.spi.input.InputSystem;
49a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.ArrayList;
50a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.logging.Level;
51a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.logging.Logger;
52a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
53a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartapublic class InputSystemJme implements InputSystem, RawInputListener {
54a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
55a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private final ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>();
56a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private InputManager inputManager;
57a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private boolean isDragging = false, niftyOwnsDragging = false;
58a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private boolean pressed = false;
59a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private int buttonIndex;
60a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private int x, y;
61a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private int height;
62a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private boolean shiftDown = false;
63a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private boolean ctrlDown = false;
64a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private Nifty nifty;
65a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
66a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public InputSystemJme(InputManager inputManager) {
67a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        this.inputManager = inputManager;
68a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
69a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
70a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
71a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
72a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
73a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void setNifty(Nifty nifty) {
74a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        this.nifty = nifty;
75a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
76a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
77a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    /**
78a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta     * @param height The height of the viewport. Used to convert
79a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta     * buttom-left origin to upper-left origin.
80a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta     */
81a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void setHeight(int height) {
82a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        this.height = height;
83a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
84a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
85a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void setMousePosition(int x, int y) {
86a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
87a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
88a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void beginInput() {
89a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
90a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
91a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void endInput() {
92a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        boolean result = nifty.update();
93a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
94a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
95a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private void onTouchEventQueued(TouchEvent evt, NiftyInputConsumer nic) {
96a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        boolean consumed = false;
97a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
98a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        x = (int) evt.getX();
99a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        y = (int) (height - evt.getY());
100a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
101a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (!inputManager.getSimulateMouse()) {
102a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            switch (evt.getType()) {
103a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                case DOWN:
104a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    consumed = nic.processMouseEvent(x, y, 0, 0, true);
105a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    isDragging = true;
106a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    niftyOwnsDragging = consumed;
107a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    if (consumed) {
108a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        evt.setConsumed();
109a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    }
110a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
111a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    break;
112a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
113a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                case UP:
114a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    if (niftyOwnsDragging) {
115a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        consumed = nic.processMouseEvent(x, y, 0, 0, false);
116a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        if (consumed) {
117a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                            evt.setConsumed();
118a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        }
119a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    }
120a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
121a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    isDragging = false;
122a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    niftyOwnsDragging = false;
123a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
124a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    if (consumed) {
125a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        processSoftKeyboard();
126a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    }
127a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
128a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    break;
129a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
130a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
131a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
132a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
133a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private void onMouseMotionEventQueued(MouseMotionEvent evt, NiftyInputConsumer nic) {
134a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        x = evt.getX();
135a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        y = height - evt.getY();
136a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        nic.processMouseEvent(x, y, evt.getDeltaWheel(), buttonIndex, pressed);
137a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta//        if (nic.processMouseEvent(niftyEvt) /*|| nifty.getCurrentScreen().isMouseOverElement()*/){
138a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        // Do not consume motion events
139a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        //evt.setConsumed();
140a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta//        }
141a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
142a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
143a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private void onMouseButtonEventQueued(MouseButtonEvent evt, NiftyInputConsumer nic) {
144a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        boolean wasPressed = pressed;
145a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        boolean forwardToNifty = true;
146a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
147a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        buttonIndex = evt.getButtonIndex();
148a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        pressed = evt.isPressed();
149a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
150a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        // Mouse button raised. End dragging
151a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (wasPressed && !pressed) {
152a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            if (!niftyOwnsDragging) {
153a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                forwardToNifty = false;
154a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
155a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            isDragging = false;
156a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            niftyOwnsDragging = false;
157a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
158a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
159a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        boolean consumed = false;
160a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (forwardToNifty) {
161a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            consumed = nic.processMouseEvent(x, y, 0, buttonIndex, pressed);
162a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            if (consumed) {
163a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                evt.setConsumed();
164a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
165a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
166a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
167a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        // Mouse button pressed. Begin dragging
168a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (!wasPressed && pressed) {
169a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            isDragging = true;
170a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            niftyOwnsDragging = consumed;
171a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
172a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
173a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (consumed && pressed) {
174a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            processSoftKeyboard();
175a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
176a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
177a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
178a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
179a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private void onKeyEventQueued(KeyInputEvent evt, NiftyInputConsumer nic) {
180a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        int code = evt.getKeyCode();
181a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
182a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (code == KeyInput.KEY_LSHIFT || code == KeyInput.KEY_RSHIFT) {
183a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            shiftDown = evt.isPressed();
184a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        } else if (code == KeyInput.KEY_LCONTROL || code == KeyInput.KEY_RCONTROL) {
185a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            ctrlDown = evt.isPressed();
186a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
187a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
188a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        KeyboardInputEvent keyEvt = new KeyboardInputEvent(code,
189a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                evt.getKeyChar(),
190a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                evt.isPressed(),
191a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                shiftDown,
192a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                ctrlDown);
193a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
194a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (nic.processKeyboardEvent(keyEvt)) {
195a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            evt.setConsumed();
196a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
197a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
198a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
199a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onMouseMotionEvent(MouseMotionEvent evt) {
200a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        // Only forward the event if there's actual motion involved.
201a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (inputManager.isCursorVisible() && (evt.getDX() != 0
202a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                || evt.getDY() != 0
203a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                || evt.getDeltaWheel() != 0)) {
204a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            inputQueue.add(evt);
205a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
206a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
207a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
208a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onMouseButtonEvent(MouseButtonEvent evt) {
209a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (inputManager.isCursorVisible() && evt.getButtonIndex() >= 0 && evt.getButtonIndex() <= 2) {
210a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            inputQueue.add(evt);
211a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
212a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
213a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
214a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onJoyAxisEvent(JoyAxisEvent evt) {
215a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
216a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
217a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onJoyButtonEvent(JoyButtonEvent evt) {
218a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
219a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
220a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onKeyEvent(KeyInputEvent evt) {
221a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        inputQueue.add(evt);
222a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
223a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
224a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void onTouchEvent(TouchEvent evt) {
225a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        inputQueue.add(evt);
226a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
227a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
228a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    public void forwardEvents(NiftyInputConsumer nic) {
229a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        int queueSize = inputQueue.size();
230a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
231a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        for (int i = 0; i < queueSize; i++) {
232a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            InputEvent evt = inputQueue.get(i);
233a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            if (evt instanceof MouseMotionEvent) {
234a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                onMouseMotionEventQueued((MouseMotionEvent) evt, nic);
235a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } else if (evt instanceof MouseButtonEvent) {
236a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                onMouseButtonEventQueued((MouseButtonEvent) evt, nic);
237a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } else if (evt instanceof KeyInputEvent) {
238a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                onKeyEventQueued((KeyInputEvent) evt, nic);
239a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            } else if (evt instanceof TouchEvent) {
240a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                onTouchEventQueued((TouchEvent) evt, nic);
241a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
242a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
243a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
244a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        inputQueue.clear();
245a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
246a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
247a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    private void processSoftKeyboard() {
248a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        SoftTextDialogInput softTextDialogInput = JmeSystem.getSoftTextDialogInput();
249a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        if (softTextDialogInput != null) {
250a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
251a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            Element element = nifty.getCurrentScreen().getFocusHandler().getKeyboardFocusElement();
252a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            if (element != null) {
253a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                final TextField textField = element.getNiftyControl(TextField.class);
254a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                if (textField != null && !(textField instanceof TextFieldNull)) {
255a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    Logger.getLogger(InputSystemJme.class.getName()).log(Level.INFO, "Current TextField: {0}", textField.getId());
256a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    String initialValue = textField.getText();
257a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    if (initialValue == null) {
258a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        initialValue = "";
259a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    }
260a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
261a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    softTextDialogInput.requestDialog(SoftTextDialogInput.TEXT_ENTRY_DIALOG, "Enter Text", initialValue, new SoftTextDialogInputListener() {
262a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
263a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        public void onSoftText(int action, String text) {
264a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                            if (action == SoftTextDialogInputListener.COMPLETE) {
265a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                                textField.setText(text);
266a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                            }
267a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                        }
268a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                    });
269a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta                }
270a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta            }
271a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta        }
272a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta
273a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta    }
274a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta}
275