/* An attribute that stores the configuration of a generator tableau. Copyright (c) 1998-2007 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.copernicus.gui; import java.awt.Frame; import ptolemy.actor.gui.EditorFactory; import ptolemy.actor.gui.Effigy; import ptolemy.actor.gui.Tableau; import ptolemy.actor.gui.TableauFactory; import ptolemy.actor.gui.TableauFrame; import ptolemy.copernicus.kernel.GeneratorAttribute; import ptolemy.data.BooleanToken; import ptolemy.data.expr.SingletonParameter; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.InternalErrorException; import ptolemy.kernel.util.NameDuplicationException; import ptolemy.kernel.util.NamedObj; import ptolemy.kernel.util.Settable; ////////////////////////////////////////////////////////////////////////// //// GeneratorTableauAttribute /** This is an attribute that stores the configuration of a generator tableau. It contains a number of parameters that are presented to the user in the generator tableau to configure the generator. @author Edward A. Lee, Christopher Hylands @version $Id$ @since Ptolemy II 2.0 @Pt.ProposedRating Red (eal) @Pt.AcceptedRating Red (johnr) */ public class GeneratorTableauAttribute extends GeneratorAttribute { /** Construct an attribute with the given name contained by the specified * entity. The container argument must not be null, or a * NullPointerException will be thrown. This attribute will use the * workspace of the container for synchronization and version counts. * If the name argument is null, then the name is set to the empty string. * Increment the version of the workspace. * @param container The container. * @param name The name of this attribute. * @exception IllegalActionException If the attribute is not of an * acceptable class for the container, or if the name contains a period. * @exception NameDuplicationException If the name coincides with * an attribute already in the container. */ public GeneratorTableauAttribute(NamedObj container, String name) throws IllegalActionException, NameDuplicationException { super(container, name); SingletonParameter hide = new SingletonParameter(this, "_hideName"); hide.setToken(BooleanToken.TRUE); hide.setVisibility(Settable.EXPERT); new GeneratorTableauEditorFactory(this, "_editorFactory"); _tableauFactory = new GeneratorTableau.Factory(this, "_tableauFactory"); } /////////////////////////////////////////////////////////////////// //// private variables //// /** The tableau factory. */ private TableauFactory _tableauFactory; /////////////////////////////////////////////////////////////////// //// inner classes //// private class GeneratorTableauEditorFactory extends EditorFactory { public GeneratorTableauEditorFactory(NamedObj _container, String name) throws IllegalActionException, NameDuplicationException { super(_container, name); } /** Create an editor for configuring the specified object with the * specified parent window. * @param object The object to configure. * @param parent The parent window, or null if there is none. */ public void createEditor(NamedObj object, Frame parent) { try { Effigy effigy = ((TableauFrame) parent).getEffigy(); Tableau tableau = _tableauFactory.createTableau(effigy); if (tableau == null) { throw new Exception("Tableau factory returns null."); } tableau.setEditable(effigy.isModifiable()); tableau.show(); } catch (Exception ex) { throw new InternalErrorException(object, ex, "Cannot generate code. Perhaps outside Vergil?"); } } } }