001/* Histogram application that is capable of reading PlotML 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.plotml; 033 034import javax.swing.JOptionPane; 035import javax.swing.SwingUtilities; 036 037import ptolemy.plot.Histogram; 038import ptolemy.plot.PlotBox; 039import ptolemy.util.StringUtilities; 040 041/////////////////////////////////////////////////////////////////// 042//// HistogramMLApplication 043 044/** 045 An application that can histogram data in PlotML format from a URL or 046 from files specified on the command line. 047 To compile and run this application, do the following: 048 <pre> 049 javac -classpath ../../.. HistogramMLApplication.java 050 java -classpath ../../.. ptolemy.plot.plotml.HistogramMLApplication 051 </pre> 052 053 @author Edward A. Lee 054 @version $Id$ 055 @since Ptolemy II 0.4 056 @Pt.ProposedRating red (eal) 057 @Pt.AcceptedRating red (cxh) 058 @see Histogram 059 */ 060@SuppressWarnings("serial") 061public class HistogramMLApplication extends PlotMLApplication { 062 /** Construct a histogram with no command-line arguments. 063 * It initially displays a sample plot. 064 * @exception Exception If command line arguments have problems. 065 */ 066 public HistogramMLApplication() throws Exception { 067 this(null); 068 } 069 070 /** Construct a plot with the specified command-line arguments. 071 * @param args The command-line arguments. 072 * @exception Exception If command line arguments have problems. 073 */ 074 public HistogramMLApplication(String[] args) throws Exception { 075 this(new Histogram(), args); 076 } 077 078 /** Construct a plot with the specified command-line arguments 079 * and instance of plot. 080 * @param plot The instance of Histogram to use. 081 * @param args The command-line arguments. 082 * @exception Exception If command line arguments have problems. 083 */ 084 public HistogramMLApplication(Histogram plot, String[] args) 085 throws Exception { 086 super(plot, args); 087 setTitle("Ptolemy Histogram"); 088 } 089 090 /////////////////////////////////////////////////////////////////// 091 //// public methods //// 092 093 /** Create a new plot window and map it to the screen. 094 * The command to run would be: 095 * <pre> 096 * java -classpath $PTII ptolemy.plot.plotml.HistogramMLApplication 097 * </pre> 098 * @param args Arguments suitable for the 099 * {@link ptolemy.plot.Histogram} class. 100 */ 101 public static void main(final String[] args) { 102 try { 103 Runnable doActions = new Runnable() { 104 @Override 105 public void run() { 106 try { 107 new HistogramMLApplication(new Histogram(), args); 108 } catch (Exception ex) { 109 System.err.println(ex.toString()); 110 ex.printStackTrace(); 111 } 112 } 113 }; 114 115 // NOTE: Using invokeAndWait() here risks causing 116 // deadlock. However, the Sun Tutorial recommends calling 117 // invokeAndWait so that the work finishes before returning. 118 // if we call invokeLater() then demo/PlotFourierSeries.java 119 // has problems. 120 SwingUtilities.invokeAndWait(doActions); 121 } catch (Exception ex) { 122 System.err.println(ex.toString()); 123 ex.printStackTrace(); 124 } 125 126 // If the -test arg was set, then exit after 2 seconds. 127 if (_test) { 128 try { 129 Thread.sleep(2000); 130 } catch (InterruptedException e) { 131 } 132 133 StringUtilities.exit(0); 134 } 135 } 136 137 /////////////////////////////////////////////////////////////////// 138 //// protected methods //// 139 140 /** Display basic information about the application. 141 */ 142 @Override 143 protected void _about() { 144 JOptionPane.showMessageDialog(this, 145 "HistogramMLApplication class\n" + "By: Edward A. Lee " 146 + "and Christopher Hylands\n" + "Version " 147 + PlotBox.PTPLOT_RELEASE + ", Build: $Id$\n\n" 148 + "For more information, see\n" 149 + "http://ptolemy.eecs.berkeley.edu/java/ptplot\n\n" 150 + "Copyright (c) 1997-2014 " 151 + "The Regents of the University of California.", 152 "About Ptolemy Plot", JOptionPane.INFORMATION_MESSAGE); 153 } 154 155 /** Display more detailed information than given by _about(). 156 */ 157 @Override 158 protected void _help() { 159 JOptionPane.showMessageDialog(this, 160 "HistogramMLApplication is a standalone plot " 161 + " application.\n" 162 + " File formats understood: PlotML and Ptplot ASCII.\n" 163 + " Left mouse button: Zooming.\n" 164 + " Right mouse button: Editing data (use edit menu to select " 165 + "a dataset).\n\n" + _usage(), 166 "About Ptolemy Plot", JOptionPane.INFORMATION_MESSAGE); 167 } 168 169 /** Create a new parser object for the application. Derived classes can 170 * redefine this method to return a different type of parser. 171 * @return A new parser. 172 */ 173 @Override 174 protected PlotBoxMLParser _newParser() { 175 return new HistogramMLParser((Histogram) plot); 176 } 177}