ptolemy.actor.lib.gui
Class Display

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.gui.AbstractPlaceableActor
                              extended by ptolemy.actor.lib.gui.Display
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Actor, Executable, FiringsRecordable, Placeable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
Direct Known Subclasses:
NonStrictDisplay

public class Display
extends AbstractPlaceableActor

Display the values of the tokens arriving on the input channels in a text area on the screen. Each input token is written on a separate line. The input type can be of any type. If the input happens to be a StringToken, then the surrounding quotation marks are stripped before printing the value of the token. Thus, string-valued tokens can be used to generate arbitrary textual output, at one token per line. Tokens are read from the input only in the postfire() method, to allow them to settle in domains where they converge to a fixed point.

This actor has a suppressBlankLines parameter, whose default value is false. If this parameter is configured to be true, this actor does not put a blank line in the display.

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. To control the size, you should set the rowsDisplayed and columnsDisplayed parameters.

Note that this actor internally uses JTextArea, a Java Swing object that is known to consume large amounts of memory. It is not advisable to use this actor to log large output streams.

Since:
Ptolemy II 1.0
Version:
$Id: Display.java 57587 2010-04-13 00:31:37Z cxh $
Author:
Yuhong Xiong, Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Yellow (vogel)
Proposed Rating:
Yellow (yuhong)

Nested Class Summary
private static class Display.DisplayWindowTableau
          Version of TextEditorTableau that creates DisplayWindow.
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  java.awt.Container _container
           
protected  boolean _initialized
          Indicator that the display window has been opened.
private  int _previousNumColumns
           
private  int _previousNumRows
           
private  javax.swing.JScrollPane _scrollPane
           
protected  boolean _suppressBlankLines
          The flag indicating whether the blank lines will be suppressed.
private  Display.DisplayWindowTableau _tableau
          The version of TextEditorTableau that creates a Display window.
 Parameter columnsDisplayed
          The horizontal size of the display, in columns.
 TypedIOPort input
          The input port, which is a multiport.
 Parameter rowsDisplayed
          The vertical size of the display, in rows.
 Parameter suppressBlankLines
          The flag indicating whether this display actor suppress blank lines.
 javax.swing.JTextArea textArea
          The text area in which the data will be displayed.
 StringParameter title
          The title to put on top.
 
Fields inherited from class ptolemy.actor.gui.AbstractPlaceableActor
_frame, _paneSize, _windowProperties
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Display(CompositeEntity container, java.lang.String name)
          Construct an actor with an input multiport of type GENERAL.
 
Method Summary
protected  void _openWindow()
          Open the display window if it has not been opened.
private  void _remove()
          Remove the display from the current container, if there is one.
private  void _setTitle(java.lang.String name)
          Set the title of this window.
 void attributeChanged(Attribute attribute)
          If the specified attribute is rowsDisplayed, then set the desired number of rows of the textArea, if there is one.
 java.lang.Object clone(Workspace workspace)
          Clone the actor into the specified workspace.
 java.awt.Color getBackground()
          Get the background color.
 void initialize()
          Initialize this display.
 void place(java.awt.Container container)
          Specify the container in which the data should be displayed.
 boolean postfire()
          Read at most one token from each input channel and display its string value on the screen.
 void setBackground(java.awt.Color background)
          Set the background.
 void setContainer(CompositeEntity container)
          Override the base class to remove the display from its graphical container if the argument is null.
 void setDisplayName(java.lang.String name)
          Set a name to present to the user.
 void setName(java.lang.String name)
          Set or change the name.
 
Methods inherited from class ptolemy.actor.gui.AbstractPlaceableActor
_exportMoMLContents, setFrame
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, fire, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence
 
Methods inherited from class ptolemy.kernel.Entity
_description, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
fire, isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

columnsDisplayed

public Parameter columnsDisplayed
The horizontal size of the display, in columns. This contains an integer, and defaults to 40.


input

public TypedIOPort input
The input port, which is a multiport.


rowsDisplayed

public Parameter rowsDisplayed
The vertical size of the display, in rows. This contains an integer, and defaults to 10.


suppressBlankLines

public Parameter suppressBlankLines
The flag indicating whether this display actor suppress blank lines. The default value is false.


textArea

public transient javax.swing.JTextArea textArea
The text area in which the data will be displayed.


title

public StringParameter title
The title to put on top. Note that the value of the title overrides the value of the name of the actor or the display name of the actor.


_initialized

protected boolean _initialized
Indicator that the display window has been opened.


_suppressBlankLines

protected boolean _suppressBlankLines
The flag indicating whether the blank lines will be suppressed.


_container

private java.awt.Container _container

_previousNumColumns

private int _previousNumColumns

_previousNumRows

private int _previousNumRows

_scrollPane

private javax.swing.JScrollPane _scrollPane

_tableau

private Display.DisplayWindowTableau _tableau
The version of TextEditorTableau that creates a Display window.

Constructor Detail

Display

public Display(CompositeEntity container,
               java.lang.String name)
        throws IllegalActionException,
               NameDuplicationException
Construct an actor with an input multiport of type GENERAL.

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

attributeChanged

public void attributeChanged(Attribute attribute)
                      throws IllegalActionException
If the specified attribute is rowsDisplayed, then set the desired number of rows of the textArea, if there is one.

Overrides:
attributeChanged in class NamedObj
Parameters:
attribute - The attribute that has changed.
Throws:
IllegalActionException - If the specified attribute is rowsDisplayed and its value is not positive.

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the textArea public variable to null.

Overrides:
clone in class AtomicActor
Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

getBackground

public java.awt.Color getBackground()
Get the background color.

Returns:
The background color of the text area.
See Also:
setBackground(Color)

initialize

public void initialize()
                throws IllegalActionException
Initialize this display. If place() has not been called with a container into which to place the display, then create a new frame into which to put it.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If the parent class throws it, or if the numRows or numColumns parameters are incorrect, or if there is no effigy for the top level container, or if a problem occurs creating the effigy and tableau.

place

public void place(java.awt.Container container)
Specify the container in which the data should be displayed. An instance of JTextArea will be added to that container. This method needs to be called before the first call to initialize(). Otherwise, an instance of JTextArea will be placed in its own frame. The text area is also placed in its own frame if this method is called with a null argument. The background of the text area is set equal to that of the container (unless it is null).

Specified by:
place in interface Placeable
Specified by:
place in class AbstractPlaceableActor
Parameters:
container - The container into which to place the text area, or null to specify that there is no current container.

postfire

public boolean postfire()
                 throws IllegalActionException
Read at most one token from each input channel and display its string value on the screen. Each value is terminated with a newline character.

Specified by:
postfire in interface Executable
Overrides:
postfire in class AtomicActor
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - If there is no director.

setBackground

public void setBackground(java.awt.Color background)
Set the background.

Parameters:
background - The background color.
See Also:
getBackground()

setContainer

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

Overrides:
setContainer in class AtomicActor
Parameters:
container - The proposed container.
Throws:
IllegalActionException - If the base class throws it.
NameDuplicationException - If the base class throws it.
See Also:
ComponentEntity.getContainer()

setDisplayName

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

If the title parameter is set to the empty string, and the Display window has been rendered, then the title of the Display 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()

setName

public void setName(java.lang.String name)
             throws IllegalActionException,
                    NameDuplicationException
Set or change the name. If a null argument is given the name is set to an empty string. Increment the version of the workspace. This method is write-synchronized on the workspace.

If the title parameter is set to the empty string, and the Display window has been rendered, then the title of the Display window will be updated to the value of the name parameter.

Specified by:
setName in interface Nameable
Overrides:
setName in class ComponentEntity
Parameters:
name - The new name.
Throws:
IllegalActionException - If the name contains a period or if the object is a derived object and the name argument does not match the current name.
NameDuplicationException - Not thrown in this base class. May be thrown by derived classes if the container already contains an object with this name.
See Also:
NamedObj.getName(), NamedObj.getName(NamedObj), title

_openWindow

protected void _openWindow()
                    throws IllegalActionException
Open the display window if it has not been opened.

Throws:
IllegalActionException - If there is a problem creating the effigy and tableau.

_remove

private void _remove()
Remove the display from the current container, if there is one.


_setTitle

private void _setTitle(java.lang.String name)
Set the title of this window.

If the title parameter is set to the empty string, and the Display window has been rendered, then the title of the Display window will be updated to the value of the name parameter.