001/* A constant source with a string value.
002
003 Copyright (c) 2004-2005 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
027 */
028package ptolemy.actor.lib;
029
030import ptolemy.data.type.BaseType;
031import ptolemy.kernel.CompositeEntity;
032import ptolemy.kernel.util.IllegalActionException;
033import ptolemy.kernel.util.NameDuplicationException;
034
035//////////////////////////////////////////////////////////////////////////
036//// StringConst
037
038/**
039 Produce a constant output of type string. This is similar to the base
040 class Const, which can also produce a string output, but this has the
041 added convenience that the string can be specified without the enclosing
042 double quotes. Moreover, the string can include references to parameters
043 within scope using the $name syntax. The value of the
044 output is that of the token contained by the <i>value</i> parameter,
045 which by default is an empty string.
046
047 @see ptolemy.data.expr.Variable
048 @author Edward A. Lee
049 @version $Id$
050 @since Ptolemy II 4.1
051 @Pt.ProposedRating Green (eal)
052 @Pt.AcceptedRating Red (bilung)
053 */
054public class StringConst extends Const {
055    /** Construct a constant source with the given container and name.
056     *  Create the <i>value</i> parameter, initialize its value.
057     *  @param container The container.
058     *  @param name The name of this actor.
059     *  @exception IllegalActionException If the entity cannot be contained
060     *   by the proposed container.
061     *  @exception NameDuplicationException If the container already has an
062     *   actor with this name.
063     */
064    public StringConst(CompositeEntity container, String name)
065            throws NameDuplicationException, IllegalActionException {
066        super(container, name);
067
068        value.setExpression("");
069        value.setStringMode(true);
070
071        // Set the type constraint.
072        output.setTypeEquals(BaseType.STRING);
073
074        _attachText("_iconDescription",
075                "<svg>\n" + "<rect x=\"0\" y=\"0\" "
076                        + "width=\"60\" height=\"20\" "
077                        + "style=\"fill:lightBlue\"/>\n" + "</svg>\n");
078    }
079}