/* Plotter application that is capable of reading pxgraph files. @Author: Edward A. Lee and Christopher Hylands @Version: $Id: PxgraphApplication.java,v 1.48 2006/08/21 21:22:52 cxh Exp $ @Copyright (c) 1997-2006 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.plot.compat; import java.awt.Point; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.StringTokenizer; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import ptolemy.plot.CmdLineArgException; import ptolemy.plot.Plot; import ptolemy.plot.PlotApplication; import ptolemy.plot.PlotBox; import ptolemy.util.StringUtilities; ////////////////////////////////////////////////////////////////////////// //// 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.48 2006/08/21 21:22:52 cxh Exp $ @since Ptolemy II 0.4 @Pt.ProposedRating red (eal) @Pt.AcceptedRating red (cxh) @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 plot The 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. * @param args The command line arguments. To see what command * line arguments are available, run with "-help" as the first element. */ public static void main(final String[] args) { try { // Run this in the Swing Event Thread. Runnable doActions = new Runnable() { public void run() { try { new PxgraphApplication(new Plot(), args); } catch (Exception ex) { System.err.println(ex.toString()); ex.printStackTrace(); } } }; SwingUtilities.invokeAndWait(doActions); } 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 and\n" + " Christopher Brooks\n" + "Version " + PlotBox.PTPLOT_RELEASE + ", Build: $Id: PxgraphApplication.java,v 1.48 2006/08/21 21:22:52 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. * @param args The command line arguments to parse. * @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; int 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()); StringUtilities.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