Package com.j3d.engine.interact.cmd.base
Interface KeyedStatefulCommand
- All Superinterfaces:
SemiStatefulCommand,StatefulCommand<Void>
- All Known Implementing Classes:
AbstractTransform,ExtrudeCmd,PrismCmd,RotateSelection,ScaleSelection,TranslateSelection
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, likeAbstractTransform, 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 Summary
Modifier and TypeMethodDescriptiondefault voidfinished(boolean success, SafeJLabel lbl) Method which clears all state related to this which can be keys ghost previews temporary listeners ...intGets the index of the currently active step size in the gear train.double[]Gets the array of available step sizes for the transformation (the "gear train").getKeys()Gets the list of temporaryJ3Keys that are active during this command's state.default J3KeynewGearKey(String name) A factory method to create a new "gear" key for cycling through step sizes.selfName()Returns the name of the specific command instance, used for creating unique key IDs.default <T> voidsetDownKey(Supplier<T> shared, Function<T, Boolean> earlyExit, Consumer<T> application) A convenience method to configure the 'Down Arrow' key.voidsetGearIndex(int index) Sets the current gear index, allowing the command to cycle through step sizes.default <T> voidConfigures and registers aJ3Keyfor a specific transformation action.default voidsetKeyAsSideEffects(int keyEvent, Runnable function) Configures a key to execute a simpleRunnableas a side effect, without involving the constraint system or any transformations.default <T> voidsetLeftKey(Supplier<T> shared, Function<T, Boolean> earlyExit, Consumer<T> application) A convenience method to configure the 'Left Arrow' key.default <T> voidsetRightKey(Supplier<T> shared, Function<T, Boolean> earlyExit, Consumer<T> application) A convenience method to configure the 'Right Arrow' key.default <T> voidA convenience method to configure the 'Up Arrow' key.Methods inherited from interface com.j3d.engine.interact.cmd.base.SemiStatefulCommand
fire
-
Method Details
-
getKeys
Gets the list of temporaryJ3Keys that are active during this command's state.- Returns:
- An
ArrayListof 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
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
J3Keyconfigured 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 aJ3Keyfor 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- TheKeyEventvirtual key code for the key (e.g.,KeyEvent.VK_UP).earlyExit- A function that is called before any processing. If it returnstrue, the entire action is aborted. Useful for state-dependent logic.shared- ASupplierthat provides a shared variable (of typeT) representing the transformation's value (e.g., the distance to move).application- AConsumerthat applies the transformation to the "real"GObjects. This is only executed if all constraints are satisfied.
-
finished
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 invocationlbl- 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
Configures a key to execute a simpleRunnableas a side effect, without involving the constraint system or any transformations.
-