Update to java 9 for OSX integration support, fix broken OSX UI integration (app prefs)
diff --git a/pom.xml b/pom.xml
index 1b77c81..9dabf46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -144,6 +144,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
+ <configuration>
+ <source>9</source>
+ <target>9</target>
+ </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -510,7 +514,7 @@
<plugin>
<groupId>de.perdian.maven.plugins</groupId>
<artifactId>macosappbundler-maven-plugin</artifactId>
- <version>1.9.0</version>
+ <version>1.10.2</version>
<configuration>
<plist>
<CFBundleIconFile>src/main/resources/logo.icns</CFBundleIconFile>
diff --git a/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java b/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java
index 8ac570b..9124099 100644
--- a/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java
+++ b/src/main/java/org/apache/log4j/chainsaw/osx/OSXIntegration.java
@@ -19,81 +19,36 @@
import org.apache.log4j.Logger;
import org.apache.log4j.chainsaw.LogUI;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
+import java.awt.Desktop;
/**
- * This class adds dynamic hooks into OSX version of Java so that various
- * Mac-specific UI guidelines are adhered to.
+ * This class leverages the 'Desktop' awt API in order to follow Mac-specific UI guidelines.
* <p>
- * This class uses reflection to build the necessary hooks so that there is no compile-time
- * dependency on a Mac SDK.
*
* @author psmith
* @see "http://developer.apple.com/documentation/Java/index.html"
*/
public class OSXIntegration {
public static final boolean IS_OSX = System.getProperty("os.name").startsWith("Mac OS X");
- private static final Logger LOG = Logger.getLogger(OSXIntegration.class);
- private static Object applicationInstance;
+ private static final Desktop desktop = Desktop.getDesktop();
- public static final void init(final LogUI logui) {
- LOG.info("OSXIntegration.init() called");
- if (!IS_OSX) {
- LOG.info("Not OSX, ignoring...");
- return;
- }
- try {
- Class applicationClazz = Class.forName("com.apple.eawt.Application");
- Class listenerClass = Class.forName("com.apple.eawt.ApplicationListener");
- applicationInstance = applicationClazz.newInstance();
+ public static final void init(final LogUI logUI) {
+ desktop.setAboutHandler(e ->
+ logUI.showAboutBox()
+ );
-// now register that we want that Preferences menu
- Method enablePreferenceMethod = applicationClazz.getMethod("setEnabledPreferencesMenu", boolean.class);
- enablePreferenceMethod.invoke(applicationInstance, Boolean.TRUE);
-
-
- // no About menu for us for now.
- Method enableAboutMethod = applicationClazz.getMethod("setEnabledAboutMenu", boolean.class);
- enableAboutMethod.invoke(applicationInstance, Boolean.TRUE);
-
- // Need to create a Proxy object to represent an anonymous impl of the ApplicationListener class
- Object listenerProxy = Proxy.newProxyInstance(OSXIntegration.class.getClassLoader(),
- new Class[]{listenerClass},
- new InvocationHandler() {
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- switch (method.getName()) {
- case "handlePreferences":
- LOG.info("handlePreferences(...) called");
- logui.showApplicationPreferences();
- break;
- case "handleQuit":
- setHandled(args[0], logui.exit() ? Boolean.TRUE : Boolean.FALSE);
-
- break;
- case "handleAbout":
- logui.showAboutBox();
- setHandled(args[0], Boolean.TRUE);
- break;
- }
-// TODO think about File Open/Save options
- return null;
- }
-
- private void setHandled(Object event, Boolean val) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Method handleMethod = event.getClass().getMethod("setHandled", boolean.class);
- handleMethod.invoke(event, val);
- }
- });
- // register the proxy object via the addApplicationListener method, cross fingers...
- Method registerListenerMethod = applicationClazz.getMethod("addApplicationListener", listenerClass);
- registerListenerMethod.invoke(applicationInstance, listenerProxy);
- } catch (Exception e) {
- LOG.error("Failed to setup OSXIntegration", e);
- }
+ desktop.setPreferencesHandler(e ->
+ logUI.showApplicationPreferences()
+ );
+ desktop.setQuitHandler((e, r) -> {
+ if (
+ logUI.exit()) {
+ r.performQuit();
+ } else {
+ r.cancelQuit();
+ }
+ }
+ );
}
}