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