001/* Interface for parameters that provide web export content.
002
003 Copyright (c) 2011-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
027 */
028
029package ptolemy.vergil.basic;
030
031import java.awt.Color;
032import java.io.File;
033
034import ptolemy.kernel.util.Attribute;
035import ptolemy.kernel.util.NamedObj;
036import ptolemy.vergil.basic.export.web.WebExportParameters;
037
038///////////////////////////////////////////////////////////////////
039//// ExportParameters
040/**
041 * A data structure containing parameters for exporting a
042 * Ptolemy model to a web page.
043 * This data structure will typically be provided by an instance
044 * of {@link WebExportParameters}, which is an
045 * {@link Attribute} that can be stored in a model.
046 *
047 * @author Christopher Brooks and Edward A. Lee
048 * @version $Id$
049 * @since Ptolemy II 10.0
050 * @Pt.ProposedRating Red (cxh)
051 * @Pt.AcceptedRating Red (cxh)
052 */
053public class ExportParameters {
054
055    /** Construct an instance of this data structure with
056     *  default values, which are
057     *  null for backgroundColor,
058     *  false for copyJavaScriptFiles,
059     *  null for directoryToExportTo,
060     *  false for openCompositesBeforeExport,
061     *  false for runBeforeExport,
062     *  and true for showInBrowser.
063     */
064    public ExportParameters() {
065        this(null);
066    }
067
068    /** Construct an instance of this data structure with
069     *  default values, which are
070     *  null for backgroundColor,
071     *  false for copyJavaScriptFiles,
072     *  false for deleteFilesOnExit,
073     *  false for openCompositesBeforeExport,
074     *  false for runBeforeExport,
075     *  true for showInBrowser,
076     *  and empty String for HTMLPathForFiles.
077     *  @param directoryToExportTo The directory to export to.
078     */
079    public ExportParameters(File directoryToExportTo) {
080        this.directoryToExportTo = directoryToExportTo;
081        backgroundColor = null;
082        deleteFilesOnExit = false;
083        imageFormat = "gif";
084        openCompositesBeforeExport = false;
085        runBeforeExport = false;
086        showInBrowser = true;
087        copyJavaScriptFiles = false;
088        _jsCopier = null;
089        HTMLPathForFiles = "";
090    }
091
092    /** Construct an instance of this data structure that is
093     *  identical to the one given except for directoryToExportTo,
094     *  which is as specified.
095     *  @param directoryToExportTo The directory to export to.
096     *  @param template The template parameters.
097     */
098    public ExportParameters(File directoryToExportTo,
099            ExportParameters template) {
100        this.directoryToExportTo = directoryToExportTo;
101        backgroundColor = template.backgroundColor;
102        deleteFilesOnExit = template.deleteFilesOnExit;
103        imageFormat = template.imageFormat;
104        openCompositesBeforeExport = template.openCompositesBeforeExport;
105        runBeforeExport = template.runBeforeExport;
106        showInBrowser = template.showInBrowser;
107        copyJavaScriptFiles = template.copyJavaScriptFiles;
108        _jsCopier = template._jsCopier;
109        HTMLPathForFiles = template.HTMLPathForFiles;
110    }
111
112    ///////////////////////////////////////////////////////////////////
113    ////                         public methods                    ////
114
115    /** Get the composite entity that
116     *  is copying JavaScript and
117     *  related files; return null if they are not being copied.
118     *  Note that this would ideally be protected, as it is used
119     *  only by ExportHTMLAction, but to avoid package dependencies,
120     *  we have to make it public.
121     *  @return The composite entity that is set to copy JavaScript and related files,
122     *  or null if they are not being copied.
123     *  @see #setJSCopier(NamedObj)
124     */
125    public NamedObj getJSCopier() {
126        return _jsCopier;
127    }
128
129    /** Specify the composite entity responsible for copying JavaScript and
130     *  related files. Set to null if they are not being copied.
131     *  This will normally be the same as the model for which these
132     *  parameters apply, its container, or a container above that
133     *  in the hierarchy.
134     *  Note that this would ideally be protected, as it is used
135     *  only by ExportHTMLAction, but to avoid package dependencies,
136     *  we have to make it public.
137     *  @param copier The composite entity responsible for
138     *   copying JavaScript and related files.
139     *  @see #getJSCopier()
140     */
141    public void setJSCopier(NamedObj copier) {
142        _jsCopier = copier;
143    }
144
145    ///////////////////////////////////////////////////////////////////
146    ////                         public fields                     ////
147
148    /** Background color. A null value indicates
149     *  to use the background color of the model.
150     */
151    public Color backgroundColor;
152
153    /** If true, then make an exported web page stand alone.
154     *  Instead of referencing JavaScript and image files on the
155     *  ptolemy.org website, if this parameter is true, then the
156     *  required files will be copied into the target directory.
157     *  This is a boolean that defaults to false.
158     */
159    public boolean copyJavaScriptFiles;
160
161    /** If true, files generated will be deleted when the JVM terminates.
162     */
163    public boolean deleteFilesOnExit;
164
165    /** The directory to export to.
166     */
167    public File directoryToExportTo;
168
169    /** The path to use for accessing the file in the HTML code.  This can
170     *  differ from the physical location of the file in the file system
171     *  depending on how the exporter accesses the files.  For example,
172     *  an HttpService uses a URL as a path since the WebServer has a
173     *  resource handler to serve files.  The HTML to include e.g. an image
174     *  would be:
175     *  <pre>
176     *  &lt;img src="/files/imagename.gif"/&gt;
177     *  </pre>
178     *  even though the image is stored in $PTT/org/ptolemy/ptango/temp, since
179     *  the resource handler is mapped to http://hostname:port/servicename/files.
180     */
181    public String HTMLPathForFiles;
182
183    /** The image format to use, which can be one of "gif" (the default),
184     *  "png", or "jpg".
185     */
186    public String imageFormat;
187
188    /** If true, hierarchically open all composite actors
189     *  in the model before exporting (so that these also
190     *  get exported, and hyperlinks to them are created).
191     */
192    public boolean openCompositesBeforeExport;
193
194    /** If true, run the model before exporting (to open plotter
195     *  or other display windows that get exported). Note that
196     *  it is important the model have a finite run.
197     */
198    public boolean runBeforeExport;
199
200    /** If true, open a web browser to display the resulting
201     *  export.
202     */
203    public boolean showInBrowser;
204
205    /** If true, use the server-side includes of the Ptolemy website. */
206    public boolean usePtWebsite;
207
208    ///////////////////////////////////////////////////////////////////
209    ////                         protected fields                  ////
210
211    /** Directory into which JavaScript and related files have been written,
212     *  or null if they are not being copied.
213     */
214    protected NamedObj _jsCopier = null;
215}