Apple Java Extensions

com.apple.eawt
Class Application

java.lang.Object
  extended by com.apple.eawt.Application

public class Application
extends java.lang.Object

The Application class allows you to integrate your Java code with the native Mac OS X application environment. In conjunction with the ApplicationEvent and ApplicationHandler classes, you can simply wrap certain native application behaviors and functionality. As a JavaBeans implementation, it provides a mechanism to simply manipulate these features in modern integrated development environments. By implementing the features exposed in this class, and its associated classes, you can provide users with a greatly enhanced user experience on Mac OS X. For example, by implementing the event handlers exposed in this class you are also providing basic AppleScript compatibility that your Java application can be incorporated into Mac OS X workflow solutions that require interapplication communication.

Obtain a new Application object if you want to do any of the following tasks

This class permits your Java application to respond Mac OX X-specific Apple events. To use this class:
  1. Obtain an instance of Application.
  2. Instantiate one or more objects that implement the ApplicationListener interface. (A convenience class, com.apple.eawt.ApplicationAdaptor, is provided. Create an instance of it for default handling of the events in the ApplicationListener interface).
  3. Implement handlers for the appropriate events.
  4. Register the ApplicationAdaptor(s) with the Application object.


Constructor Summary
Application()
          Creates an Application.
 
Method Summary
 void addAboutMenuItem()
          Adds the About item to the application menu if the item is not already present.
 void addApplicationListener(ApplicationListener listener)
          Adds the specified ApplicationListener as a receiver of callbacks from this class.
 void addPreferencesMenuItem()
          Adds the Preferences item to the application menu if the item is not already present.
static Application getApplication()
           
 boolean getEnabledAboutMenu()
          Determines whether the About item of the application menu is enabled.
 boolean getEnabledPreferencesMenu()
          Determines whether the Preferences item of the application menu is enabled.
static java.awt.Point getMouseLocationOnScreen()
          Deprecated. replaced by java.awt.MouseInfo.getPointerInfo().getLocation().
 boolean isAboutMenuItemPresent()
          Determines whether the About item of the application menu is present.
 boolean isPreferencesMenuItemPresent()
          Determines whether the About Preferences of the application menu is present.
 void removeAboutMenuItem()
          Removes the About item from the application menu if the item is present.
 void removeApplicationListener(ApplicationListener listener)
          Removes the specified ApplicationListener from being a receiver of callbacks from this class.
 void removePreferencesMenuItem()
          Removes the Preferences item from the application menu if that item is present.
 void setEnabledAboutMenu(boolean enable)
          Enables the About item in the application menu.
 void setEnabledPreferencesMenu(boolean enable)
          Enables the Preferences item in the application menu.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Application

public Application()
Creates an Application. Useful for JavaBean environments.

Method Detail

getApplication

public static Application getApplication()
Returns:
a singleton Application. Useful for AWT runtime environments.

addApplicationListener

public void addApplicationListener(ApplicationListener listener)
Adds the specified ApplicationListener as a receiver of callbacks from this class.

Parameters:
listener - an implementation of ApplicationListener that handles ApplicationEvents generated by this class

removeApplicationListener

public void removeApplicationListener(ApplicationListener listener)
Removes the specified ApplicationListener from being a receiver of callbacks from this class.

Parameters:
listener - an implementation of ApplicationListener that had previously been registered to handle ApplicationEvents generated by this class

setEnabledPreferencesMenu

public void setEnabledPreferencesMenu(boolean enable)
Enables the Preferences item in the application menu. The ApplicationListener receives a callback for selection of the Preferences item in the application menu only if this is set to true. Because an application may not have a preferences window, by default this is set to false, meaning that the Preferences item in the application menu is grayed out and unselectable. If a Preferences item isn't present, this method adds and enables it.

Parameters:
enable - specifies whether the Preferences item in the application menu should be enabled (true) or not (false)

setEnabledAboutMenu

public void setEnabledAboutMenu(boolean enable)
Enables the About item in the application menu. The ApplicationListener receives a callback for selection of the About item in the application menu only if this is set to true. Because AWT supplies a standard About window when an application may not, by default this is set to true. If the About item isn't present, this method adds and enables it.

Parameters:
enable - specifies whether the About item in the application menu should be enabled (true) or not (false)

getEnabledPreferencesMenu

public boolean getEnabledPreferencesMenu()
Determines whether the Preferences item of the application menu is enabled.


getEnabledAboutMenu

public boolean getEnabledAboutMenu()
Determines whether the About item of the application menu is enabled.


isAboutMenuItemPresent

public boolean isAboutMenuItemPresent()
Determines whether the About item of the application menu is present.


addAboutMenuItem

public void addAboutMenuItem()
Adds the About item to the application menu if the item is not already present.


removeAboutMenuItem

public void removeAboutMenuItem()
Removes the About item from the application menu if the item is present.


isPreferencesMenuItemPresent

public boolean isPreferencesMenuItemPresent()
Determines whether the About Preferences of the application menu is present. By default there is no Preferences menu item.


addPreferencesMenuItem

public void addPreferencesMenuItem()
Adds the Preferences item to the application menu if the item is not already present.


removePreferencesMenuItem

public void removePreferencesMenuItem()
Removes the Preferences item from the application menu if that item is present.


getMouseLocationOnScreen

@Deprecated
public static java.awt.Point getMouseLocationOnScreen()
Deprecated. replaced by java.awt.MouseInfo.getPointerInfo().getLocation().


Apple Java Extensions

To file bugs or suggest feature enhancements for the Java implementation in Mac OS X, visit the Apple Developer Connection Bug Reporter website. File bugs under the Java (new bugs) component, version X.

Additional documentation for Java development on Mac OS X is available online at the Java Developer Documentation website.

© Apple Computer, Inc. March 2008