001/* A tableau representing a Doc Builder window. 002 003 Copyright (c) 2006-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.vergil.actor; 028 029import ptolemy.actor.gui.Effigy; 030import ptolemy.actor.gui.MoMLApplication; 031import ptolemy.actor.gui.Tableau; 032import ptolemy.actor.gui.TableauFactory; 033import ptolemy.kernel.util.IllegalActionException; 034import ptolemy.kernel.util.NameDuplicationException; 035import ptolemy.kernel.util.NamedObj; 036 037/////////////////////////////////////////////////////////////////// 038//// DocBuilderTableau 039 040/** 041 A tableau representing a documentation builder. 042 043 <p> The constructor of this class creates the window. The text window 044 itself is an instance of DocBuilderGUI, and can be accessed using the 045 getFrame() method. As with other tableaux, this is an entity that is 046 contained by an effigy of a model. There can be any number of 047 instances of this class in an effigy. 048 049 @author Christopher Brooks 050 @version $Id$ 051 @since Ptolemy II 5.2 052 @Pt.ProposedRating Yellow (eal) 053 @Pt.AcceptedRating Red (cxh) 054 @see Effigy 055 @see DocBuilderGUI 056 @see MoMLApplication#specToURL(String) 057 */ 058public class DocBuilderTableau extends Tableau { 059 060 /** Construct a new tableau for the model represented by the given effigy. 061 * This creates an instance of DocBuildGUI. It does not make the frame 062 * visible. To do that, call show(). 063 * @param container The container. 064 * @param name The name. 065 * @exception IllegalActionException If the container does not accept 066 * this entity (this should not occur). 067 * @exception NameDuplicationException If the name coincides with an 068 * attribute already in the container. 069 */ 070 public DocBuilderTableau(Effigy container, String name) 071 throws IllegalActionException, NameDuplicationException { 072 super(container, name); 073 try { 074 DocBuilder docBuilder = new DocBuilder(container, 075 container.uniqueName("myDocBuilder")); 076 DocBuilderGUI frame = new DocBuilderGUI(docBuilder, this); 077 setFrame(frame); 078 frame.setTableau(this); 079 } catch (Exception ex) { 080 throw new IllegalActionException(this, container, ex, 081 "Malformed URL"); 082 } 083 } 084 085 /////////////////////////////////////////////////////////////////// 086 //// inner classes //// 087 088 /** A factory that creates DocBuilderGUI tableaux for Ptolemy models. 089 */ 090 public static class Factory extends TableauFactory { 091 /** Create a factory with the given name and container. 092 * @param container The container. 093 * @param name The name. 094 * @exception IllegalActionException If the container is incompatible 095 * with this attribute. 096 * @exception NameDuplicationException If the name coincides with 097 * an attribute already in the container. 098 */ 099 public Factory(NamedObj container, String name) 100 throws IllegalActionException, NameDuplicationException { 101 super(container, name); 102 } 103 104 /////////////////////////////////////////////////////////////////// 105 //// public methods //// 106 107 /** If the specified effigy already contains a tableau named 108 * "DocBuilderTableau", then return that tableau; otherwise, create 109 * a new instance of DocBuilderTableau in the specified 110 * effigy, and name it "DocBuilderTableau". If the specified 111 * effigy is not an instance of DocBuilderEffigy, then do not 112 * create a tableau and return null. It is the 113 * responsibility of callers of this method to check the 114 * return value and call show(). 115 * 116 * @param effigy The effigy. 117 * @return A DocBuilder tableau, or null if one cannot be 118 * found or created. 119 * @exception Exception If the factory should be able to create a 120 * tableau for the effigy, but something goes wrong. 121 */ 122 @Override 123 public Tableau createTableau(Effigy effigy) throws Exception { 124 // Indicate to the effigy that this factory contains effigies 125 // offering multiple views of the effigy data. 126 effigy.setTableauFactory(this); 127 128 // First see whether the effigy already contains an 129 // DocBuilderTableau. 130 DocBuilderTableau tableau = (DocBuilderTableau) effigy 131 .getEntity("DocBuilderTableau"); 132 133 if (tableau == null) { 134 tableau = new DocBuilderTableau(effigy, "DocBuilderTableau"); 135 } 136 // Don't call show() here. If show() is called here, 137 // then you can't set the size of the window after 138 // createTableau() returns. This will affect how 139 // centering works. 140 return tableau; 141 } 142 } 143}