11package edu .stanford .nlp .trees .tregex .gui ;
22
3- import com .apple .eawt .ApplicationAdapter ;
4- import com .apple .eawt .ApplicationEvent ;
53
4+ import java .awt .*;
65
76/**
8- * Class to load OSX specific settings for TregexGUI. Made by consulting the Apple sample code
9- * for a similar (and identically named) class at http://devworld.apple.com/samplecode/OSXAdapter/index.html.
7+ * Class to load macOS-specific settings for TregexGUI. This was initially written to use the (pre-2014, OS X)
8+ * {@code com.apple.eawt.*} library (AppleJavaExtensions.jar), but now uses the Java 9+ methods in
9+ * the {@code java.awt.Desktop} class.
10+ *
1011 * @author rafferty
12+ * @author Christopher Manning
1113 *
1214 */
13- public class OSXAdapter extends ApplicationAdapter {
15+ public class OSXAdapter {
1416
1517 private static OSXAdapter adapter ;
16- private static com .apple .eawt .Application app ;
18+ private static Desktop desktop ;
19+ private static TregexGUI mainApp ;
20+
1721
18- private TregexGUI mainApp ;
19-
2022 private OSXAdapter (TregexGUI inApp ) {
2123 mainApp = inApp ;
2224 }
2325
2426 // implemented handler methods. These are basically hooks into existing
2527 // functionality from the main app, as if it came over from another platform.
26- @ Override
27- public void handleAbout (ApplicationEvent ae ) {
28+
29+ public void handleAbout () {
2830 if (mainApp != null ) {
29- ae .setHandled (true );
31+ // ae.setHandled(true);
3032 mainApp .about ();
3133 } else {
3234 throw new IllegalStateException ("handleAbout: TregexGUI instance detached from listener" );
3335 }
3436 }
3537
36- @ Override
37- public void handlePreferences (ApplicationEvent ae ) {
38+ public void handlePreferences () {
3839 if (mainApp != null ) {
3940 mainApp .doPreferences ();
40- ae .setHandled (true );
41+ // ae.setHandled(true);
4142 } else {
4243 throw new IllegalStateException ("handlePreferences: TregexGUI instance detached from listener" );
4344 }
4445 }
4546
46- @ Override
47- public void handleQuit (ApplicationEvent ae ) {
47+ public void handleQuit () {
4848 if (mainApp != null ) {
4949 /*
5050 / You MUST setHandled(false) if you want to delay or cancel the quit.
@@ -53,35 +53,38 @@ public void handleQuit(ApplicationEvent ae) {
5353 / on all platforms. This example simply cancels the AppleEvent-based quit and
5454 / defers to that universal method.
5555 */
56- ae .setHandled (false );
56+ // ae.setHandled(false);
5757 TregexGUI .doQuit ();
5858 } else {
5959 throw new IllegalStateException ("handleQuit: TregexGUI instance detached from listener" );
6060 }
6161 }
6262
63-
64- // The main entry-point for this functionality. This is the only method
65- // that needs to be called at runtime, and it can easily be done using
66- // reflection (see MyApp.java)
67- public static void registerMacOSXApplication (TregexGUI inApp ) {
68- if (app == null ) {
69- app = new com .apple .eawt .Application ();
70- }
63+
64+ /** The main method for this macOS-specific functionality. */
65+ public static void registerMacOSApplication (TregexGUI inApp ) {
66+ System .setProperty ( "apple.laf.useScreenMenuBar" , "true" );
67+ System .setProperty ( "apple.awt.application.name" , "TregexGUI" );
68+ System .setProperty ( "apple.awt.application.appearance" , "system" );
69+ // if (app == null) {
70+ // app = new com.apple.eawt.Application();
71+ // }
7172
7273 if (adapter == null ) {
7374 adapter = new OSXAdapter (inApp );
7475 }
75- app .addApplicationListener (adapter );
76+ // app.addApplicationListener(adapter);
7677 }
7778
7879 // Another static entry point for EAWT functionality. Enables the
7980 // "Preferences..." menu item in the application menu.
8081 public static void enablePrefs (boolean enabled ) {
81- if (app == null ) {
82- app = new com .apple .eawt .Application ();
83- }
84- app .setEnabledPreferencesMenu (enabled );
82+ System .setProperty ( "apple.laf.useScreenMenuBar" , "true" );
83+ System .setProperty ( "apple.awt.application.name" , "TregexGUI" );
84+ // if (app == null) {
85+ // app = new com.apple.eawt.Application();
86+ // }
87+ // app.setEnabledPreferencesMenu(enabled);
8588 }
8689
8790}
0 commit comments