001/* A representative of a Tcl shell.
002
003 Copyright (c) 2003-2014 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 */
027package ptolemy.actor.gui.ptjacl;
028
029import java.net.URL;
030
031import ptolemy.actor.gui.Effigy;
032import ptolemy.actor.gui.PtolemyEffigy;
033import ptolemy.kernel.CompositeEntity;
034import ptolemy.kernel.util.IllegalActionException;
035import ptolemy.kernel.util.InternalErrorException;
036import ptolemy.kernel.util.KernelException;
037import ptolemy.kernel.util.NameDuplicationException;
038import ptolemy.kernel.util.NamedObj;
039import ptolemy.kernel.util.Workspace;
040
041///////////////////////////////////////////////////////////////////
042//// TclShellEffigy
043
044/**
045 A representative of an Tcl expression shell.
046
047 @author Edward A. Lee, Christopher Hylands
048 @version $Id$
049 @since Ptolemy II 1.0
050 @Pt.ProposedRating Red (eal)
051 @Pt.AcceptedRating Red (janneck)
052 */
053public class TclShellEffigy extends Effigy {
054    /** Create a new effigy in the specified workspace with an empty string
055     *  for its name.
056     *  @param workspace The workspace for this effigy.
057     */
058    public TclShellEffigy(Workspace workspace) {
059        super(workspace);
060        _init();
061    }
062
063    /** Create a new effigy in the given container with the given name.
064     *  @param container The container that contains this effigy.
065     *  @param name The name of this effigy.
066     *  @exception IllegalActionException If the entity cannot be contained
067     *   by the proposed container.
068     *  @exception NameDuplicationException If the name coincides with
069     *   an entity already in the container.
070     */
071    public TclShellEffigy(CompositeEntity container, String name)
072            throws IllegalActionException, NameDuplicationException {
073        super(container, name);
074        _init();
075    }
076
077    ///////////////////////////////////////////////////////////////////
078    ////                         public methods                    ////
079
080    /** Clone the object into the specified workspace. This calls the
081     *  base class and then clones the associated model.
082     *  @param workspace The workspace for the new effigy.
083     *  @return A new effigy.
084     *  @exception CloneNotSupportedException If a derived class contains
085     *   an attribute that cannot be cloned.
086     */
087    @Override
088    public Object clone(Workspace workspace) throws CloneNotSupportedException {
089        TclShellEffigy newObject = (TclShellEffigy) super.clone(workspace);
090
091        if (_model != null) {
092            newObject._model = (NamedObj) _model.clone(new Workspace());
093        }
094
095        return newObject;
096    }
097
098    /** Return the model used to store variables.
099     *  @return A model.
100     */
101    public NamedObj getModel() {
102        return _model;
103    }
104
105    ///////////////////////////////////////////////////////////////////
106    ////                         private methods                   ////
107    // Initialization.
108    private void _init() {
109        _model = new NamedObj();
110
111        try {
112            _model.setName("Tcl");
113            identifier.setExpression("Tcl Evaluator");
114        } catch (KernelException ex) {
115            throw new InternalErrorException(ex);
116        }
117    }
118
119    ///////////////////////////////////////////////////////////////////
120    ////                         private variables                 ////
121
122    /** A model used to store variables. */
123    private NamedObj _model;
124
125    ///////////////////////////////////////////////////////////////////
126    ////                         inner classes                     ////
127
128    /** A factory for creating new Ptolemy effigies.
129     */
130    public static class ShellFactory extends PtolemyEffigy.Factory {
131        /** Create a factory with the given name and container.
132         *  @param container The container.
133         *  @param name The name.
134         *  @exception IllegalActionException If the container is incompatible
135         *   with this entity.
136         *  @exception NameDuplicationException If the name coincides with
137         *   an entity already in the container.
138         */
139        public ShellFactory(CompositeEntity container, String name)
140                throws IllegalActionException, NameDuplicationException {
141            super(container, name);
142        }
143
144        ///////////////////////////////////////////////////////////////////
145        ////                         public methods                    ////
146
147        /** Return true, indicating that this effigy factory is
148         *  capable of creating an effigy without a URL being specified.
149         *  @return True.
150         */
151        @Override
152        public boolean canCreateBlankEffigy() {
153            return true;
154        }
155
156        /** If the <i>input</i> URL is null, then
157         *  create a blank effigy; otherwise, return null.
158         *  This effigy is not capable of reading a file.
159         *  The blank effigy will have a new model associated with it.
160         *  @param container The container for the effigy.
161         *  @param base The base for relative file references, or null if
162         *   there are no relative file references.
163         *  @param input The input URL.
164         *  @return A new instance of TclShellEffigy, or null if the URL
165         *   is not null.
166         *  @exception Exception If there is some failure.
167         *   is malformed in some way.
168         */
169        @Override
170        public Effigy createEffigy(CompositeEntity container, URL base,
171                URL input) throws Exception {
172            return new TclShellEffigy(container,
173                    container.uniqueName("effigy"));
174        }
175    }
176}