001/* An application that reads one or more files specified on the command line. 002 003 Copyright (c) 1999-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 */ 028package ptolemy.actor.gui; 029 030import javax.swing.UIManager; 031 032import ptolemy.moml.ErrorHandler; 033import ptolemy.moml.SimpleErrorHandler; 034import ptolemy.util.MessageHandler; 035import ptolemy.util.StringUtilities; 036 037////////////////////////////////////////////////////////////////////////// 038//// MoMLApplication 039 040/** 041 An application that sets the look and feel to the native look 042 and feel and then reads one or more 043 files specified on the command line, or instantiates one or 044 more Java classes specified by the -class option. 045 046 <p>This class sets the look and feel of the user interface (UI) to 047 the native look and feel. Thus, this class invokes Java's user 048 interface code which means that this class should be run in an 049 environment that has a display. To run in a environment 050 that has no display, see the {@link ptolemy.actor.gui.ConfigurationApplication} 051 parent class. 052 053 <p>For complete usage, see the {@link ptolemy.actor.gui.ConfigurationApplication} 054 parent class. 055 056 @author Edward A. Lee and Steve Neuendorffer, Contributor: Christopher Hylands 057 @version $Id$ 058 @since Ptolemy II 0.4 059 @Pt.ProposedRating Yellow (eal) 060 @Pt.AcceptedRating Red (eal) 061 @see Configuration 062 */ 063public class MoMLApplication extends ConfigurationApplication { 064 /** Parse the specified command-line arguments, instantiating classes 065 * and reading files that are specified. 066 * @param args The command-line arguments. 067 * @exception Exception If command line arguments have problems. 068 */ 069 public MoMLApplication(String[] args) throws Exception { 070 this("ptolemy/configs", args); 071 MessageHandler.setMessageHandler(new ActorGraphicalMessageHandler()); 072 } 073 074 /** Parse the specified command-line arguments, instantiating classes 075 * and reading files that are specified. 076 * @param basePath The basePath to look for configurations 077 * in, usually "ptolemy/configs", but other tools might 078 * have other configurations in other directories 079 * @param args The command-line arguments. 080 * @exception Exception If command line arguments have problems. 081 */ 082 public MoMLApplication(String basePath, String[] args) throws Exception { 083 this(basePath, args, new ActorGraphicalMessageHandler(), 084 new SimpleErrorHandler()); 085 } 086 087 /** Parse the specified command-line arguments, instantiating classes 088 * and reading files that are specified. 089 * @param basePath The basePath to look for configurations 090 * in, usually "ptolemy/configs", but other tools might 091 * have other configurations in other directories 092 * @param args The command-line arguments. 093 * @param messageHandler The message handler. 094 * @param errorHandler The MoML error handler. 095 * @exception Exception If command line arguments have problems. 096 */ 097 public MoMLApplication(String basePath, String[] args, 098 MessageHandler messageHandler, ErrorHandler errorHandler) 099 throws Exception { 100 super(basePath, args, messageHandler, errorHandler); 101 } 102 103 /** Set the look and feel to the native look and feel. 104 * This method is called by early in the constructor, 105 * so the object may not be completely constructed, so 106 * derived classes should not access fields from a 107 * parent class. 108 */ 109 @Override 110 protected void _initializeApplication() { 111 // The Java look & feel is pretty lame, so we use the native 112 // look and feel of the platform we are running on. 113 // NOTE: This creates the only dependence on Swing in this 114 // class. Should this be left to derived classes? 115 try { 116 // Setting the look and feel causes problems with applets 117 // under JDK1.6.0_02 -> JDK1.6.0_13. 118 // The exception is: Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: access denied (java.io.FilePermission C:\WINDOWS\Fonts\TAHOMA.TTF read) 119 // Unfortunately, it occurs well *after* the l&f is set. 120 String javaVersion = StringUtilities.getProperty("java.version"); 121 if (javaVersion.compareTo("1.6.0") > 0 122 && javaVersion.compareTo("1.6.0_14") < 0 123 && StringUtilities.inApplet()) { 124 System.out.println("Warning: skipping setting the look and " 125 + "feel in Java version " + javaVersion 126 + " because it causes problems under applets under " 127 + "Java 1.6.0_02 through 1.6.0_13."); 128 } else { 129 UIManager.setLookAndFeel( 130 UIManager.getSystemLookAndFeelClassName()); 131 } 132 } catch (Throwable throwable) { 133 // Ignore exceptions, which only result in the wrong look and feel. 134 } 135 } 136}