001/* A Graphical Message Handler Applet
002
003 Copyright (c) 2009-2014 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028
029package ptolemy.gui.test;
030
031import javax.swing.UIManager;
032
033import ptolemy.gui.BasicJApplet;
034import ptolemy.gui.GraphicalMessageHandler;
035import ptolemy.kernel.attributes.VersionAttribute;
036import ptolemy.util.MessageHandler;
037import ptolemy.vergil.VergilApplication;
038
039///////////////////////////////////////////////////////////////////
040//// GraphicalMessageHandlerApplet
041/** An applet that bring up a toplevel, standalone Vergil frame.
042
043 @author Christopher Brooks.
044 @version $Id$
045 @since Ptolemy II 8.0
046 @Pt.ProposedRating Red (cxh)
047 @Pt.AcceptedRating Red (cxh)
048 */
049@SuppressWarnings("serial")
050public class GraphicalMessageHandlerApplet extends BasicJApplet {
051    ///////////////////////////////////////////////////////////////////
052    ////                         public methods                    ////
053
054    /** Cleanup after execution of the model.  This method is called
055     *  by the browser or appletviewer to inform this applet that
056     *  it should clean up.
057     */
058    @Override
059    public void destroy() {
060        super.destroy();
061        // Note: we used to call manager.terminate() here to get rid
062        // of a lingering browser problem
063        System.out.println(
064                "FIXME: Need to destroy GraphicalMessageHandlerApplet");
065        stop();
066    }
067
068    /** Return a string describing this applet.
069     *  @return A string describing the applet.
070     */
071    @Override
072    public String getAppletInfo() {
073        return "Ptolemy applet that brings up an error message "
074                + VersionAttribute.CURRENT_VERSION
075                + "\nPtolemy II comes from UC Berkeley, Department of EECS.\n"
076                + "See http://ptolemy.eecs.berkeley.edu/ptolemyII"
077                + "\n(Build: $Id$)";
078    }
079
080    /** Initialize the applet. This method is called by the browser
081     *  or applet viewer to inform this applet that it has been
082     *  loaded into the system. It is always called before
083     *  the first time that the start() method is called.
084     *  In this class, this invokes {@link VergilApplication#main(String[])}
085     */
086    @Override
087    public void init() {
088        super.init();
089        try {
090            // Setting the look and feel causes problems with applets
091            // under JDK1.6.0_02 -> JDK1.6.0_13.
092            // The exception is: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission C:\WINDOWS\Fonts\TAHOMA.TTF read)
093            // Unfortunately, it occurs well *after* the call below.
094            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
095        } catch (Throwable throwable) {
096            throw new RuntimeException("Failed to set look and feel.",
097                    throwable);
098        }
099        try {
100            java.util.Locale.setDefault(java.util.Locale.US);
101        } catch (java.security.AccessControlException accessControl) {
102            System.err.println("Warning, failed to set locale");
103            accessControl.printStackTrace();
104            // FIXME: If the application is run under Web Start, then this
105            // exception will be thrown.
106        }
107        GraphicalMessageHandler handler = new GraphicalMessageHandler();
108        MessageHandler.setMessageHandler(handler);
109        Exception exception = new Exception("My Test Exception");
110        MessageHandler.error("My Error Message.", exception);
111    }
112
113    /** Stop execution of the model. This method is called by the
114     *  browser or applet viewer to inform this applet that it should
115     *  stop its execution. It is called when the Web page
116     *  that contains this applet has been replaced by another page,
117     *  and also just before the applet is to be destroyed.
118     *  In this base class, this method calls the stop() method
119     *  of the manager. If there is no manager, do nothing.
120     */
121    @Override
122    public void stop() {
123        super.stop();
124        System.out.println("FIXME: Need to stop GraphicalMessageHandlerApplet");
125    }
126}