Class KeyboardFocusStack

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

public class KeyboardFocusStack extends Object
Manages keyboard focus for interactive 3D components.

Exactly one KeyboardInputHandler has keyboard focus at a time. When a component gains focus (e.g., by being clicked), the previous focus owner is notified and forgotten. When the component releases focus (ESC or middle mouse button), focus falls back to the default handler — never to a previously focused component (there is no focus stack).

The default handler is a WorldNavigationUserInputTracker, which handles WASD/arrow-key camera movement while no component has focus.

Focus flow example:

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

// User presses ESC or middle-clicks the editor:
focus.popFocusOwner();
// Camera movement is active again
See Also:
  • Constructor Details

    • KeyboardFocusStack

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

    • getCurrentFocusOwner

      public KeyboardInputHandler getCurrentFocusOwner()
      Returns the handler that currently has keyboard focus. When no component is focused, this is the default camera navigation handler.
      Returns:
      the current focus owner
    • popFocusOwner

      public void popFocusOwner()
      Releases focus from the current focus owner; focus falls back to the default camera navigation handler. No previously focused component is restored — focus is single-level, not a stack.
    • pushFocusOwner

      public boolean pushFocusOwner(KeyboardInputHandler newInputHandler)
      Gives keyboard focus to the given handler. The previous focus owner is notified via KeyboardInputHandler.focusLost(ViewPanel) and forgotten.

      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