/** * Constructor. * * @throws Exception if any error occurs. */ public GUIMacOSX() throws Exception { // Name for the dock icon and the application menu System.setProperty(P_ABOUT_NAME, NAME); // Show menu in the screen menu instead of inside the application window System.setProperty(P_SCREEN_MENU_BAR, "true"); // load native java classes... appClass = Class.forName(C_APPLICATION); appObj = invoke(appClass, null, "getApplication", EC, EO); Class.forName(C_APPLICATION_EVENT); if (appObj != null) { invoke("addAboutMenuItem"); invoke("setEnabledAboutMenu", true); invoke("addPreferencesMenuItem"); invoke("setEnabledPreferencesMenu", true); addDockIcon(); final Class<?> alc = Class.forName(C_APPLICATION_LISTENER); final Object listener = Proxy.newProxyInstance( getClass().getClassLoader(), new Class[] {alc}, new AppInvocationHandler()); invoke("addApplicationListener", alc, listener); } }
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { final Object obj = args[0]; /* * Get the name of the method and call the method of this object that has * the same name with only the first argument. * This emulates the an implementation of the native 'ApplicationListener' * interface (@see com.apple.eawt.ApplicationListener on Mac OS X). * The argument is an instance of the 'ApplicationEvent' class * (@see com.apple.eawt.ApplicationEvent) */ try { GUIMacOSX.invoke(this, method.getName(), Object.class, obj); } catch (final NoSuchMethodException ex) { GUIMacOSX.invoke(this, method.getName()); } // mark the current event as 'handled' GUIMacOSX.invoke(obj, "setHandled", true); return null; }
/** * Sets a value for the badge in the dock. * * @param value string value * @throws Exception if any error occurs */ public void setBadge(final String value) throws Exception { invoke("setDockIconBadge", String.class, value); }
/** * Adds the project icon to the dock. * * @throws Exception if any error occurs. */ private void addDockIcon() throws Exception { invoke("setDockIconImage", Image.class, BaseXLayout.image("logo")); }