2 * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 3 of the GNU Lesser General Public License
6 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.sixth.e3d.gui.humaninput;
12 import eu.svjatoslav.sixth.e3d.gui.ViewPanel;
14 import java.util.Stack;
16 public class KeyboardFocusStack {
18 private final ViewPanel viewPanel;
19 private WorldNavigationUserInputTracker defaultInputHandler = new WorldNavigationUserInputTracker();
20 private Stack<UserInputHandler> inputHandlers = new Stack<>();
21 private UserInputHandler currentUserInputHandler;
23 public KeyboardFocusStack(final ViewPanel viewPanel) {
24 this.viewPanel = viewPanel;
25 pushFocusOwner(defaultInputHandler);
28 public UserInputHandler getCurrentFocusOwner() {
29 return currentUserInputHandler;
32 public void popFocusOwner() {
33 if (currentUserInputHandler != null)
34 currentUserInputHandler.focusLost(viewPanel);
36 if (inputHandlers.isEmpty())
39 currentUserInputHandler = inputHandlers.pop();
40 currentUserInputHandler.focusReceived(viewPanel);
43 public boolean pushFocusOwner(final UserInputHandler newInputHandler) {
44 boolean updateNeeded = false;
46 if (currentUserInputHandler == newInputHandler)
49 if (currentUserInputHandler != null) {
50 updateNeeded = currentUserInputHandler.focusLost(viewPanel);
51 inputHandlers.push(currentUserInputHandler);
54 currentUserInputHandler = newInputHandler;
55 updateNeeded |= currentUserInputHandler.focusReceived(viewPanel);