Back to index

wims  3.65+svn20090927
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
ptolemy.plot.PlotApplication Class Reference

PlotApplication is a versatile two-dimensional data plotter application. More...

Inheritance diagram for ptolemy.plot.PlotApplication:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.plot.PlotApplication:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PlotApplication () throws Exception
 Construct a plot with no command-line arguments.
 PlotApplication (String[] args) throws Exception
 Construct a plot with the specified command-line arguments.
 PlotApplication (PlotBox plot, String[] args) throws Exception
 Construct a plot with the specified command-line arguments and instance of plot.
 PlotApplication (PlotBox plot)
 Display the given plot.
void samplePlot ()
 Create a sample plot.
void setVisible (boolean visible)
 Set the visibility.

Static Public Member Functions

static void main (final String[] args)
 Create a new plot window and map it to the screen.

Public Attributes

PlotBox plot
 The plot object held by this frame.

Protected Member Functions

void _about ()
void _close ()
 Exit the application.
void _help ()
 Display more detailed information than given by _about().
int _parseArgs (String[] args) throws CmdLineArgException, FileNotFoundException, IOException
 Parse the command-line arguments and make calls to the Plot class accordingly.
String _usage ()
 Return a string summarizing the command-line arguments.
void _editFormat ()
 Interactively edit the file format in a modal dialog.
void _export ()
 Query the user for a filename and export the plot to that file.
void _open ()
 Open a new file and plot its data.
void _print ()
 Print the plot.
void _printCrossPlatform ()
 Print using the cross platform dialog.
void _printNative ()
 Print using the native dialog.
void _read (URL base, InputStream in) throws IOException
 Read the specified stream.
void _save ()
 Save the plot to the current file, determined by the and _file protected variable.
void _saveAs ()
 Query the user for a filename and save the plot to that file.

Protected Attributes

JMenuBar _menubar = new JMenuBar()
 Menubar for this frame.
JMenu _editMenu = new JMenu("Edit")
 Edit menu for this frame.
JMenu _fileMenu = new JMenu("File")
 File menu for this frame.
JMenu _specialMenu = new JMenu("Special")
 Special menu for this frame.
File _directory = null
 Directory that contains the input file.
File _file = null
 The input file.

Static Protected Attributes

static boolean _test = false
 If true, then auto exit after a few seconds.

Detailed Description

PlotApplication is a versatile two-dimensional data plotter application.

It can read files compatible with the Ptolemy plot file format (currently only ASCII). For a description of the file format, see the Plot and PlotBox classes. Command-line options include:

-help
Print the usage, including all command-line options that exist for backward compatibility and then exit. The help menu choice will display the same information.
-test
Display the plot, then exit after 2 seconds.
-version
Print the program version and then exit. While ptplot is running, the version menu choice will display the same information.
-
Read the plot data from standard in.

For compatibility with historical applications, this application has a limited ability to read pxgraph files. The command line arguments must be used, and the options that are understood are exactly those of the pxgraph application, plus some more to allow for cross-platform reading. It is not possible to read pxgraph files using the "Open" menu command (because of the cross-platform problems). The additional command-line arguments are:

-bigendian
Data files are in big-endian, or network binary format. If you are on a little-endian machine, such as a machine with an Intel x86 chip, and you would like to read a binary format file created on a big-endian machine, such as a Sun SPARC, use the -bigendian flag.
-littleendian
Data files are in little-endian, or x86 binary format. If you are on a big-endian machine, such as a Sun Sparc, and you would like to read a binary format file created on a little-endian machine, such as Intel x86 machine, then use the -littleendian flag.

To compile and run this application, do the following:

 javac -classpath ../.. PlotApplication.java
 java -classpath ../.. ptolemy.plot.PlotApplication
 

This assumes a particular directory structure. If this is not what you have, then alter the above accordingly.

See also:
Plot
PlotBox
Author:
Christopher Brooks and Edward A. Lee
Version:
Id:
PlotApplication.java,v 1.69.4.1 2008/04/04 20:01:01 cxh Exp
Since:
Ptolemy II 0.2 .ProposedRating Yellow (cxh) .AcceptedRating Yellow (cxh)

Definition at line 112 of file PlotApplication.java.


Constructor & Destructor Documentation

ptolemy.plot.PlotApplication.PlotApplication ( ) throws Exception [inline]

Construct a plot with no command-line arguments.

It initially displays a sample plot.

Exceptions:
ExceptionNot thrown in this base class.

Definition at line 117 of file PlotApplication.java.

                                              {
        this(new String[0]);
    }

Here is the caller graph for this function:

ptolemy.plot.PlotApplication.PlotApplication ( String[]  args) throws Exception [inline]

Construct a plot with the specified command-line arguments.

Parameters:
argsThe command-line arguments.
Exceptions:
ExceptionIf command line arguments have problems.

Definition at line 125 of file PlotApplication.java.

                                                           {
        this(new Plot(), args);
    }
ptolemy.plot.PlotApplication.PlotApplication ( PlotBox  plot,
String[]  args 
) throws Exception [inline]

Construct a plot with the specified command-line arguments and instance of plot.

If there are no command-line arguments, then display a sample plot.

Parameters:
plotThe instance of Plot to use.
argsThe command-line arguments.
Exceptions:
ExceptionIf command line arguments have problems.

Definition at line 136 of file PlotApplication.java.

                                                                         {
        // invoke the base class constructor and pass in the argument a Plot
        // object. This makes sure that the plot field is an instance of
        // Plot class.
        super("PlotApplication", plot);

        // Handle window closing by exiting the application.
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // Strangely, calling _close() here sends javac into
                // an infinite loop (in jdk 1.1.4).
                //              _close();
                System.exit(0);
            }
        });

        _parseArgs(args);

        if ((args == null) || (args.length == 0)) {
            samplePlot();
        }

        setVisible(true);
    }

Here is the call graph for this function:

Display the given plot.

Unlike the two argument constructor, this does not take command-line arguments, and does not fill the plot with a sample plot.

Parameters:
plotThe instance of Plot to display.

Definition at line 166 of file PlotApplication.java.

                                         {
        // Invoke the base class constructor and pass in the argument a Plot
        // object. This makes sure that the plot field is an instance of
        // Plot class.
        super("PlotApplication", plot);

        // Handle window closing by exiting the application.
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                // Strangely, calling _close() here sends javac into
                // an infinite loop (in jdk 1.1.4).
                //              _close();
                System.exit(0);
            }
        });

        setVisible(true);
    }

Here is the call graph for this function:


Member Function Documentation

void ptolemy.plot.PlotApplication._about ( ) [inline, protected]

Reimplemented from ptolemy.plot.PlotFrame.

Definition at line 223 of file PlotApplication.java.

                            {
        JOptionPane
                .showMessageDialog(
                        this,
                        "PlotApplication class\n"
                                + "By: Edward A. Lee "
                                + "and Christopher Brooks\n"
                                + "Version "
                                + PlotBox.PTPLOT_RELEASE
                                + ", Build: $Id: PlotApplication.java,v 1.69.4.1 2008/04/04 20:01:01 cxh Exp $\n\n"
                                + "For more information, see\n"
                                + "http://ptolemy.eecs.berkeley.edu/java/ptplot\n\n"
                                + "Copyright (c) 1997-2008, "
                                + "The Regents of the University of California.",
                        "About Ptolemy Plot", JOptionPane.INFORMATION_MESSAGE);
    }
void ptolemy.plot.PlotApplication._close ( ) [inline, protected]

Exit the application.

Reimplemented from ptolemy.plot.PlotFrame.

Definition at line 242 of file PlotApplication.java.

                            {
        StringUtilities.exit(0);
    }

Here is the call graph for this function:

void ptolemy.plot.PlotFrame._editFormat ( ) [inline, protected, inherited]

Interactively edit the file format in a modal dialog.

Definition at line 301 of file PlotFrame.java.

                                 {
        PlotFormatter fmt = new PlotFormatter(plot);
        fmt.openModal();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._export ( ) [inline, protected, inherited]

Query the user for a filename and export the plot to that file.

Currently, the only supported format is EPS.

Definition at line 309 of file PlotFrame.java.

                             {
        JFileChooser fileDialog = new JFileChooser();
        fileDialog.addChoosableFileFilter(new EPSFileFilter());
        fileDialog.setDialogTitle("Export EPS to...");

        if (_directory != null) {
            fileDialog.setCurrentDirectory(_directory);
        } else {
            // The default on Windows is to open at user.home, which is
            // typically an absurd directory inside the O/S installation.
            // So we use the current directory instead.
            String cwd = StringUtilities.getProperty("user.dir");

            if (cwd != null) {
                fileDialog.setCurrentDirectory(new File(cwd));
            }
        }

        fileDialog.setSelectedFile(new File(fileDialog.getCurrentDirectory(),
                "plot.eps"));

        int returnVal = fileDialog.showDialog(this, "Export");

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fileDialog.getSelectedFile();

            try {
                FileOutputStream fout = null;

                try {
                    fout = new FileOutputStream(file);
                    plot.export(fout);
                } finally {
                    try {
                        fout.close();
                    } catch (Throwable throwable) {
                        System.out.println("Ignoring failure to close stream "
                                + "on " + file);
                        throwable.printStackTrace();
                    }
                }
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Error exporting plot: "
                        + ex, "Ptolemy II Error", JOptionPane.WARNING_MESSAGE);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotApplication._help ( ) [inline, protected]

Display more detailed information than given by _about().

Reimplemented from ptolemy.plot.PlotFrame.

Definition at line 248 of file PlotApplication.java.

                           {
        JOptionPane.showMessageDialog(this,
                "PlotApplication is a standalone plot " + " application.\n"
                        + "  File formats understood: Ptplot ASCII.\n"
                        + "  Left mouse button: Zooming.\n\n" + _usage(),
                "About Ptolemy Plot", JOptionPane.INFORMATION_MESSAGE);
    }

Here is the call graph for this function:

void ptolemy.plot.PlotFrame._open ( ) [inline, protected, inherited]

Open a new file and plot its data.

Definition at line 369 of file PlotFrame.java.

                           {
        JFileChooser fileDialog = new JFileChooser();
        fileDialog.setDialogTitle("Select a plot file");

        // Filter file names.
        fileDialog.addChoosableFileFilter(new PLTOrXMLFileFilter());

        if (_directory != null) {
            fileDialog.setCurrentDirectory(_directory);
        } else {
            // The default on Windows is to open at user.home, which is
            // typically an absurd directory inside the O/S installation.
            // So we use the current directory instead.
            String cwd = StringUtilities.getProperty("user.dir");

            if (cwd != null) {
                fileDialog.setCurrentDirectory(new File(cwd));
            }
        }

        int returnVal = fileDialog.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            _file = fileDialog.getSelectedFile();
            setTitle(_file.getName());
            _directory = fileDialog.getCurrentDirectory();

            try {
                plot.clear(true);
                _read(new URL("file", null, _directory.getAbsolutePath()),
                        new FileInputStream(_file));
                plot.repaint();
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(this, "File not found:\n"
                        + ex.toString(), "Ptolemy Plot Error",
                        JOptionPane.WARNING_MESSAGE);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Error reading input:\n"
                        + ex.toString(), "Ptolemy Plot Error",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

int ptolemy.plot.PlotApplication._parseArgs ( String[]  args) throws CmdLineArgException, FileNotFoundException, IOException [inline, protected]

Parse the command-line arguments and make calls to the Plot class accordingly.

Returns:
The number of arguments read.
Exceptions:
CmdLineArgExceptionIf a command line argument cannot be parsed.
FileNotFoundExceptionIf an input file cannot be found.
IOExceptionIf there is a problem reading an input.

Definition at line 264 of file PlotApplication.java.

                                               {
        int i = 0;
        int argumentsRead;
        String arg;
        String title = "Ptolemy plot";

        int width = 500; // Default width of the graph
        int height = 300; // Default height of the graph

        while ((args != null) && (i < args.length)) {
            arg = args[i++];

            if (arg.equals("-height")) {
                if (i > (args.length - 1)) {
                    throw new CmdLineArgException(_usage());
                }

                height = Integer.valueOf(args[i++]).intValue();
                continue;
            } else if (arg.equals("-help")) {
                System.out.println(_usage());
                StringUtilities.exit(0);
                continue;
            } else if (arg.equals("-test")) {
                _test = true;
                continue;
            } else if (arg.equals("-version")) {
                System.out
                        .println("Version "
                                + PlotBox.PTPLOT_RELEASE
                                + ", Build $Id: PlotApplication.java,v 1.69.4.1 2008/04/04 20:01:01 cxh Exp $");
                StringUtilities.exit(0);
                continue;
            } else if (arg.equals("-width")) {
                if (i > (args.length - 1)) {
                    throw new CmdLineArgException(
                            "-width requires an integer argument");
                }

                width = Integer.valueOf(args[i++]).intValue();
                continue;
            } else if (arg.equals("")) {
                // Ignore blank argument.
            } else if (arg.equals("-")) {
                // read from standard input
                URL base = new URL("file", null, "standard input");
                _read(base, System.in);
            } else if (!arg.startsWith("-")) {
                // Have a filename.  First attempt to open it as a URL.
                InputStream instream;
                URL base;

                try {
                    // First argument is null because we are only
                    // processing absolute URLs this way.  Relative
                    // URLs are opened as ordinary files.
                    URL inurl = new URL(null, arg);
                    base = inurl;
                    instream = inurl.openStream();
                } catch (MalformedURLException ex) {
                    File file = new File(arg);
                    instream = new FileInputStream(file);
                    _file = new File(file.getAbsolutePath());
                    title = _file.getName();
                    _directory = _file.getParentFile();
                    base = new URL("file", null, _directory.getAbsolutePath());
                }

                _read(base, instream);
            } else {
                // Unrecognized option.
                throw new CmdLineArgException("Unrecognized option: " + arg);
            }
        }

        setSize(width, height);
        setTitle(title);

        argumentsRead = i;

        return argumentsRead;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._print ( ) [inline, protected, inherited]

Print the plot.

Definition at line 415 of file PlotFrame.java.

                            {
        _printCrossPlatform();

        //_printNative();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._printCrossPlatform ( ) [inline, protected, inherited]

Print using the cross platform dialog.

FIXME: this dialog is slow and is often hidden behind other windows. However, it does honor the user's choice of portrait vs. landscape

Definition at line 426 of file PlotFrame.java.

                                         {
        // Build a set of attributes
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(plot);

        if (job.printDialog(aset)) {
            try {
                job.print(aset);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Printing failed:\n"
                        + ex.toString(), "Print Error",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    }

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._printNative ( ) [inline, protected, inherited]

Print using the native dialog.

FIXME: This method does not seem to honor the user's choice of portrait vs. landscape.

Definition at line 447 of file PlotFrame.java.

                                  {
        PrinterJob job = PrinterJob.getPrinterJob();

        //PageFormat pageFormat = job.defaultPage();
        //job.setPrintable(plot, pageFormat);
        job.setPrintable(plot);

        if (job.printDialog()) {
            try {
                // job.print() eventually
                // calls PlotBox.print(Graphics, PageFormat)
                job.print();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Printing failed:\n"
                        + ex.toString(), "Print Error",
                        JOptionPane.WARNING_MESSAGE);
            }
        }
    }
void ptolemy.plot.PlotFrame._read ( URL  base,
InputStream  in 
) throws IOException [inline, protected, inherited]

Read the specified stream.

Derived classes may override this to support other file formats.

Parameters:
baseThe base for relative file references, or null if there are not relative file references.
inThe input stream.
Exceptions:
IOExceptionIf the stream cannot be read.

Definition at line 474 of file PlotFrame.java.

                                                                      {
        plot.read(in);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._save ( ) [inline, protected, inherited]

Save the plot to the current file, determined by the and _file protected variable.

Definition at line 481 of file PlotFrame.java.

                           {
        if (_file != null) {
            try {
                FileOutputStream fout = new FileOutputStream(_file);
                plot.write(fout);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Error writing file:\n"
                        + ex.toString(), "Ptolemy Plot Error",
                        JOptionPane.WARNING_MESSAGE);
            }
        } else {
            _saveAs();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame._saveAs ( ) [inline, protected, inherited]

Query the user for a filename and save the plot to that file.

Definition at line 498 of file PlotFrame.java.

                             {
        JFileChooser fileDialog = new JFileChooser();
        fileDialog.addChoosableFileFilter(new PLTOrXMLFileFilter());
        fileDialog.setDialogTitle("Save plot as...");

        if (_directory != null) {
            fileDialog.setCurrentDirectory(_directory);
        } else {
            // The default on Windows is to open at user.home, which is
            // typically an absurd directory inside the O/S installation.
            // So we use the current directory instead.
            String cwd = StringUtilities.getProperty("user.dir");

            if (cwd != null) {
                fileDialog.setCurrentDirectory(new File(cwd));
            }
        }

        fileDialog.setSelectedFile(new File(fileDialog.getCurrentDirectory(),
                "plot.xml"));

        int returnVal = fileDialog.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            _file = fileDialog.getSelectedFile();
            setTitle(_file.getName());
            _directory = fileDialog.getCurrentDirectory();
            _save();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

String ptolemy.plot.PlotApplication._usage ( ) [inline, protected]

Return a string summarizing the command-line arguments.

Returns:
A usage string.

Definition at line 351 of file PlotApplication.java.

                              {
        // We use a table here to keep things neat.
        // If we have:
        //  {"-bd",  "<color>", "Border",  "White", "(Unsupported)"},
        // -bd       - The argument
        // <color>   - The description of the value of the argument
        // Border    - The Xgraph file directive (not supported at this time).
        // White     - The default (not supported at this time)
        // "(Unsupported)" - The string that is printed to indicate if
        //                   a option is unsupported.
        String[][] commandOptions = { { "-height", "<pixels>" },
                { "-width", "<pixels>" }, };

        String[] commandFlags = { "-help", "-test", "-version", "-", };
        StringBuffer result = new StringBuffer(
                "Usage: ptplot [ options ] [file ...]\n\n"
                        + "Options that take values:\n");

        int i;

        for (i = 0; i < commandOptions.length; i++) {
            result.append(" " + commandOptions[i][0] + " "
                    + commandOptions[i][1] + "\n");
        }

        result.append("\nBoolean flags:\n");

        for (i = 0; i < commandFlags.length; i++) {
            result.append(" " + commandFlags[i]);
        }

        return result.toString();
    }

Here is the caller graph for this function:

static void ptolemy.plot.PlotApplication.main ( final String[]  args) [inline, static]

Create a new plot window and map it to the screen.

Definition at line 190 of file PlotApplication.java.

                                                 {
        try {
            // Run this in the Swing Event Thread.
            Runnable doActions = new Runnable() {
                public void run() {
                    try {
                        new PlotApplication(new Plot(), args);
                    } catch (Exception ex) {
                        System.err.println(ex.toString());
                        ex.printStackTrace();
                    }
                }
            };

            SwingUtilities.invokeAndWait(doActions);
        } catch (Exception ex) {
            System.err.println(ex.toString());
            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);
        }
    }

Here is the call graph for this function:

void ptolemy.plot.PlotFrame.samplePlot ( ) [inline, inherited]

Create a sample plot.

Definition at line 227 of file PlotFrame.java.

                             {
        _file = null;
        _directory = null;
        plot.samplePlot();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.plot.PlotFrame.setVisible ( boolean  visible) [inline, inherited]

Set the visibility.

As a side effect, this method sets the background of the menus.

Parameters:
visibleTrue if the Frame is to be visible, false if it is not visible.

Definition at line 238 of file PlotFrame.java.

                                            {
        super.setVisible(visible);
        _editMenu.setBackground(_menubar.getBackground());
        _fileMenu.setBackground(_menubar.getBackground());
        _specialMenu.setBackground(_menubar.getBackground());
    }

Here is the caller graph for this function:


Member Data Documentation

File ptolemy.plot.PlotFrame._directory = null [protected, inherited]

Directory that contains the input file.

Definition at line 269 of file PlotFrame.java.

JMenu ptolemy.plot.PlotFrame._editMenu = new JMenu("Edit") [protected, inherited]

Edit menu for this frame.

Definition at line 260 of file PlotFrame.java.

File ptolemy.plot.PlotFrame._file = null [protected, inherited]

The input file.

Definition at line 272 of file PlotFrame.java.

JMenu ptolemy.plot.PlotFrame._fileMenu = new JMenu("File") [protected, inherited]

File menu for this frame.

Definition at line 263 of file PlotFrame.java.

JMenuBar ptolemy.plot.PlotFrame._menubar = new JMenuBar() [protected, inherited]

Menubar for this frame.

Definition at line 257 of file PlotFrame.java.

JMenu ptolemy.plot.PlotFrame._specialMenu = new JMenu("Special") [protected, inherited]

Special menu for this frame.

Definition at line 266 of file PlotFrame.java.

If true, then auto exit after a few seconds.

Definition at line 389 of file PlotApplication.java.

The plot object held by this frame.

Definition at line 251 of file PlotFrame.java.


The documentation for this class was generated from the following file: