Compile against com.apple.eawt.* stub

This commit is contained in:
Reinhard Pointner 2016-03-19 14:42:43 +00:00
parent 22ece907de
commit adda35edd4
3 changed files with 21 additions and 31 deletions

View File

@ -32,5 +32,6 @@
<classpathentry kind="lib" path="lib/ivy/jar/language-detector.jar"/> <classpathentry kind="lib" path="lib/ivy/jar/language-detector.jar"/>
<classpathentry kind="lib" path="lib/ivy/bundle/guava.jar"/> <classpathentry kind="lib" path="lib/ivy/bundle/guava.jar"/>
<classpathentry kind="lib" path="lib/ivy/jar/streamex.jar"/> <classpathentry kind="lib" path="lib/ivy/jar/streamex.jar"/>
<classpathentry kind="lib" path="lib/jars/AppleJavaExtensions.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

Binary file not shown.

View File

@ -8,19 +8,23 @@ import java.awt.SecondaryLoop;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.Window; import java.awt.Window;
import java.io.File; import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.logging.Level;
import javax.swing.JMenuBar; import javax.swing.JMenuBar;
import javax.swing.UIManager; import javax.swing.UIManager;
import com.apple.eawt.Application;
import com.apple.eawt.FullScreenUtilities;
import com.apple.eawt.QuitStrategy;
import com.apple.eio.FileManager;
import com.sun.jna.Pointer;
import ca.weblite.objc.Client; import ca.weblite.objc.Client;
import ca.weblite.objc.Proxy; import ca.weblite.objc.Proxy;
import com.sun.jna.Pointer;
public class MacAppUtilities { public class MacAppUtilities {
private static Client _objc; private static Client _objc;
@ -85,7 +89,7 @@ public class MacAppUtilities {
// Enter the loop to block the current event handler, but leave UI responsive // Enter the loop to block the current event handler, but leave UI responsive
if (!secondaryLoop.enter()) { if (!secondaryLoop.enter()) {
throw new IllegalStateException("SecondaryLoop.enter()"); throw new IllegalStateException("SecondaryLoop");
} }
return result; return result;
@ -93,56 +97,41 @@ public class MacAppUtilities {
public static void setWindowCanFullScreen(Window window) { public static void setWindowCanFullScreen(Window window) {
try { try {
Class<?> fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities"); FullScreenUtilities.setWindowCanFullScreen(window, true);
Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class<?>[] { Window.class, boolean.class });
setWindowCanFullScreen.invoke(null, window, true);
} catch (Throwable t) { } catch (Throwable t) {
debug.warning("setWindowCanFullScreen not supported: " + t); debug.log(Level.WARNING, t.getMessage(), t);
} }
} }
public static void requestForeground() { public static void requestForeground() {
try { try {
Class<?> application = Class.forName("com.apple.eawt.Application"); Application.getApplication().requestForeground(true);
Object instance = application.getMethod("getApplication").invoke(null);
Method requestForeground = application.getMethod("requestForeground", new Class<?>[] { boolean.class });
requestForeground.invoke(instance, true);
} catch (Throwable t) { } catch (Throwable t) {
debug.warning("requestForeground not supported: " + t); debug.log(Level.WARNING, t.getMessage(), t);
} }
} }
public static void revealInFinder(File file) { public static void revealInFinder(File file) {
try { try {
Class<?> fileManager = Class.forName("com.apple.eio.FileManager"); FileManager.revealInFinder(file);
Method revealInFinder = fileManager.getMethod("revealInFinder", new Class<?>[] { File.class });
revealInFinder.invoke(null, file);
} catch (Throwable t) { } catch (Throwable t) {
debug.warning("revealInFinder not supported: " + t); debug.log(Level.WARNING, t.getMessage(), t);
} }
} }
public static void setDefaultMenuBar(JMenuBar menu) { public static void setDefaultMenuBar(JMenuBar menu) {
try { try {
Class<?> application = Class.forName("com.apple.eawt.Application"); Application.getApplication().setDefaultMenuBar(menu);
Object instance = application.getMethod("getApplication").invoke(null);
Method setDefaultMenuBar = application.getMethod("setDefaultMenuBar", new Class<?>[] { JMenuBar.class });
setDefaultMenuBar.invoke(instance, menu);
} catch (Throwable t) { } catch (Throwable t) {
debug.warning("setDefaultMenuBar not supported: " + t); debug.log(Level.WARNING, t.getMessage(), t);
} }
} }
public static void setQuitStrategy(String field) { public static void setQuitStrategyCloseAll() {
try { try {
Class<?> application = Class.forName("com.apple.eawt.Application"); Application.getApplication().setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
Object instance = application.getMethod("getApplication").invoke(null);
Class<?> quitStrategy = Class.forName("com.apple.eawt.QuitStrategy");
Method setQuitStrategy = application.getMethod("setQuitStrategy", quitStrategy);
Object closeAllWindows = quitStrategy.getField(field).get(null);
setQuitStrategy.invoke(instance, closeAllWindows);
} catch (Throwable t) { } catch (Throwable t) {
debug.warning("setQuitStrategy not supported: " + t); debug.log(Level.WARNING, t.getMessage(), t);
} }
} }
@ -151,7 +140,7 @@ public class MacAppUtilities {
UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant")); UIManager.put("TitledBorder.border", UIManager.getBorder("InsetBorder.aquaVariant"));
// make sure Application Quit Events get forwarded to normal Window Listeners // make sure Application Quit Events get forwarded to normal Window Listeners
setQuitStrategy("CLOSE_ALL_WINDOWS"); setQuitStrategyCloseAll();
} }
public static boolean isLockedFolder(File folder) { public static boolean isLockedFolder(File folder) {