1
1
package edu .stanford .nlp .trees .tregex .gui ;
2
2
3
- import com .apple .eawt .ApplicationAdapter ;
4
- import com .apple .eawt .ApplicationEvent ;
5
3
4
+ import java .awt .*;
6
5
7
6
/**
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
+ *
10
11
* @author rafferty
12
+ * @author Christopher Manning
11
13
*
12
14
*/
13
- public class OSXAdapter extends ApplicationAdapter {
15
+ public class OSXAdapter {
14
16
15
17
private static OSXAdapter adapter ;
16
- private static com .apple .eawt .Application app ;
18
+ private static Desktop desktop ;
19
+ private static TregexGUI mainApp ;
20
+
17
21
18
- private TregexGUI mainApp ;
19
-
20
22
private OSXAdapter (TregexGUI inApp ) {
21
23
mainApp = inApp ;
22
24
}
23
25
24
26
// implemented handler methods. These are basically hooks into existing
25
27
// 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 () {
28
30
if (mainApp != null ) {
29
- ae .setHandled (true );
31
+ // ae.setHandled(true);
30
32
mainApp .about ();
31
33
} else {
32
34
throw new IllegalStateException ("handleAbout: TregexGUI instance detached from listener" );
33
35
}
34
36
}
35
37
36
- @ Override
37
- public void handlePreferences (ApplicationEvent ae ) {
38
+ public void handlePreferences () {
38
39
if (mainApp != null ) {
39
40
mainApp .doPreferences ();
40
- ae .setHandled (true );
41
+ // ae.setHandled(true);
41
42
} else {
42
43
throw new IllegalStateException ("handlePreferences: TregexGUI instance detached from listener" );
43
44
}
44
45
}
45
46
46
- @ Override
47
- public void handleQuit (ApplicationEvent ae ) {
47
+ public void handleQuit () {
48
48
if (mainApp != null ) {
49
49
/*
50
50
/ You MUST setHandled(false) if you want to delay or cancel the quit.
@@ -53,35 +53,38 @@ public void handleQuit(ApplicationEvent ae) {
53
53
/ on all platforms. This example simply cancels the AppleEvent-based quit and
54
54
/ defers to that universal method.
55
55
*/
56
- ae .setHandled (false );
56
+ // ae.setHandled(false);
57
57
TregexGUI .doQuit ();
58
58
} else {
59
59
throw new IllegalStateException ("handleQuit: TregexGUI instance detached from listener" );
60
60
}
61
61
}
62
62
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
+ // }
71
72
72
73
if (adapter == null ) {
73
74
adapter = new OSXAdapter (inApp );
74
75
}
75
- app .addApplicationListener (adapter );
76
+ // app.addApplicationListener(adapter);
76
77
}
77
78
78
79
// Another static entry point for EAWT functionality. Enables the
79
80
// "Preferences..." menu item in the application menu.
80
81
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);
85
88
}
86
89
87
90
}
0 commit comments