001/* TimeDisplay test actor 002 003 Copyright (c) 2000-2018 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 @ProposedRating Red (cxh) 027 @AcceptedRating Red (cxh) 028 */ 029package ptolemy.actor.lib.gui; 030 031import ptolemy.actor.Director; 032import ptolemy.actor.lib.SequenceActor; 033import ptolemy.kernel.CompositeEntity; 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036 037/////////////////////////////////////////////////////////////////// 038//// TimedDisplay 039 040/** 041 * Display the model time and the input. 042 * @author Christopher Brooks, based on dt/kernel/test/TimedDisplay.java by Chamberlain Fong 043 * @version $Id$ 044 * @since Ptolemy II 11.0 045 * @Pt.ProposedRating Red (cxh) 046 * @Pt.AcceptedRating Red (cxh)n 047 */ 048public class TimedDisplay extends Display implements SequenceActor { 049 050 /** Construct an actor with an input multiport of type GENERAL that 051 * displays the model time and the value of the input. 052 * @param container The container. 053 * @param name The name of this actor. 054 * @exception IllegalActionException If the entity cannot be contained 055 * by the proposed container. 056 * @exception NameDuplicationException If the container already has an 057 * actor with this name. 058 */ 059 public TimedDisplay(CompositeEntity container, String name) 060 throws IllegalActionException, NameDuplicationException { 061 super(container, name); 062 } 063 064 /** Return a string describing the model time of the containing director 065 * a colon and the input on channel i. 066 * @param i The channel 067 * @return A string representation of the input, or null if there 068 * is nothing to display. If there is no director, then only the 069 * value is returned. 070 * @exception IllegalActionException If reading the input fails. 071 */ 072 @Override 073 protected String _getInputString(int i) throws IllegalActionException { 074 String value = super._getInputString(i); 075 if (value == null) { 076 if (_isSuppressBlankLines) { 077 return null; 078 } 079 // Replace with an empty string to show a blank line. 080 value = ""; 081 } 082 083 Director director = getDirector(); 084 if (director != null) { 085 return director.getModelTime() + ": " + value; 086 } 087 return value; 088 } 089}