2 * Sixth 3D engine. Copyright ©2012-2016, 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.ViewContext;
14 import java.util.Stack;
16 public class KeyboardFocusTracker {
18 private final ViewContext viewContext;
19 WorldNavigationTracker defaultInputHandler = new WorldNavigationTracker();
20 Stack<UserInputHandler> inputHandlers = new Stack<>();
21 private UserInputHandler currentUserInputHandler;
23 public KeyboardFocusTracker(final ViewContext viewContext) {
24 this.viewContext = viewContext;
25 setFocusOwner(defaultInputHandler);
28 public UserInputHandler getCurrentFocusOwner() {
29 return currentUserInputHandler;
32 public void popFocusOwner() {
33 if (currentUserInputHandler == null)
36 if (inputHandlers.isEmpty())
39 currentUserInputHandler.focusLost(viewContext);
41 currentUserInputHandler = inputHandlers.pop();
43 currentUserInputHandler.focusReceived(viewContext);
46 public void setFocusOwner(final UserInputHandler inputHandler) {
47 if (currentUserInputHandler == inputHandler)
50 if (currentUserInputHandler != null) {
51 currentUserInputHandler.focusLost(viewContext);
52 inputHandlers.push(currentUserInputHandler);
55 currentUserInputHandler = inputHandler;
57 currentUserInputHandler.focusReceived(viewContext);