HiRISE

HiRISE.HiPlan.Utilities
Class Mac_Adapter

java.lang.Object
  extended by HiRISE.HiPlan.Utilities.Mac_Adapter
All Implemented Interfaces:
InvocationHandler

public class Mac_Adapter
extends Object
implements InvocationHandler

A mechanism to hook Mac OS X application menu functionality into existing methods. This mechanism uses reflection to avoid stub methods and classes.

This class is adapted from Apple's OSXAdapter example code. It only implements the About handler, the Quit handler, and the Preferences handler. It does not implement the Open Application handler, the Re-Open Application handler, the Open File handler, or the Print File handler at present. It could be modified to do so in the future, however.

Version:
1.4

Field Summary
static String ID
          Class identification name with source code version and date.
protected  Method method
          The method that will handle a this adapter's application event.
protected  Object object
          The object that on which the method is called.
protected  String signature
          The name of the application event method to handle.
 
Constructor Summary
protected Mac_Adapter(String signature, Object object, Method method)
          Creates a new Mac adapter to handle a given application event.
 
Method Summary
 boolean callTarget(Object appleEvent)
           
 Object invoke(Object proxy, Method method, Object[] args)
           
protected  boolean isCorrectMethod(Method method, Object[] args)
           
static void setAboutHandler(Object target, Method method)
           
protected  void setApplicationEventHandled(Object event, boolean handled)
           
static void setDockIconBadge(String badge)
           
static void setDockIconImage(Image image)
           
static void setHandler(Mac_Adapter adapter)
           
static void setJmarsQuitHandler()
          Sets the quit handler for JMARS applications.
static void setPreferencesHandler(Object target, Method method)
           
static void setQuitHandler(Object target, Method method)
          Sets a handler for the Mac Quit menu item.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
Class identification name with source code version and date.

See Also:
Constant Field Values

signature

protected String signature
The name of the application event method to handle. For example, handleQuit.


object

protected Object object
The object that on which the method is called. This object obviously must implement the method.


method

protected Method method
The method that will handle a this adapter's application event.

Constructor Detail

Mac_Adapter

protected Mac_Adapter(String signature,
                      Object object,
                      Method method)
Creates a new Mac adapter to handle a given application event.

Parameters:
signature - the name of the method to handle.
object - the object that implements the method.
method - the method that handles the event.
Method Detail

setHandler

public static void setHandler(Mac_Adapter adapter)

setAboutHandler

public static void setAboutHandler(Object target,
                                   Method method)

setPreferencesHandler

public static void setPreferencesHandler(Object target,
                                         Method method)

setQuitHandler

public static void setQuitHandler(Object target,
                                  Method method)
Sets a handler for the Mac Quit menu item. The handler should return a boolean. If the return value is true, the application is allowed to quit. If false, it is not.

Parameters:
target - the object that will handle the quit event.
method - the method of target that handles the quit event.

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

isCorrectMethod

protected boolean isCorrectMethod(Method method,
                                  Object[] args)

callTarget

public boolean callTarget(Object appleEvent)
                   throws IllegalAccessException,
                          InvocationTargetException
Throws:
IllegalAccessException
InvocationTargetException

setApplicationEventHandled

protected void setApplicationEventHandled(Object event,
                                          boolean handled)

setDockIconImage

public static void setDockIconImage(Image image)

setDockIconBadge

public static void setDockIconBadge(String badge)

setJmarsQuitHandler

public static void setJmarsQuitHandler()
Sets the quit handler for JMARS applications. The Mac Quit menu item is not normally functional in JMARS on a Mac. This method enables it. Note that if this method relies on some reflection tricks beyond what the Mac Adapter already does normally, so if this method is invoked outside of a running JMARS, it will cause problems.


HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona