001/* An application that shows the elements of a Ptolemy II model in a JTree.
002
003 Copyright (c) 1998-2014 The Regents of the University of California.
004 All rights reserved.
005
006 Permission is hereby granted, without written agreement and without
007 license or royalty fees, to use, copy, modify, and distribute this
008 software and its documentation for any purpose, provided that the above
009 copyright notice and the following two paragraphs appear in all copies
010 of this software.
011
012 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
013 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
014 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
015 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
016 SUCH DAMAGE.
017
018 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
019 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
021 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
022 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
023 ENHANCEMENTS, OR MODIFICATIONS.
024
025 PT_COPYRIGHT_VERSION_2
026 COPYRIGHTENDKEY
027
028
029 */
030package ptolemy.vergil.tree;
031
032import java.awt.event.WindowAdapter;
033import java.awt.event.WindowEvent;
034
035import javax.swing.JFrame;
036
037import ptolemy.util.StringUtilities;
038
039///////////////////////////////////////////////////////////////////
040//// TreeEditor
041
042/**
043 An application that shows the elements of a Ptolemy II model in a JTree.
044
045 @author Edward Lee
046 @version $Id$
047 @since Ptolemy II 1.0
048 @Pt.ProposedRating Red (ctsay)
049 @Pt.AcceptedRating Red (ctsay)
050 */
051@SuppressWarnings("serial")
052public class TreeEditor extends JFrame {
053    /** Construct a display of the Ptolemy II model given by the
054     *  specified MoML file.
055     *  @param filename The name of a MoML file.
056     *  @exception Exception If the parser cannot parse the file.
057     */
058    public TreeEditor(String filename) throws Exception {
059        super();
060
061        // Handle window closing by exiting the application.
062        addWindowListener(new WindowAdapter() {
063            @Override
064            public void windowClosing(WindowEvent e) {
065                StringUtilities.exit(0);
066            }
067        });
068
069        getContentPane().add(new TreeEditorPanel(filename));
070        pack();
071        setVisible(true);
072    }
073
074    ///////////////////////////////////////////////////////////////////
075    ////                         public methods                    ////
076
077    /** Create an instance of this class to display the abstract syntax
078     *  tree for the specified file.
079     *  @param args An array of size one where the first element contains
080     *  the name of a MoML file.
081     */
082    public static void main(String[] args) {
083        if (args.length != 1) {
084            System.out.println(
085                    "usage : ptolemy.vergil.tree.TreeEditor file.java");
086            return;
087        }
088
089        try {
090            new TreeEditor(args[0]);
091        } catch (Exception ex) {
092            System.err.println(ex.toString());
093        }
094    }
095}