Apple Java Extensions

com.apple.eawt
Class ApplicationAdapter

java.lang.Object
  extended by com.apple.eawt.ApplicationAdapter
All Implemented Interfaces:
ApplicationListener, java.util.EventListener

public class ApplicationAdapter
extends java.lang.Object
implements ApplicationListener

An abstract adapter class for receiving ApplicationEvents. The methods in this class are empty. This class exists as a convenience for creating listener objects.

ApplicationEvents allow Java applications to handle basic Mac OS X Apple events.

Extend this class to create an ApplicationEvent listener and override the methods for the events of interest. For example:

...
public class QuitAdapter extends ApplicationAdapter {
   public void handleQuit(ApplicationEvent e) {
      //Check to see if user has unsaved changes, if not set e.setHandled(true)
      //If user has unsaved changes set e.setHandled(false) and move into code
      //that handles saving files.
   }
}
...


Constructor Summary
ApplicationAdapter()
           
 
Method Summary
 void handleAbout(ApplicationEvent event)
          Called when the user selects the About item in the application menu.
 void handleOpenApplication(ApplicationEvent event)
          Called when the application receives an Open Application event from the Finder or another application.
 void handleOpenFile(ApplicationEvent event)
          Called when the application receives an Open Document event from the Finder or another application.
 void handlePreferences(ApplicationEvent event)
          Called when the Preference item in the application menu is selected.
 void handlePrintFile(ApplicationEvent event)
          Called when the application is sent a request to print a particular file or files.
 void handleQuit(ApplicationEvent event)
          Called when the application is sent the Quit event.
 void handleReOpenApplication(ApplicationEvent event)
          Called when the application receives a Reopen Application event from the Finder or another application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApplicationAdapter

public ApplicationAdapter()
Method Detail

handleAbout

public void handleAbout(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the user selects the About item in the application menu. If event is not handled, by setting isHandled(true), a default About window consisting of the application's name and icon is displayed. To display a custom About window, designate the event as being handled and display the appropriate About window.

Specified by:
handleAbout in interface ApplicationListener
Parameters:
event - an ApplicationEvent initiated by the user choosing About in the application menu

handleOpenApplication

public void handleOpenApplication(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the application receives an Open Application event from the Finder or another application. Usually this will come from the Finder when a user double-clicks your application icon. If there is any special code that you want to run when you user launches your application from the Finder or by sending an Open Application event from another application, include that code as part of this handler. The Open Application event is sent after AWT has been loaded.

Specified by:
handleOpenApplication in interface ApplicationListener
Parameters:
event - the Open Application event

handleOpenFile

public void handleOpenFile(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the application receives an Open Document event from the Finder or another application. This event is generated when a user double-clicks a document in the Finder. If the document is registered as belonging to your application, this event is sent to your application. Documents are bound to a particular application based primarily on their suffix. In the Finder, a user selects a document and then from the File Menu chooses Get Info. The Info window allows users to bind a document to a particular application. These events are sent only if the bound application has file types listed in the Info.plist entries Document Types or CFBundleDocumentTypes. The ApplicationEvent sent to this handler holds a reference to the file being opened.

Specified by:
handleOpenFile in interface ApplicationListener
Parameters:
event - an Open Document event with reference to the file to be opened

handlePreferences

public void handlePreferences(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the Preference item in the application menu is selected. Native Mac OS X applications make their Preferences window available through the application menu. Java applications are automatically given an application menu in Mac OS X. By default, the Preferences item is disabled in that menu. If you are deploying an application on Mac OS X, you should enable the preferences item with setEnabledPreferencesMenu(true) in the Application object and then display your Preferences window in this handler.

Specified by:
handlePreferences in interface ApplicationListener
Parameters:
event - triggered when the user selects Preferences from the application menu

handlePrintFile

public void handlePrintFile(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the application is sent a request to print a particular file or files. You can allow other applications to print files with your application by implementing this handler. If another application sends a Print Event along with the name of a file that your application knows how to process, you can use this handler to determine what to do with that request. You might open your entire application, or just invoke your printing classes. These events are sent only if the bound application has file types listed in the Info.plist entries Document Types or CFBundleDocumentTypes. The ApplicationEvent sent to this handler holds a reference to the file being opened.

Specified by:
handlePrintFile in interface ApplicationListener
Parameters:
event - a Print Document event with a reference to the file(s) to be printed

handleQuit

public void handleQuit(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the application is sent the Quit event. This event is generated when the user selects Quit from the application menu, when the user types Command-Q, or when the user control clicks on your application icon in the Dock and chooses Quit. You can either accept or reject the request to quit. You might want to reject the request to quit if the user has unsaved work. Reject the request, move into your code to save changes, then quit your application. To accept the request to quit, and terminate the application, set isHandled(true) for the event. To reject the quit, set isHandled(false).

Specified by:
handleQuit in interface ApplicationListener
Parameters:
event - a Quit Application event

handleReOpenApplication

public void handleReOpenApplication(ApplicationEvent event)
Description copied from interface: ApplicationListener
Called when the application receives a Reopen Application event from the Finder or another application. Usually this will come when a user clicks on your application icon in the Dock. If there is any special code that needs to run when your user clicks on your application icon in the Dock or when a Reopen Application event is sent from another application, include that code as part of this handler.

Specified by:
handleReOpenApplication in interface ApplicationListener
Parameters:
event - the Reopen Application event

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