Groovy Documentation

griffon.swt.support
[Java] Class CocoaUIEnhancer

java.lang.Object
  griffon.swt.support.CocoaUIEnhancer

public class CocoaUIEnhancer
extends Object

Provide a hook to connecting the Preferences, About and Quit menu items of the Mac OS X Application menu when using the SWT Cocoa bindings.

This code does not require the Cocoa SWT JAR in order to be compiled as it uses reflection to access the Cocoa specific API methods. It does, however, depend on JFace (for IAction), but you could easily modify the code to use SWT Listeners instead in order to use this class in SWT only applications.

This code was influenced by the CarbonUIEnhancer from Agynami with the implementation being modified from the org.eclipse.ui.internal.cocoa.CocoaUIEnhancer.

This class works with both the 32-bit and 64-bit versions of the SWT Cocoa bindings.

This class is released under the Eclipse Public License (EPL). Taken from http://stackoverflow.com/questions/6665933/swt-how-to-handle-application-events-correctly-on-os-x Posted (and authored) by Jean-Philippe Pellet.


Nested Class Summary
private static class CocoaUIEnhancer.MenuHookObject

Class invoked via the Callback object to run the about and preferences actions.

 
Field Summary
private String appName

private static long kAboutMenuItem

private static long kPreferencesMenuItem

private static long kQuitMenuItem

static org.eclipse.swt.internal.Callback proc3Args

static long sel_aboutMenuItemSelected_

static long sel_preferencesMenuItemSelected_

static long sel_toolbarButtonClicked_

 
Constructor Summary
CocoaUIEnhancer()

 
Method Summary
def CocoaUIEnhancer(String appName)

Construct a new CocoaUIEnhancer.

private Class classForName(String classname)

private long convertToLong(Object object)

void hookApplicationMenu(org.eclipse.swt.widgets.Display display, org.eclipse.swt.widgets.Listener quitListener, RunnableWithArgs aboutAction, RunnableWithArgs preferencesAction)

Hook the given Listener to the Mac OS X application Quit menu and the IActions to the About and Preferences menus.

private void initialize(Object callbackObject)

private static Object invoke(Class clazz, String methodName, Object[] args)

private static Object invoke(Class clazz, Object target, String methodName, Object[] args)

private Object invoke(Class cls, String methodName)

private Object invoke(Class cls, String methodName, Class[] paramTypes, Object... arguments)

private Object invoke(Object obj, String methodName)

private Object invoke(Object obj, String methodName, Class[] paramTypes, Object... arguments)

private long registerName(Class osCls, String name)

private static Object wrapPointer(long value)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

appName

private final String appName


kAboutMenuItem

private static final long kAboutMenuItem


kPreferencesMenuItem

private static final long kPreferencesMenuItem


kQuitMenuItem

private static final long kQuitMenuItem


proc3Args

static org.eclipse.swt.internal.Callback proc3Args


sel_aboutMenuItemSelected_

static long sel_aboutMenuItemSelected_


sel_preferencesMenuItemSelected_

static long sel_preferencesMenuItemSelected_


sel_toolbarButtonClicked_

static long sel_toolbarButtonClicked_


 
Constructor Detail

CocoaUIEnhancer

CocoaUIEnhancer()


 
Method Detail

CocoaUIEnhancer

public def CocoaUIEnhancer(String appName)
Construct a new CocoaUIEnhancer.
Parameters:
appName - The name of the application. It will be used to customize the About and Quit menu items. If you do not wish to customize the About and Quit menu items, just pass null here.


classForName

private Class classForName(String classname)


convertToLong

private long convertToLong(Object object)


hookApplicationMenu

public void hookApplicationMenu(org.eclipse.swt.widgets.Display display, org.eclipse.swt.widgets.Listener quitListener, RunnableWithArgs aboutAction, RunnableWithArgs preferencesAction)
Hook the given Listener to the Mac OS X application Quit menu and the IActions to the About and Preferences menus.
Parameters:
display - The Display to use.
quitListener - The listener to invoke when the Quit menu is invoked.
aboutAction - The action to run when the About menu is invoked.
preferencesAction - The action to run when the Preferences menu is invoked.


initialize

private void initialize(Object callbackObject)


invoke

private static Object invoke(Class clazz, String methodName, Object[] args)


invoke

private static Object invoke(Class clazz, Object target, String methodName, Object[] args)


invoke

private Object invoke(Class cls, String methodName)


invoke

private Object invoke(Class cls, String methodName, Class[] paramTypes, Object... arguments)


invoke

private Object invoke(Object obj, String methodName)


invoke

private Object invoke(Object obj, String methodName, Class[] paramTypes, Object... arguments)


registerName

private long registerName(Class osCls, String name)


wrapPointer

private static Object wrapPointer(long value)


 

Groovy Documentation