Class Invoker

java.lang.Object
com.j3d.engine.interact.cmd.Invoker

public class Invoker extends Object
Represents the source or context from which a command was invoked.

A command can be invoked by their following classifications:

  • User: The user explicitly typed this command out in the command line (or it has been pasted) and they hit enter in the command lin and it executed. Can only set CommandParser#run()
  • Engine: Anything else the user does, but does not have to go through the command line text input. So clicking a button or a keyboard shortcut, all count as engine invocations. set within CommandParser.run(Command, ArrayList, ArrayList) overload
  • fromParent: This specific command was invoked as a result of a parent command calling it. This specifically indicates that this was invoked as a Subcommand of the stored parent. This is set only by Command#dispatchToSubcommands(String, SafeJLabel, Object[], ArrayList)
  • fromCall: If another command call specifically calls some other command. The command has to use the CommandParser.run(Command, ArrayList, ArrayList, Command) overload.

Author:
Lehlogonolo Poole
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final boolean
    Indicates if the invocation originated from the engine itself.
    private final Command
    The command that called this command if this invoker represents a direct command call.
    private final Command
    The parent command that invoked this command as a subcommand of itself, if applicable.
    private final boolean
    Indicates if the invocation originated from a macro.
    private final boolean
    Indicates if the invocation originated from a user action.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Invoker(boolean user, boolean engine, boolean macro, Command parent, Command call)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Invoker
    Creates an Invoker instance indicating the command was invoked directly through a command different call.
    static Invoker
    Creates an Invoker instance indicating the invocation originated from the engine.
    static Invoker
    Creates an Invoker instance indicating the invocation originated from a macro
    static Invoker
    Creates an Invoker instance indicating the command was invoked as a subcommand by another parent command.
    static Invoker
    Creates an Invoker instance indicating the invocation originated from the command line input (the user hit enter)
    Returns the command that was called, if this invoker represents a direct command call.
    Returns the parent command that invoked this command, if applicable.
    Returns a descriptive string indicating the source of the invocation.
    boolean
    Checks if the invocation originated from the engine itself.
    boolean
    Checks if the invocation originated from a user action.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • user

      private final boolean user
      Indicates if the invocation originated from a user action.
    • engine

      private final boolean engine
      Indicates if the invocation originated from the engine itself.
    • macro

      private final boolean macro
      Indicates if the invocation originated from a macro.
    • invokedFromParent

      private final Command invokedFromParent
      The parent command that invoked this command as a subcommand of itself, if applicable.
    • invokedFromCall

      private final Command invokedFromCall
      The command that called this command if this invoker represents a direct command call.
  • Constructor Details

    • Invoker

      private Invoker(boolean user, boolean engine, boolean macro, Command parent, Command call)
  • Method Details

    • byUser

      public static Invoker byUser()
      Creates an Invoker instance indicating the invocation originated from the command line input (the user hit enter)
      Returns:
      An Invoker instance representing a user invocation.
    • byMacro

      public static Invoker byMacro()
      Creates an Invoker instance indicating the invocation originated from a macro
      Returns:
      An Invoker instance representing a macro invocation.
    • byEngine

      public static Invoker byEngine()
      Creates an Invoker instance indicating the invocation originated from the engine. (anything else)
      Returns:
      An Invoker instance representing an engine invocation.
    • byParentCommand

      public static Invoker byParentCommand(Command command)
      Creates an Invoker instance indicating the command was invoked as a subcommand by another parent command.
      Parameters:
      command - The parent command.
      Returns:
      An Invoker instance.
    • byCommandCall

      public static Invoker byCommandCall(Command command)
      Creates an Invoker instance indicating the command was invoked directly through a command different call.
      Parameters:
      command - The command that was called.
      Returns:
      An Invoker instance.
    • isUser

      public boolean isUser()
      Checks if the invocation originated from a user action.
      Returns:
      True if invoked by user, false otherwise.
    • isEngine

      public boolean isEngine()
      Checks if the invocation originated from the engine itself.
      Returns:
      True if invoked by engine, false otherwise.
    • getInvokedFromParent

      public Command getInvokedFromParent()
      Returns the parent command that invoked this command, if applicable.
      Returns:
      The parent Command, or null if not invoked as a subcommand.
    • getInvokedFromCall

      public Command getInvokedFromCall()
      Returns the command that was called, if this invoker represents a direct command call.
      Returns:
      The Command that was called, or null if not a direct call.
    • getString

      public String getString()
      Returns a descriptive string indicating the source of the invocation. This will be "USER", "ENGINE", or the simple class name of the invoking command with an indication of whether it was a subcommand or a direct call.
      Returns:
      A string representing the invoker.