Class KeyboardFocusStack

java.lang.Object
eu.svjatoslav.sixth.e3d.gui.humaninput.KeyboardFocusStack

public class KeyboardFocusStack extends Object
Manages a stack-based keyboard focus system for interactive 3D components.

The focus stack determines which KeyboardInputHandler currently receives keyboard events. When a component gains focus (e.g., by being clicked), it is pushed onto the stack and the previous focus owner is notified. When the component releases focus (e.g., pressing ESC), the previous handler is restored.

The default handler at the bottom of the stack is a WorldNavigationUserInputTracker, which handles WASD/arrow-key camera movement when no other component has focus.

Focus flow example:


 // Initial state: WorldNavigationUserInputTracker has focus (camera movement)
 // User clicks on a text editor:
 focusStack.pushFocusOwner(textEditor);
 // Now textEditor receives keyboard events

 // User presses ESC:
 focusStack.popFocusOwner();
 // Camera movement is restored
 
See Also:
  • Constructor Details

    • KeyboardFocusStack

      public KeyboardFocusStack(ViewPanel viewPanel)
      Creates a new focus stack for the given view panel, with WorldNavigationUserInputTracker as the default focus owner.
      Parameters:
      viewPanel - the view panel this focus stack belongs to
  • Method Details

    • getCurrentFocusOwner

      public KeyboardInputHandler getCurrentFocusOwner()
      Returns the handler that currently has keyboard focus.
      Returns:
      the current focus owner
    • popFocusOwner

      public void popFocusOwner()
      Removes the current focus owner from the stack and restores focus to the previous handler. If the stack is empty, no action is taken.
    • pushFocusOwner

      public boolean pushFocusOwner(KeyboardInputHandler newInputHandler)
      Pushes a new handler onto the focus stack, making it the current focus owner. The previous focus owner is notified via KeyboardInputHandler.focusLost(eu.svjatoslav.sixth.e3d.gui.ViewPanel) and preserved on the stack for later restoration.

      If the given handler is already the current focus owner, this method does nothing and returns false.

      Parameters:
      newInputHandler - the handler to receive keyboard focus
      Returns:
      true if the view needs to be repainted as a result