/* Plotter application that is capable of reading pxgraph files. @Author: Edward A. Lee and Christopher Hylands @Version: $Id: PxgraphApplication.java,v 1.24 2003/04/29 03:05:20 cxh Exp $ @Copyright (c) 1997-2003 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 @ProposedRating red (eal@eecs.berkeley.edu) @AcceptedRating red (cxh@eecs.berkeley.edu) */ package ptolemy.plot.compat; import ptolemy.plot.CmdLineArgException; import ptolemy.plot.Plot; import ptolemy.plot.PlotApplication; import ptolemy.plot.PlotBox; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.StringTokenizer; import java.awt.Point; import javax.swing.JOptionPane; ////////////////////////////////////////////////////////////////////////// //// PxgraphApplication /** An application that can plot data in pxgraph format. To compile and run this application, do the following:
javac -classpath ../../.. PxgraphApplication.java java -classpath ../../.. ptolemy.plot.compat.PxgraphApplication
This class uses the helper class PxgraphParser to parse command-line arguments and binary files. See that class for documentation on the formats. @author Edward A. Lee @version $Id: PxgraphApplication.java,v 1.24 2003/04/29 03:05:20 cxh Exp $ @since Ptolemy II 0.4 @see PxgraphParser @see Plot */ public class PxgraphApplication extends PlotApplication { /** Construct a plot with no command-line arguments. * It initially displays a sample plot. * @exception Exception If command line arguments have problems. */ public PxgraphApplication() throws Exception { this(null); } /** Construct a plot with the specified command-line arguments. * @param args The command-line arguments. * @exception Exception If command line arguments have problems. */ public PxgraphApplication(String args[]) throws Exception { this(new Plot(), args); } /** Construct a plot with the specified command-line arguments * and instance of plot. * @param args The command-line arguments. * @exception Exception If command line arguments have problems. */ public PxgraphApplication(Plot plot, String args[]) throws Exception { super(plot, args); } /////////////////////////////////////////////////////////////////// //// public methods //// /** Create a new plot window and map it to the screen. */ public static void main(String args[]) { try { new PxgraphApplication(new Plot(), args); } catch (Exception ex) { ex.printStackTrace(); } // If the -test arg was set, then exit after 2 seconds. if (_test) { try { Thread.sleep(2000); } catch (InterruptedException e) { } System.exit(0); } } /////////////////////////////////////////////////////////////////// //// protected methods //// /** Display basic information about the application. */ protected void _about() { JOptionPane.showMessageDialog(this, " pxgraph\n" + " A Java Plotting Tool\n\n" + "By: Edward A. Lee, eal@eecs.berkeley.edu and\n" + " Christopher Hylands, cxh@eecs.berkeley.edu\n" + "Version " + PlotBox.PTPLOT_RELEASE + ", Build: $Id: PxgraphApplication.java,v 1.24 2003/04/29 03:05:20 cxh Exp $\n\n"+ "For help, type 'pxgraph -help', or see \n" + "the class documentation in the plot.compat package.\n" + "For more information, see\n" + "http://ptolemy.eecs.berkeley.edu/java/ptplot\n", "About pxgraph", JOptionPane.INFORMATION_MESSAGE); } /** Parse those command-line arguments that are relevant to the * application only, and refer other arguments to the PxgraphParser * helper class. * @return The number of arguments read. * @exception CmdLineArgException If a command line argument cannot * be parsed. * @exception FileNotFoundException If an input file cannot be found. * @exception IOException If there is a problem reading an input. */ protected int _parseArgs(String args[]) throws CmdLineArgException, FileNotFoundException, IOException { int i = 0, argumentsRead; String arg; String title = "Ptolemy plot, pxgraph version"; int width = 400; // Default width of the graph int height = 300; // Default height of the graph // Although most of the arguments are handled by the Plot class, // a few are dealt with here. while (args != null && i < args.length) { arg = args[i++]; if (arg.equals("-help")) { // -help is not in the original X11 pxgraph. System.out.println(_usage()); System.exit(0); continue; } else if (arg.equals("-test")) { // -test is not in the original X11 pxgraph. _test = true; continue; } else if (arg.equals("-t")) { // -t