001/* A representative of an expression 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; 028 029import java.net.URL; 030 031import ptolemy.kernel.CompositeEntity; 032import ptolemy.kernel.util.IllegalActionException; 033import ptolemy.kernel.util.InternalErrorException; 034import ptolemy.kernel.util.KernelException; 035import ptolemy.kernel.util.NameDuplicationException; 036import ptolemy.kernel.util.NamedObj; 037import ptolemy.kernel.util.Workspace; 038 039/////////////////////////////////////////////////////////////////// 040//// ExpressionShellEffigy 041 042/** 043 A representative of an expression shell. 044 045 @see ptolemy.gui.ShellTextArea 046 @see ExpressionShellTableau 047 @author Edward A. Lee 048 @version $Id$ 049 @since Ptolemy II 3.0 050 @Pt.ProposedRating Red (eal) 051 @Pt.AcceptedRating Red (janneck) 052 */ 053public class ExpressionShellEffigy 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 ExpressionShellEffigy(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 ExpressionShellEffigy(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 ExpressionShellEffigy newObject = (ExpressionShellEffigy) super.clone( 090 workspace); 091 092 if (_model != null) { 093 newObject._model = (NamedObj) _model.clone(new Workspace()); 094 } 095 096 return newObject; 097 } 098 099 /** Return the model used to store variables. 100 * @return A model. 101 */ 102 public NamedObj getModel() { 103 return _model; 104 } 105 106 /////////////////////////////////////////////////////////////////// 107 //// private methods //// 108 // Initialization. 109 private void _init() { 110 _model = new NamedObj(); 111 112 try { 113 _model.setName("Expression"); 114 identifier.setExpression("Expression Evaluator"); 115 } catch (KernelException ex) { 116 throw new InternalErrorException(ex); 117 } 118 } 119 120 /////////////////////////////////////////////////////////////////// 121 //// private variables //// 122 123 /** A model used to store variables. */ 124 private NamedObj _model; 125 126 /////////////////////////////////////////////////////////////////// 127 //// inner classes //// 128 129 /** A factory for creating new Ptolemy effigies. 130 */ 131 public static class ShellFactory extends PtolemyEffigy.Factory { 132 /** Create a factory with the given name and container. 133 * @param container The container. 134 * @param name The name. 135 * @exception IllegalActionException If the container is incompatible 136 * with this entity. 137 * @exception NameDuplicationException If the name coincides with 138 * an entity already in the container. 139 */ 140 public ShellFactory(CompositeEntity container, String name) 141 throws IllegalActionException, NameDuplicationException { 142 super(container, name); 143 } 144 145 /////////////////////////////////////////////////////////////////// 146 //// public methods //// 147 148 /** Return true, indicating that this effigy factory is 149 * capable of creating an effigy without a URL being specified. 150 * @return True. 151 */ 152 @Override 153 public boolean canCreateBlankEffigy() { 154 return true; 155 } 156 157 /** If the <i>input</i> URL is null, then 158 * create a blank effigy; otherwise, return null. 159 * This effigy is not capable of reading a file. 160 * The blank effigy will have a new model associated with it. 161 * @param container The container for the effigy. 162 * @param base The base for relative file references, or null if 163 * there are no relative file references. 164 * @param input The input URL. 165 * @return A new instance of ExpressionShellEffigy, or null if the URL 166 * is not null. 167 * @exception Exception If there is some failure. 168 * is malformed in some way. 169 */ 170 @Override 171 public Effigy createEffigy(CompositeEntity container, URL base, 172 URL input) throws Exception { 173 if (input == null) { 174 return new ExpressionShellEffigy(container, 175 container.uniqueName("effigy")); 176 } 177 return null; 178 } 179 } 180}