2828import java .io .IOException ;
2929import java .net .URI ;
3030
31- import com .apple .eio .FileManager ;
31+ import javax .swing .JMenu ;
32+ import javax .swing .JMenuBar ;
3233
3334import processing .app .Base ;
3435import processing .app .Messages ;
3536import processing .app .platform .DefaultPlatform ;
37+ import processing .app .ui .About ;
3638
3739
3840/**
39- * Platform handler for Mac OS X .
41+ * Platform handler for macOS .
4042 */
4143public class MacPlatform extends DefaultPlatform {
4244
43- // Removing for 2.0b8 because Quaqua doesn't have OS X 10.8 version.
44- /*
45- public void setLookAndFeel() throws Exception {
46- // Use the Quaqua L & F on OS X to make JFileChooser less awful
47- UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
48- // undo quaqua trying to fix the margins, since we've already
49- // hacked that in, bit by bit, over the years
50- UIManager.put("Component.visualMargin", new Insets(1, 1, 1, 1));
51- }
52- */
53-
5445 public void saveLanguage (String language ) {
5546 String [] cmdarray = new String []{
5647 "defaults" , "write" ,
@@ -67,35 +58,42 @@ public void saveLanguage(String language) {
6758
6859 public void initBase (Base base ) {
6960 super .initBase (base );
61+
62+ final Desktop desktop = Desktop .getDesktop ();
63+
7064 System .setProperty ("apple.laf.useScreenMenuBar" , "true" );
71- ThinkDifferent .init (base );
72- /*
73- try {
74- String name = "processing.app.macosx.ThinkDifferent";
75- Class osxAdapter = ClassLoader.getSystemClassLoader().loadClass(name);
76-
77- Class[] defArgs = { Base.class };
78- Method registerMethod = osxAdapter.getDeclaredMethod("register", defArgs);
79- if (registerMethod != null) {
80- Object[] args = { this };
81- registerMethod.invoke(osxAdapter, args);
65+
66+ // Set the menu bar to be used when nothing else is open.
67+ JMenuBar defaultMenuBar = new JMenuBar ();
68+ JMenu fileMenu = base .initDefaultFileMenu ();
69+ defaultMenuBar .add (fileMenu );
70+ desktop .setDefaultMenuBar (defaultMenuBar );
71+
72+ desktop .setAboutHandler ((event ) -> {
73+ new About (null );
74+ });
75+
76+ desktop .setPreferencesHandler ((event ) -> {
77+ base .handlePrefs ();
78+ });
79+
80+ desktop .setOpenFileHandler ((event ) -> {
81+ for (File file : event .getFiles ()) {
82+ base .handleOpen (file .getAbsolutePath ());
8283 }
83- } catch (NoClassDefFoundError e) {
84- // This will be thrown first if the OSXAdapter is loaded on a system without the EAWT
85- // because OSXAdapter extends ApplicationAdapter in its def
86- System.err.println("This version of Mac OS X does not support the Apple EAWT." +
87- "Application Menu handling has been disabled (" + e + ")");
88-
89- } catch (ClassNotFoundException e) {
90- // This shouldn't be reached; if there's a problem with the OSXAdapter
91- // we should get the above NoClassDefFoundError first.
92- System.err.println("This version of Mac OS X does not support the Apple EAWT. " +
93- "Application Menu handling has been disabled (" + e + ")");
94- } catch (Exception e) {
95- System.err.println("Exception while loading BaseOSX:");
96- e.printStackTrace();
97- }
98- */
84+ });
85+
86+ desktop .setPrintFileHandler ((event ) -> {
87+ // TODO not yet implemented
88+ });
89+
90+ desktop .setQuitHandler ((event , quitResponse ) -> {
91+ if (base .handleQuit ()) {
92+ quitResponse .performQuit ();
93+ } else {
94+ quitResponse .cancelQuit ();
95+ }
96+ });
9997 }
10098
10199
@@ -106,30 +104,9 @@ public File getSettingsFolder() throws Exception {
106104
107105 public File getDefaultSketchbookFolder () throws Exception {
108106 return new File (getDocumentsFolder (), "Processing" );
109- /*
110- // looking for /Users/blah/Documents/Processing
111- try {
112- Class clazz = Class.forName("processing.app.BaseMacOS");
113- Method m = clazz.getMethod("getDocumentsFolder", new Class[] { });
114- String documentsPath = (String) m.invoke(null, new Object[] { });
115- sketchbookFolder = new File(documentsPath, "Processing");
116-
117- } catch (Exception e) {
118- sketchbookFolder = promptSketchbookLocation();
119- }
120- */
121107 }
122108
123109
124- // /**
125- // * Moves the specified File object (which might be a file or folder)
126- // * to the trash.
127- // */
128- // public boolean deleteFile(File file) throws IOException {
129- // return FileManager.moveToTrash(file);
130- // }
131-
132-
133110 public void openURL (String url ) throws Exception {
134111 try {
135112 Desktop .getDesktop ().browse (new URI (url ));
@@ -145,64 +122,23 @@ public void openURL(String url) throws Exception {
145122 }
146123
147124
148- /*
149- public void openURL(String url) throws Exception {
150- if (PApplet.javaVersion < 1.6f) {
151- if (url.startsWith("http://")) {
152- // formerly com.apple.eio.FileManager.openURL(url);
153- // but due to deprecation, instead loading dynamically
154- try {
155- Class<?> eieio = Class.forName("com.apple.eio.FileManager");
156- Method openMethod =
157- eieio.getMethod("openURL", new Class[] { String.class });
158- openMethod.invoke(null, new Object[] { url });
159- } catch (Exception e) {
160- e.printStackTrace();
161- }
162- } else {
163- // Assume this is a file instead, and just open it.
164- // Extension of http://dev.processing.org/bugs/show_bug.cgi?id=1010
165- processing.core.PApplet.open(url);
166- }
167- } else {
168- try {
169- Class<?> desktopClass = Class.forName("java.awt.Desktop");
170- Method getMethod = desktopClass.getMethod("getDesktop");
171- Object desktop = getMethod.invoke(null, new Object[] { });
172-
173- // for Java 1.6, replacing with java.awt.Desktop.browse()
174- // and java.awt.Desktop.open()
175- if (url.startsWith("http://")) { // browse to a location
176- Method browseMethod =
177- desktopClass.getMethod("browse", new Class[] { URI.class });
178- browseMethod.invoke(desktop, new Object[] { new URI(url) });
179- } else { // open a file
180- Method openMethod =
181- desktopClass.getMethod("open", new Class[] { File.class });
182- openMethod.invoke(desktop, new Object[] { new File(url) });
183- }
184- } catch (Exception e) {
185- e.printStackTrace();
186- }
187- }
188- }
125+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
189126
190127
191- public boolean openFolderAvailable() {
192- return true;
128+ // TODO I suspect this won't work much longer, since access to the user's
129+ // home directory seems verboten on more recent macOS versions [fry 191008]
130+ protected String getLibraryFolder () throws FileNotFoundException {
131+ return System .getProperty ("user.home" ) + "/Library" ;
193132 }
194133
195134
196- public void openFolder(File file) throws Exception {
197- //openURL(file.getAbsolutePath()); // handles char replacement, etc
198- processing.core.PApplet.open(file.getAbsolutePath()) ;
135+ // see notes on getLibraryFolder()
136+ protected String getDocumentsFolder () throws FileNotFoundException {
137+ return System . getProperty ( "user.home" ) + "/Documents" ;
199138 }
200- */
201-
202-
203- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
204139
205140
141+ /*
206142 // Some of these are supposedly constants in com.apple.eio.FileManager,
207143 // however they don't seem to link properly from Eclipse.
208144
@@ -237,4 +173,5 @@ protected String getLibraryFolder() throws FileNotFoundException {
237173 protected String getDocumentsFolder() throws FileNotFoundException {
238174 return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
239175 }
176+ */
240177}
0 commit comments