JHotDraw 7.5.1

org.jhotdraw.app.osx
Class OSXAdapter

java.lang.Object
  extended by org.jhotdraw.app.osx.OSXAdapter
All Implemented Interfaces:
java.lang.reflect.InvocationHandler

public class OSXAdapter
extends java.lang.Object
implements java.lang.reflect.InvocationHandler

OSXAdapter uses a Proxy object to dynamically implement the com.apple.eawt.ApplicationListener interface and register it with the com.apple.eawt.Application object. This allows the complete project to be both built and run on any platform without any stubs or placeholders. Useful for developers looking to implement Mac OS X features while supporting multiple platforms with minimal impact.

This class has been derived from OSXAdapter 2.0 © Apple Inc., All Rights Rserved.

Version:
$Id: OSXAdapter.java 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer

Field Summary
protected  java.lang.String proxySignature
           
protected  java.awt.event.ActionListener targetAction
           
protected  java.lang.reflect.Method targetMethod
           
protected  java.lang.Object targetObject
           
 
Constructor Summary
protected OSXAdapter(java.lang.String proxySignature, java.awt.event.ActionListener handler)
          Each OSXAdapter has the name of the EAWT method it intends to listen for (handleAbout, for example), the Object that will ultimately perform the task, and the Method to be called on that Object.
protected OSXAdapter(java.lang.String proxySignature, java.lang.Object target, java.lang.reflect.Method handler)
          Each OSXAdapter has the name of the EAWT method it intends to listen for (handleAbout, for example), the Object that will ultimately perform the task, and the Method to be called on that Object.
 
Method Summary
 boolean callTarget(java.lang.Object appleEvent)
          Override this method to perform any operations on the event that comes with the various callbacks.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          InvocationHandler implementation.
protected  boolean isCorrectMethod(java.lang.reflect.Method method, java.lang.Object[] args)
          Compare the method that was called to the intended method when the OSXAdapter instance was created (e.g.
static void setAboutHandler(java.awt.event.ActionListener aboutHandler)
          The action listener will be called when the user selects the About item in the application menu.
protected  void setApplicationEventHandled(java.lang.Object event, boolean handled)
          It is important to mark the ApplicationEvent as handled and cancel the default behavior.
static void setHandler(OSXAdapter adapter)
          setHandler creates a Proxy object from the passed OSXAdapter and adds it as an ApplicationListener.
static void setOpenApplicationHandler(java.awt.event.ActionListener openHandler)
          The action listener will be called when the application receives an Open Application event from the Finder or another application.
static void setOpenFileHandler(java.awt.event.ActionListener fileHandler)
          Pass this method an ActionListener equipped to handle document events from the Finder.
static void setPreferencesHandler(java.awt.event.ActionListener prefsHandler)
          Pass this method an ActionListener equipped to display application options.
static void setPrintFileHandler(java.awt.event.ActionListener fileHandler)
          Pass this method an ActionListener equipped to handle document events from the Finder.
static void setQuitHandler(java.awt.event.ActionListener aboutHandler)
          The action listener will be called when the Quit menu item is selected from the application menu.
static void setReOpenApplicationHandler(java.awt.event.ActionListener reopenHandler)
          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
 

Field Detail

targetAction

protected java.awt.event.ActionListener targetAction

targetObject

protected java.lang.Object targetObject

targetMethod

protected java.lang.reflect.Method targetMethod

proxySignature

protected java.lang.String proxySignature
Constructor Detail

OSXAdapter

protected OSXAdapter(java.lang.String proxySignature,
                     java.lang.Object target,
                     java.lang.reflect.Method handler)
Each OSXAdapter has the name of the EAWT method it intends to listen for (handleAbout, for example), the Object that will ultimately perform the task, and the Method to be called on that Object.


OSXAdapter

protected OSXAdapter(java.lang.String proxySignature,
                     java.awt.event.ActionListener handler)
Each OSXAdapter has the name of the EAWT method it intends to listen for (handleAbout, for example), the Object that will ultimately perform the task, and the Method to be called on that Object.

Method Detail

setOpenApplicationHandler

public static void setOpenApplicationHandler(java.awt.event.ActionListener openHandler)
The action listener will be 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.


setReOpenApplicationHandler

public static void setReOpenApplicationHandler(java.awt.event.ActionListener reopenHandler)
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.


setQuitHandler

public static void setQuitHandler(java.awt.event.ActionListener aboutHandler)
The action listener will be called when the Quit menu item is selected from the application menu.


setAboutHandler

public static void setAboutHandler(java.awt.event.ActionListener aboutHandler)
The action listener will be called when the user selects the About item in the application menu.


setPreferencesHandler

public static void setPreferencesHandler(java.awt.event.ActionListener prefsHandler)
Pass this method an ActionListener equipped to display application options. They will be called when the Preferences menu item is selected from the application menu.


setOpenFileHandler

public static void setOpenFileHandler(java.awt.event.ActionListener fileHandler)
Pass this method an ActionListener equipped to handle document events from the Finder. Documents are registered with the Finder via the CFBundleDocumentTypes dictionary in the application bundle's Info.plist.

The filename is passed as the actionCommand.


setPrintFileHandler

public static void setPrintFileHandler(java.awt.event.ActionListener fileHandler)
Pass this method an ActionListener equipped to handle document events from the Finder. Documents are registered with the Finder via the CFBundleDocumentTypes dictionary in the application bundle's Info.plist.

The filename is passed as the actionCommand.


setHandler

public static void setHandler(OSXAdapter adapter)
setHandler creates a Proxy object from the passed OSXAdapter and adds it as an ApplicationListener.


callTarget

public boolean callTarget(java.lang.Object appleEvent)
                   throws java.lang.reflect.InvocationTargetException,
                          java.lang.IllegalAccessException
Override this method to perform any operations on the event that comes with the various callbacks. See setOpenFileHandler above for an example.

Throws:
java.lang.reflect.InvocationTargetException
java.lang.IllegalAccessException

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
InvocationHandler implementation. This is the entry point for our proxy object; it is called every time an ApplicationListener method is invoked.

Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable

isCorrectMethod

protected boolean isCorrectMethod(java.lang.reflect.Method method,
                                  java.lang.Object[] args)
Compare the method that was called to the intended method when the OSXAdapter instance was created (e.g. handleAbout, handleQuit, handleOpenFile, etc.).


setApplicationEventHandled

protected void setApplicationEventHandled(java.lang.Object event,
                                          boolean handled)
It is important to mark the ApplicationEvent as handled and cancel the default behavior. This method checks for a boolean result from the proxy method and sets the event accordingly.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.