Interface KeyedStatefulCommand

All Superinterfaces:
SemiStatefulCommand, StatefulCommand<Void>
All Known Implementing Classes:
AbstractTransform, ExtrudeCmd, PrismCmd, RotateSelection, ScaleSelection, TranslateSelection

public interface KeyedStatefulCommand extends StatefulCommand<Void>
An extension of StatefulCommand for commands that are interactive and primarily driven by a set of temporary, context-specific keybindings, such as the arrow keys.

This interface defines the contract for a command that enters a "state" where it listens for specific key presses (like Up, Down, Left, Right) to manipulate a selection of objects. It provides a powerful, reusable framework for defining these key actions while seamlessly integrating with the application's constraint validation system.

A typical implementation, like AbstractTransform, will use this interface to manage the lifecycle of temporary keybindings, applying transformations incrementally and ensuring all geometric constraints are satisfied before committing any changes.
Author:
Lehlogonolo Poole
See Also:
  • Method Details

    • getKeys

      ArrayList<J3Key> getKeys()
      Gets the list of temporary J3Keys that are active during this command's state.
      Returns:
      An ArrayList of active keys.
    • selfName

      String selfName()
      Returns the name of the specific command instance, used for creating unique key IDs.
      Returns:
      The name of the command.
    • getGearTrain

      double[] getGearTrain()
      Gets the array of available step sizes for the transformation (the "gear train").
      Returns:
      An array of doubles representing different step magnitudes.
    • getGearIndex

      int getGearIndex()
      Gets the index of the currently active step size in the gear train.
      Returns:
      The current gear index.
    • setGearIndex

      void setGearIndex(int index)
      Sets the current gear index, allowing the command to cycle through step sizes.
      Parameters:
      index - The new gear index.
    • newGearKey

      default J3Key newGearKey(String name)
      A factory method to create a new "gear" key for cycling through step sizes.
      Parameters:
      name - The base name for the key.
      Returns:
      A new J3Key configured to change the gear index.
    • setKey

      default <T> void setKey(int key, Function<T,Boolean> earlyExit, Supplier<T> shared, Consumer<T> application)
      Configures and registers a J3Key for a specific transformation action.

      This is the core helper method of the interface. It encapsulates the entire "check-then-apply" logic: it creates a keybinding that, when triggered, will first validate the proposed transformation against all relevant constraints and, only if validation succeeds, apply the transformation to the real objects.

      Type Parameters:
      T - The type of the shared variable representing the transformation value.
      Parameters:
      key - The KeyEvent virtual key code for the key (e.g., KeyEvent.VK_UP).
      earlyExit - A function that is called before any processing. If it returns true, the entire action is aborted. Useful for state-dependent logic.
      shared - A Supplier that provides a shared variable (of type T) representing the transformation's value (e.g., the distance to move).
      application - A Consumer that applies the transformation to the "real" GObjects. This is only executed if all constraints are satisfied.
    • finished

      default void finished(boolean success, SafeJLabel lbl)
      Method which clears all state related to this which can be
      • keys
      • ghost previews
      • temporary listeners
      • ...
      Parameters:
      success - Whether the command finished successfully or not. if the user had clicked escape or an error occurred that counts as an unsuccessful invocation
      lbl - The label.
    • setUpKey

      default <T> void setUpKey(Supplier<T> shared, Function<T,Boolean> earlyExit, Consumer<T> application)
      A convenience method to configure the 'Up Arrow' key.
    • setDownKey

      default <T> void setDownKey(Supplier<T> shared, Function<T,Boolean> earlyExit, Consumer<T> application)
      A convenience method to configure the 'Down Arrow' key.
    • setLeftKey

      default <T> void setLeftKey(Supplier<T> shared, Function<T,Boolean> earlyExit, Consumer<T> application)
      A convenience method to configure the 'Left Arrow' key.
    • setRightKey

      default <T> void setRightKey(Supplier<T> shared, Function<T,Boolean> earlyExit, Consumer<T> application)
      A convenience method to configure the 'Right Arrow' key.
    • setKeyAsSideEffects

      default void setKeyAsSideEffects(int keyEvent, Runnable function)
      Configures a key to execute a simple Runnable as a side effect, without involving the constraint system or any transformations.
      Parameters:
      keyEvent - The KeyEvent virtual key code for the key.
      function - The Runnable to execute when the key is pressed.