Class InteractiveShell

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Placeable, Initializable, UsesInvokeAndWait, TypedActor, ShellInterpreter, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class InteractiveShell
    extends TypedAtomicActor
    implements Placeable, ShellInterpreter, UsesInvokeAndWait

    This actor creates a command shell on the screen, sending commands that are typed by the user to its output port, and reporting values received at its input by displaying them. Each time it fires, it reads the input, displays it, then displays a command prompt (which by default is ">>"), and waits for a command to be typed. The command is terminated by an enter or return character, which then results in the command being produced on the output. In a typical use of this actor, it will be preceded by a SampleDelay actor which will provide an initial welcome message or instructions. The output will then be routed to some subsystem for processing, and the result will be fed back to the input.

    If the user types "quit" or "exit" (without the quotation marks) on the prompt, then this actor's postfire() method will return false. Depending on the domain, this can result in the model execution stopping (in SDF, for example) or in subsequent firings of this actor being skipped (in DE, for example).

    Note that because of complexities in Swing, if you resize the display window, then, unlike the plotters, the new size will not be persistent. That is, if you save the model and then re-open it, the new size is forgotten. The position, however, is persistent.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • input

        public TypedIOPort input
        The input port. By default, this has undeclared type. If backward type inference is enabled, then it has type general. In either case, it can receive any data type. If it receives token of type string, it strips off the surrounding double quotes before displaying the value.
      • prompt

        public PortParameter prompt
        The prompt. The initial default is the string ">> ". Double quotes are not necessary. If you would like to have no prompt (aka, the empty string), create a Parameter that has the value "" (for example foo) and then set the value of the prompt parameter to $foo.
    • Method Detail

      • evaluateCommand

        public java.lang.String evaluateCommand​(java.lang.String command)
                                         throws java.lang.Exception
        Evaluate the specified command.
        Specified by:
        evaluateCommand in interface ShellInterpreter
        Parameters:
        command - The command.
        Returns:
        The return value of the command, or null if there is none.
        Throws:
        java.lang.Exception - If something goes wrong processing the command.
        See Also:
        ShellTextArea.returnResult(String)
      • fire

        public void fire()
                  throws IllegalActionException
        Read and display the input, then wait for user input and produce the user data on the output. If the user input is "quit" or "exit", then set a flag that causes postfire() to return false.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If producing the output causes an exception.
      • getOutput

        public java.lang.String getOutput()
        Get the output string to be sent. This does not return until a value is entered on the shell by the user.
        Returns:
        The output string to be sent.
        See Also:
        setOutput(String)
      • isCommandComplete

        public boolean isCommandComplete​(java.lang.String command)
        Return true if the specified command is complete (ready to be interpreted).
        Specified by:
        isCommandComplete in interface ShellInterpreter
        Parameters:
        command - The command.
        Returns:
        True.
      • place

        public void place​(java.awt.Container container)
        Specify the container into which this shell should be placed. This method needs to be called before the first call to initialize(). Otherwise, the shell will be placed in its own frame. The background of the plot is set equal to that of the container (unless it is null).
        Specified by:
        place in interface Placeable
        Parameters:
        container - The container into which to place the shell, or null to specify that a new shell should be created.
      • setDisplayName

        public void setDisplayName​(java.lang.String name)
        Set a name to present to the user.

        If the Plot window has been rendered, then the title of the Plot window will be updated to the value of the name parameter.

        Overrides:
        setDisplayName in class NamedObj
        Parameters:
        name - A name to present to the user.
        See Also:
        NamedObj.getDisplayName()
      • setOutput

        public void setOutput​(java.lang.String value)
        Specify an output string to be sent. This method appends the specified string to a queue. Strings are retrieved from the queue by getOutput().
        Parameters:
        value - An output string to be sent.
        See Also:
        getOutput()
      • _customTypeConstraints

        protected java.util.Set<Inequality> _customTypeConstraints()
        Set the input port greater than or equal to BaseType.GENERAL in case backward type inference is enabled and the input port has no type declared.
        Overrides:
        _customTypeConstraints in class TypedAtomicActor
        Returns:
        A set of inequalities.
      • _exportMoMLContents

        protected void _exportMoMLContents​(java.io.Writer output,
                                           int depth)
                                    throws java.io.IOException
        Write a MoML description of the contents of this object. This overrides the base class to make sure that the current frame properties, if there is a frame, are recorded.
        Overrides:
        _exportMoMLContents in class Entity<TypedIOPort>
        Parameters:
        output - The output stream to write to.
        depth - The depth in the hierarchy, to determine indenting.
        Throws:
        java.io.IOException - If an I/O error occurs.
        See Also:
        NamedObj.exportMoML(Writer, int)