src/macosx/classes/com/apple/eawt/Application.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.apple.eawt;
  27 
  28 import java.awt.*;
  29 import java.awt.peer.*;
  30 import java.beans.Beans;
  31 import java.security.PrivilegedAction;
  32 
  33 import javax.swing.JMenuBar;
  34 
  35 import sun.lwawt.*;
  36 import sun.lwawt.macosx.*;
  37 
  38 /**
  39  * The <code>Application</code> class allows you to integrate your Java application with the native Mac OS X environment.
  40  * You can provide your Mac OS X users a greatly enhanced experience by implementing a few basic handlers for standard system events.
  41  *
  42  * For example:
  43  * <ul>
  44  * <li>Open an about dialog when a user chooses About from the application menu.</li>
  45  * <li>Open a preferences window when the users chooses Preferences from the application menu.</li>
  46  * <li>Create a new document when the user clicks on your Dock icon, and no windows are open.</li>
  47  * <li>Open a document that the user double-clicked on in the Finder.</li>
  48  * <li>Open a custom URL scheme when a user clicks on link in a web browser.</li>
  49  * <li>Reconnect to network services after the system has awoke from sleep.</li>
  50  * <li>Cleanly shutdown your application when the user chooses Quit from the application menu, Dock icon, or types Command-Q.</li>
  51  * <li>Cancel shutdown/logout if the user has unsaved changes in your application.</li>
  52  * </ul>
  53  *
  54  * @since 1.4
  55  */
  56 public class Application {
  57     private static native void nativeInitializeApplicationDelegate();
  58 
  59     static Application sApplication = null;
  60 
  61     static {
  62         java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("awt"));






  63 
  64         checkSecurity();
  65         if (!Beans.isDesignTime()) {
  66             nativeInitializeApplicationDelegate();
  67         }
  68 
  69         sApplication = new Application();
  70     }
  71 
  72     private static void checkSecurity() {
  73         final SecurityManager security = System.getSecurityManager();
  74         if (security == null) return;
  75         security.checkPermission(new RuntimePermission("canProcessApplicationEvents"));
  76     }
  77 
  78     /**
  79      * @return the singleton representing this Mac OS X Application
  80      *
  81      * @since 1.4
  82      */




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.apple.eawt;
  27 
  28 import java.awt.*;
  29 import java.awt.peer.*;
  30 import java.beans.Beans;

  31 
  32 import javax.swing.JMenuBar;
  33 
  34 import sun.lwawt.*;
  35 import sun.lwawt.macosx.*;
  36 
  37 /**
  38  * The <code>Application</code> class allows you to integrate your Java application with the native Mac OS X environment.
  39  * You can provide your Mac OS X users a greatly enhanced experience by implementing a few basic handlers for standard system events.
  40  *
  41  * For example:
  42  * <ul>
  43  * <li>Open an about dialog when a user chooses About from the application menu.</li>
  44  * <li>Open a preferences window when the users chooses Preferences from the application menu.</li>
  45  * <li>Create a new document when the user clicks on your Dock icon, and no windows are open.</li>
  46  * <li>Open a document that the user double-clicked on in the Finder.</li>
  47  * <li>Open a custom URL scheme when a user clicks on link in a web browser.</li>
  48  * <li>Reconnect to network services after the system has awoke from sleep.</li>
  49  * <li>Cleanly shutdown your application when the user chooses Quit from the application menu, Dock icon, or types Command-Q.</li>
  50  * <li>Cancel shutdown/logout if the user has unsaved changes in your application.</li>
  51  * </ul>
  52  *
  53  * @since 1.4
  54  */
  55 public class Application {
  56     private static native void nativeInitializeApplicationDelegate();
  57 
  58     static Application sApplication = null;
  59 
  60     static {
  61         java.security.AccessController.doPrivileged(
  62             new java.security.PrivilegedAction<Void>() {
  63                 public Void run() {
  64                     System.loadLibrary("awt");
  65                     return null;
  66                 }
  67             });
  68 
  69         checkSecurity();
  70         if (!Beans.isDesignTime()) {
  71             nativeInitializeApplicationDelegate();
  72         }
  73 
  74         sApplication = new Application();
  75     }
  76 
  77     private static void checkSecurity() {
  78         final SecurityManager security = System.getSecurityManager();
  79         if (security == null) return;
  80         security.checkPermission(new RuntimePermission("canProcessApplicationEvents"));
  81     }
  82 
  83     /**
  84      * @return the singleton representing this Mac OS X Application
  85      *
  86      * @since 1.4
  87      */