Class Display

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, PortablePlaceable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    DisplayAll, NonStrictDisplay, PetriNetDisplay, TimedDisplay

    public class Display
    extends TypedAtomicActor
    implements PortablePlaceable

    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 accepts any type of data on its input port, therefore it doesn't declare a type, but lets the type resolution algorithm find the least fixed point. If backward type inference is enabled, and no input type has been declared, the input is constrained to be equal to BaseType.GENERAL. This will result in upstream ports resolving to the most general type rather than the most specific.

    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$
    Author:
    Yuhong Xiong, Edward A. Lee Contributors: Ishwinder Singh
    Pt.AcceptedRating:
    Yellow (vogel)
    Pt.ProposedRating:
    Yellow (yuhong)
    • 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.
      • 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.
      • _isSuppressBlankLines

        protected boolean _isSuppressBlankLines
        The flag indicating whether the blank lines will be suppressed.
    • 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.
      • cleanUp

        public void cleanUp()
        Free up memory when closing.
      • 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<TypedIOPort>
        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​(PortableContainer container)
        Specify the container into which this object should be placed. Obviously, this method needs to be called before the object is actually placed in a container. Otherwise, the object will be expected to create its own frame into which to place itself. For actors, this method should be called before initialize().
        Specified by:
        place in interface PortablePlaceable
        Parameters:
        container - The container in which to place the object, or null to specify that there is no current container.
      • 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<TypedIOPort>
        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
      • _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.
      • _getImplementation

        protected DisplayInterface _getImplementation()
        Get the right instance of the implementation depending upon the of the dependency specified through dependency injection. If the instance has not been created, then it is created. If the instance already exists then return the same.

        This code is used as part of the dependency injection needed for the HandSimDroid project, see $PTII/ptserver. This code uses dependency inject to determine what implementation to use at runtime. This method eventually reads ptolemy/actor/ActorModule.properties. ActorModuleInitializer.initializeInjector() should be called before this method is called. If it is not called, then a message is printed and initializeInjector() is called.

        Returns:
        the instance of the implementation.
      • _getInputString

        protected java.lang.String _getInputString​(int i)
                                            throws IllegalActionException
        Return a string describing the input on channel i. This is a protected method to allow subclasses to override how inputs are observed.
        Parameters:
        i - The channel
        Returns:
        A string representation of the input, or null if there is nothing to display.
        Throws:
        IllegalActionException - If reading the input fails.