Class InputMode

java.lang.Object
com.jme3.app.state.AbstractAppState
jme3utilities.NamedAppState
jme3utilities.SimpleAppState
jme3utilities.ui.AcorusAppState
jme3utilities.ui.InputMode
All Implemented Interfaces:
com.jme3.app.state.AppState, com.jme3.input.controls.ActionListener, com.jme3.input.controls.InputListener
Direct Known Subclasses:
DefaultInputMode, DsEditInputMode

public abstract class InputMode extends AcorusAppState implements com.jme3.input.controls.ActionListener
An ActionAppState to implement a configurable input mode. At most one mode is active at a time.

Modes may be temporarily suspended, in which the case the underlying app state remains enabled even though the mode is considered inactive.

The active mode maps hotkeys to actions and controls the appearance of the mouse pointer/cursor. Hotkeys can be mapped to signal actions, which cause multiple keys (shift or control keys, for exampled) to share a common modal function.

When a hotkey binding is live in the input manager, the hotkey is said to be "mapped". When an input mode is inactive, its hotkey bindings persist, allowing them to be altered, loaded, and saved even though they are unmapped.

Hotkeys are bound to action names. The input manager, however, stores "action strings". For non-signal actions, the action string is identical to the action name. For an action which updates a signal, the action name consists of "signal " followed by the name of the signal. In that case, a space and decimal keycode are appended to the action name generate a unique action string for each signal source.

Input modes are disabled at creation.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    action-string prefix for a combo action
    static final String
    action-string prefix for a signal action

    Fields inherited from class jme3utilities.SimpleAppState

    assetManager, cam, flyCam, guiNode, guiViewPort, inputManager, renderManager, rootNode, simpleApplication, stateManager, viewPort

    Fields inherited from class com.jme3.app.state.AbstractAppState

    initialized
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate a disabled, uninitialized mode.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Activate this mode.
    void
    Add the specified action name without binding anything to it.
    void
    bind(String actionName, int... keyCodes)
    Bind the named action to the specified key codes, but don't map it yet.
    void
    bind(String actionName, String usHotkeyName)
    Bind the named action to the named hotkey, but don't map it yet.
    void
    bind(String actionName, Combo combo)
    Bind the named action to the specified Combo.
    void
    bind(String actionName, Hotkey hotkey)
    Bind the named action to the specified hotkey, but don't map it yet.
    void
    bindLocal(String actionName, String localHotkeyName)
    Bind the named action to the named hotkey, but don't map it yet.
    boolean
    binds(Hotkey hotkey)
    Test whether this input mode binds the specified hotkey.
    void
    bindSignal(String signalName, int... keyCodes)
    Bind the named signal to the specified key codes, but don't map it yet.
    void
    bindSignal(String signalName, String usHotkeyName)
    Bind the named signal to the named hotkey, but don't map it yet.
    Determine the path to the bindings asset.
    protected void
    Deactivate this mode.
    protected abstract void
    Add the default hotkey bindings: the bindings to be used if no custom bindings are found.
    Look up the action bound to a hotkey.
    static InputMode
    findMode(String shortName)
    Find an initialized mode by its short name.
    static InputMode
    Access the active mode, if any.
    com.jme3.cursors.plugins.JmeCursor
    Access the cursor for this mode, if any.
    void
    initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application application)
    Initialize this (disabled) mode prior to its first update.
    List all known action names.
    listCombos(String actionName)
    Enumerate all combos bound to the named action.
    Enumerate all hotkeys bound to a named action.
    void
    Load a set of hotkey bindings from the configuration asset.
    protected void
    Map all Hotkey and Combo actions.
    static void
    Disable the active input mode and resume the most recently suspended mode.
    boolean
    Save all hotkey bindings to the configuration asset.
    void
    setConfigPath(String assetPath)
    Alter the path to the configuration asset for bindings.
    void
    setCursor(com.jme3.cursors.plugins.JmeCursor newCursor)
    Alter the mouse cursor for this uninitialized mode.
    void
    setEnabled(boolean newState)
    Enable or disable this mode.
    Determine the short-form name for this mode.
    static void
    Save and suspend the active input mode (if any) and activate the specified mode.
    Represent this input mode as a text string.
    void
    unbind(int keyCode)
    Unbind the specified keyboard key.
    void
    unbind(Hotkey hotkey)
    Unbind the specified hotkey.
    protected void
    Unmap all Hotkey and Combo actions.

    Methods inherited from class jme3utilities.ui.AcorusAppState

    getActionApplication, getSignals, getSpeed

    Methods inherited from class jme3utilities.SimpleAppState

    refreshCachedFields, render, stateDetached

    Methods inherited from class jme3utilities.NamedAppState

    cleanup, getInfluence, hasInfluenceOver, influence, isEnabled, isInitialized, postRender, stateAttached, stopInfluencing, update

    Methods inherited from class com.jme3.app.state.AbstractAppState

    getId, setId

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.jme3.input.controls.ActionListener

    onAction
  • Field Details

    • comboActionPrefix

      public static final String comboActionPrefix
      action-string prefix for a combo action
      See Also:
    • signalActionPrefix

      public static final String signalActionPrefix
      action-string prefix for a signal action
      See Also:
  • Constructor Details

    • InputMode

      public InputMode(String name)
      Instantiate a disabled, uninitialized mode.
      Parameters:
      name - terse name for the mode (not null)
  • Method Details

    • addActionName

      public void addActionName(String name)
      Add the specified action name without binding anything to it.
      Parameters:
      name - action name (not null)
    • bind

      public void bind(String actionName, Combo combo)
      Bind the named action to the specified Combo. Any existing binding for the Combo is removed.
      Parameters:
      actionName - name of the action (not null)
      combo - which Combo to bind (not null)
    • bind

      public void bind(String actionName, Hotkey hotkey)
      Bind the named action to the specified hotkey, but don't map it yet. Any existing binding for the hotkey is removed.
      Parameters:
      actionName - name of the action (not null)
      hotkey - which hotkey to bind (not null)
    • bind

      public void bind(String actionName, int... keyCodes)
      Bind the named action to the specified key codes, but don't map it yet. Any existing bindings for those keys are removed.
      Parameters:
      actionName - the name of the action (not null)
      keyCodes - key codes from KeyInput
    • bind

      public void bind(String actionName, String usHotkeyName)
      Bind the named action to the named hotkey, but don't map it yet. Any existing binding for the hotkey is removed.
      Parameters:
      actionName - the name of the action (not null)
      usHotkeyName - the hotkey's US name (not null)
    • bindLocal

      public void bindLocal(String actionName, String localHotkeyName)
      Bind the named action to the named hotkey, but don't map it yet. Any existing binding for the hotkey is removed.
      Parameters:
      actionName - the name of the action (not null)
      localHotkeyName - the hotkey's local name (not null)
    • binds

      public boolean binds(Hotkey hotkey)
      Test whether this input mode binds the specified hotkey.
      Parameters:
      hotkey - hotkey to test (not null)
      Returns:
      true if bound, otherwise false
    • bindSignal

      public void bindSignal(String signalName, int... keyCodes)
      Bind the named signal to the specified key codes, but don't map it yet. Any existing bindings for those keys are removed.
      Parameters:
      signalName - the name of the signal (not null)
      keyCodes - key codes from KeyInput
    • bindSignal

      public void bindSignal(String signalName, String usHotkeyName)
      Bind the named signal to the named hotkey, but don't map it yet. Any existing binding for the hotkey is removed.
      Parameters:
      signalName - the name of the signal (not null)
      usHotkeyName - the hotkey's US name (not null)
    • configPath

      public String configPath()
      Determine the path to the bindings asset.
      Returns:
      the current asset path (or null if the bindings are not loadable/savable)
    • findActionName

      public String findActionName(Hotkey hotkey)
      Look up the action bound to a hotkey.
      Parameters:
      hotkey - (not null)
      Returns:
      the hotkey's action name, or null if the hotkey isn't bound
    • findMode

      public static InputMode findMode(String shortName)
      Find an initialized mode by its short name.
      Parameters:
      shortName - (not null)
      Returns:
      pre-existing instance (or null if none)
    • getActiveMode

      public static InputMode getActiveMode()
      Access the active mode, if any.
      Returns:
      the pre-existing instance (or null if none active)
    • getCursor

      public com.jme3.cursors.plugins.JmeCursor getCursor()
      Access the cursor for this mode, if any.
      Returns:
      the pre-existing instance (or null if hidden)
    • listActionNames

      public List<String> listActionNames()
      List all known action names.
      Returns:
      a new list
    • listCombos

      public Collection<Combo> listCombos(String actionName)
      Enumerate all combos bound to the named action.
      Parameters:
      actionName - the action name (not null)
      Returns:
      a new collection of combos
    • listHotkeysLocal

      public Collection<String> listHotkeysLocal(String actionName)
      Enumerate all hotkeys bound to a named action.
      Parameters:
      actionName - the name of an action (not null)
      Returns:
      a new collection of local names in lexicographic order
    • loadBindings

      public void loadBindings()
      Load a set of hotkey bindings from the configuration asset.
    • resumeLifo

      public static void resumeLifo()
      Disable the active input mode and resume the most recently suspended mode.
    • saveBindings

      public boolean saveBindings()
      Save all hotkey bindings to the configuration asset.
      Returns:
      true if successful, otherwise false
    • setConfigPath

      public void setConfigPath(String assetPath)
      Alter the path to the configuration asset for bindings.
      Parameters:
      assetPath - the desired asset path (or null to make the bindings not loadable/savable)
    • setCursor

      public void setCursor(com.jme3.cursors.plugins.JmeCursor newCursor)
      Alter the mouse cursor for this uninitialized mode.
      Parameters:
      newCursor - new cursor, or null to hide the cursor when active
    • shortName

      public String shortName()
      Determine the short-form name for this mode.
      Returns:
      name (not null)
    • suspendAndActivate

      public static void suspendAndActivate(InputMode newMode)
      Save and suspend the active input mode (if any) and activate the specified mode.
      Parameters:
      newMode - the desired input mode, or null for none
    • unbind

      public void unbind(Hotkey hotkey)
      Unbind the specified hotkey.
      Parameters:
      hotkey - (not null)
    • unbind

      public void unbind(int keyCode)
      Unbind the specified keyboard key.
      Parameters:
      keyCode - the key code
    • activate

      protected void activate()
      Activate this mode.
    • deactivate

      protected void deactivate()
      Deactivate this mode.
    • defaultBindings

      protected abstract void defaultBindings()
      Add the default hotkey bindings: the bindings to be used if no custom bindings are found.
    • mapAll

      protected void mapAll()
      Map all Hotkey and Combo actions.
    • unmapAll

      protected void unmapAll()
      Unmap all Hotkey and Combo actions.
    • initialize

      public void initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application application)
      Initialize this (disabled) mode prior to its first update.
      Specified by:
      initialize in interface com.jme3.app.state.AppState
      Overrides:
      initialize in class AcorusAppState
      Parameters:
      stateManager - (not null)
      application - (not null)
    • setEnabled

      public void setEnabled(boolean newState)
      Enable or disable this mode.
      Specified by:
      setEnabled in interface com.jme3.app.state.AppState
      Overrides:
      setEnabled in class jme3utilities.NamedAppState
      Parameters:
      newState - true to enable, false to disable
    • toString

      public String toString()
      Represent this input mode as a text string.
      Overrides:
      toString in class jme3utilities.NamedAppState
      Returns:
      descriptive string of text (not null)