001/*
002 * Copyright (c) 2005-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.resurgence.actor;
031
032import ptolemy.actor.lib.Source;
033import ptolemy.data.StringToken;
034import ptolemy.data.expr.FileParameter;
035import ptolemy.data.type.BaseType;
036import ptolemy.kernel.CompositeEntity;
037import ptolemy.kernel.util.IllegalActionException;
038import ptolemy.kernel.util.NameDuplicationException;
039import ptolemy.vergil.icon.BoxedValueIcon;
040
041//////////////////////////////////////////////////////////////////////////
042//// PermanentStringConstant
043
044/**
045 * <p>
046 * This actor generates a sequence of the input string.
047 * </p>
048 * <p>
049 * It is based on the SDM SPA StringConst actor.
050 * </p>
051 * 
052 * @author Wibke Sudholt, University and ETH Zurich, November 2004
053 * @version $Id: PermanentStringConstant.java 13429 2007-02-01 20:18:02Z berkley
054 *          $
055 */
056
057public class PermanentStringConstant extends Source {
058
059        /**
060         * Construct a PermanentStringConstant with the given container and name.
061         * Create the <i>value</i> parameter.
062         * 
063         * @param container
064         *            The container.
065         * @param name
066         *            The name of this actor.
067         * @exception IllegalActionException
068         *                If the entity cannot be contained by the proposed
069         *                container.
070         * @exception NameDuplicationException
071         *                If the container already has an actor with this name.
072         */
073        public PermanentStringConstant(CompositeEntity container, String name)
074                        throws NameDuplicationException, IllegalActionException {
075                super(container, name);
076
077                // Use a file attribute to allow the output to be either a string
078                // typed by the user or a file URL selected using a file chooser.
079                value = new FileParameter(this, "value");
080
081                // Set the type constraint.
082                output.setTypeEquals(BaseType.STRING);
083
084                BoxedValueIcon icon = new BoxedValueIcon(this, "_icon");
085                icon.displayWidth.setExpression("25");
086                icon.attributeName.setExpression("value");
087        }
088
089        // /////////////////////////////////////////////////////////////////
090        // // ports and parameters ////
091
092        /**
093         * The value produced by this constant source.
094         */
095        public FileParameter value;
096
097        // /////////////////////////////////////////////////////////////////
098        // // public methods ////
099
100        /**
101         * Send the token in the <i>value</i> parameter to the output.
102         * 
103         * @exception IllegalActionException
104         *                If it is thrown by the send() method sending out the
105         *                token.
106         */
107        public void fire() throws IllegalActionException {
108                super.fire();
109                output.send(0, new StringToken(value.stringValue()));
110        }
111
112        // /////////////////////////////////////////////////////////////////
113        // // protected members ////
114
115        // /////////////////////////////////////////////////////////////////
116        // // private methods ////
117
118        // /////////////////////////////////////////////////////////////////
119        // // private members ////
120
121}