ptolemy.actor.lib.gui
Class InteractiveShell

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.gui.InteractiveShell
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, ptolemy.actor.gui.Placeable, java.io.Serializable, ptolemy.gui.ShellInterpreter, ptolemy.actor.TypedActor

public class InteractiveShell
extends ptolemy.actor.TypedAtomicActor
implements ptolemy.actor.gui.Placeable, ptolemy.gui.ShellInterpreter

This actor creates a command shell on the screen, sending commands that are typed by the user to its output port, and reporting strings 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.

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: InteractiveShell.java,v 1.16 2004/04/13 05:12:32 cxh Exp $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 class InteractiveShell.ShellFrame
          The frame that is created by an instance of ShellTableau.
 class InteractiveShell.ShellTableau
          Version of ExpressionShellTableau that records the size of the display when it is closed.
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.actor.TypedIOPort input
          The input port.
 ptolemy.actor.TypedIOPort output
          The output port.
 PortParameter prompt
          The prompt.
 ptolemy.gui.ShellTextArea shell
          The shell window object.
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
InteractiveShell(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
protected  void _exportMoMLContents(java.io.Writer output, int depth)
          Write a MoML description of the contents of this object.
 java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
          Clone the actor into the specified workspace.
 java.lang.String evaluateCommand(java.lang.String command)
          Evaluate the specified command.
 void fire()
          Read and display the input, then wait for user input and produce the user data on the output.
 java.lang.String getOutput()
          Get the output string to be sent.
 void initialize()
          If the shell has not already been created, create it.
 boolean isCommandComplete(java.lang.String command)
          Return true if the specified command is complete (ready to be interpreted).
 void place(java.awt.Container container)
          Specify the container into which this shell should be placed.
 boolean postfire()
          Override the base class to return false if the user has typed "quit" or "exit".
 void setContainer(ptolemy.kernel.CompositeEntity container)
          Override the base class to remove the shell from its graphical container if the argument is null.
 void setOutput(java.lang.String value)
          Specify an output string to be sent.
 void stop()
          Override the base class to call notifyAll() to get out of any waiting.
 void wrapup()
          Override the base class to make the shell uneditable.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, removeDependency, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, prefire, preinitialize, stopFire, terminate
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

Field Detail

input

public ptolemy.actor.TypedIOPort input
The input port.


output

public ptolemy.actor.TypedIOPort output
The output port.


prompt

public PortParameter prompt
The prompt. The initial default is the string >>. Double quotes are not necessary.


shell

public ptolemy.gui.ShellTextArea shell
The shell window object.

Constructor Detail

InteractiveShell

public InteractiveShell(ptolemy.kernel.CompositeEntity container,
                        java.lang.String name)
                 throws ptolemy.kernel.util.IllegalActionException,
                        ptolemy.kernel.util.NameDuplicationException
Construct an actor with the given container and name.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

clone

public java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace.

Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class has an attribute that cannot be cloned.

evaluateCommand

public java.lang.String evaluateCommand(java.lang.String command)
                                 throws java.lang.Exception
Evaluate the specified command.

Specified by:
evaluateCommand in interface ptolemy.gui.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.

fire

public void fire()
          throws ptolemy.kernel.util.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 ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.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.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
If the shell has not already been created, create it. Then wait for user input and produce it on the output.

Specified by:
initialize in interface ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.IllegalActionException - If the parent class throws it.

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 ptolemy.gui.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 ptolemy.actor.gui.Placeable
Parameters:
container - The container into which to place the shell, or null to specify that a new shell should be created.

postfire

public boolean postfire()
                 throws ptolemy.kernel.util.IllegalActionException
Override the base class to return false if the user has typed "quit" or "exit".

Specified by:
postfire in interface ptolemy.actor.Executable
Returns:
False if the user has typed "quit" or "exit".
Throws:
ptolemy.kernel.util.IllegalActionException - If the superclass throws it.

setContainer

public void setContainer(ptolemy.kernel.CompositeEntity container)
                  throws ptolemy.kernel.util.IllegalActionException,
                         ptolemy.kernel.util.NameDuplicationException
Override the base class to remove the shell from its graphical container if the argument is null.

Parameters:
container - The proposed container.
Throws:
ptolemy.kernel.util.IllegalActionException - If the base class throws it.
ptolemy.kernel.util.NameDuplicationException - If the base class throws it.

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()

stop

public void stop()
Override the base class to call notifyAll() to get out of any waiting.

Specified by:
stop in interface ptolemy.actor.Executable

wrapup

public void wrapup()
            throws ptolemy.kernel.util.IllegalActionException
Override the base class to make the shell uneditable.

Specified by:
wrapup in interface ptolemy.actor.Executable
Throws:
ptolemy.kernel.util.IllegalActionException - If the parent class throws it.

_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.

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.