001/* Plotter applet that is capable of reading pxgraph files. 002 003 @Author: Edward A. Lee 004 005 @Version: $Id$ 006 007 @Copyright (c) 1997-2014 The Regents of the University of California. 008 All rights reserved. 009 010 Permission is hereby granted, without written agreement and without 011 license or royalty fees, to use, copy, modify, and distribute this 012 software and its documentation for any purpose, provided that the 013 above copyright notice and the following two paragraphs appear in all 014 copies of this software. 015 016 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 017 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 018 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 019 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 020 SUCH DAMAGE. 021 022 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 023 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 024 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 025 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 026 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 027 ENHANCEMENTS, OR MODIFICATIONS. 028 029 PT_COPYRIGHT_VERSION_2 030 COPYRIGHTENDKEY 031 */ 032package ptolemy.plot.compat; 033 034import java.io.FileNotFoundException; 035import java.io.IOException; 036import java.io.InputStream; 037 038import ptolemy.plot.CmdLineArgException; 039import ptolemy.plot.Plot; 040import ptolemy.plot.PlotApplet; 041import ptolemy.plot.PlotBox; 042 043/////////////////////////////////////////////////////////////////// 044//// PxgraphApplet 045 046/** 047 An Applet that can plot data in pxgraph format from a URL. 048 The URL should be specified using the dataurl applet parameter 049 or as part of the <i>pxgraphargs</i> applet parameter. 050 That parameter contains command-line style arguments compatible with 051 the older pxgraph program. 052 See the documentation for the PxgraphParser class for the format of 053 these arguments. 054 055 @author Edward A. Lee 056 @version $Id$ 057 @since Ptolemy II 0.4 058 @Pt.ProposedRating red (eal) 059 @Pt.AcceptedRating red (cxh) 060 @see PxgraphParser 061 @see ptolemy.plot.PlotBox 062 @see ptolemy.plot.Plot 063 */ 064@SuppressWarnings("serial") 065public class PxgraphApplet extends PlotApplet { 066 /** Return a string describing this applet. 067 */ 068 @Override 069 public String getAppletInfo() { 070 return "PxgraphApplet " + PlotBox.PTPLOT_RELEASE + ": A data plotter.\n" 071 + "By: Edward A. Lee and\n " + "Christopher Hylands\n" 072 + "($Id$)"; 073 } 074 075 /** Return information about parameters. 076 */ 077 @Override 078 public String[][] getParameterInfo() { 079 String[][] pinfo = { 080 { "background", "hexcolor value", "background color" }, 081 { "foreground", "hexcolor value", "foreground color" }, 082 { "dataurl", "url", "the URL of the data to plot" }, 083 { "pxgraphargs", "args", 084 "pxgraph style command line arguments" } }; 085 return pinfo; 086 } 087 088 /** Initialize the applet. Read the applet parameters. 089 */ 090 @Override 091 public void init() { 092 if (plot() == null) { 093 // This is a bit of a hack to make sure that we actually 094 // have a plot to operate on. 095 setPlot(newPlot()); 096 } 097 098 _parser = new PxgraphParser((Plot) plot()); 099 100 super.init(); 101 102 // Process the pxgraphargs parameter. 103 String pxgraphargs = null; 104 pxgraphargs = getParameter("pxgraphargs"); 105 106 if (pxgraphargs != null) { 107 try { 108 // Since there may be filenames specified here, we 109 // set the document base. Note that we prefer that files and 110 // URLs be specified using the dataurl parameter. 111 showStatus("Reading arguments"); 112 _parser.parsePxgraphargs(pxgraphargs, getDocumentBase()); 113 showStatus("Done reading arguments"); 114 } catch (CmdLineArgException e) { 115 System.err.println("PxgraphApplet: failed to parse `" 116 + pxgraphargs + "': " + e); 117 } catch (FileNotFoundException e) { 118 System.err.println(e.toString()); 119 } catch (IOException e) { 120 System.err.println(e.toString()); 121 } 122 } 123 124 // Because things may occur in an odd order above... 125 plot().repaint(); 126 } 127 128 /////////////////////////////////////////////////////////////////// 129 //// protected methods //// 130 131 /** Read the specified stream, assuming it is pxgraph formatted data. 132 * @param in The input stream. 133 * @exception IOException If the stream cannot be read. 134 */ 135 @Override 136 protected void _read(InputStream in) throws IOException { 137 _parser.read(in); 138 } 139 140 /////////////////////////////////////////////////////////////////// 141 //// private members //// 142 // Parser. 143 private PxgraphParser _parser; 144}