1+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+ /*
4+ Part of the Processing project - http://processing.org
5+
6+ Copyright (c) 2008 Ben Fry and Casey Reas
7+
8+ This program is free software; you can redistribute it and/or modify
9+ it under the terms of the GNU General Public License as published by
10+ the Free Software Foundation; either version 2 of the License, or
11+ (at your option) any later version.
12+
13+ This program is distributed in the hope that it will be useful,
14+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+ GNU General Public License for more details.
17+
18+ You should have received a copy of the GNU General Public License
19+ along with this program; if not, write to the Free Software Foundation,
20+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21+ */
22+
23+ package processing .app .macosx ;
24+
25+ import java .awt .Insets ;
26+ import java .io .File ;
27+ import java .io .FileNotFoundException ;
28+
29+ import javax .swing .UIManager ;
30+
31+ import com .apple .eio .FileManager ;
32+
33+ import processing .app .Base ;
34+
35+
36+ /**
37+ * Platform handler for Mac OS X.
38+ */
39+ public class Platform extends processing .app .Platform {
40+
41+ public void setLookAndFeel () throws Exception {
42+ // Use the Quaqua L & F on OS X to make JFileChooser less awful
43+ UIManager .setLookAndFeel ("ch.randelshofer.quaqua.QuaquaLookAndFeel" );
44+ // undo quaqua trying to fix the margins, since we've already
45+ // hacked that in, bit by bit, over the years
46+ UIManager .put ("Component.visualMargin" , new Insets (1 , 1 , 1 , 1 ));
47+ }
48+
49+
50+ public void init (Base base ) {
51+ new ThinkDifferent (base );
52+ /*
53+ try {
54+ String name = "processing.app.macosx.ThinkDifferent";
55+ Class osxAdapter = ClassLoader.getSystemClassLoader().loadClass(name);
56+
57+ Class[] defArgs = { Base.class };
58+ Method registerMethod = osxAdapter.getDeclaredMethod("register", defArgs);
59+ if (registerMethod != null) {
60+ Object[] args = { this };
61+ registerMethod.invoke(osxAdapter, args);
62+ }
63+ } catch (NoClassDefFoundError e) {
64+ // This will be thrown first if the OSXAdapter is loaded on a system without the EAWT
65+ // because OSXAdapter extends ApplicationAdapter in its def
66+ System.err.println("This version of Mac OS X does not support the Apple EAWT." +
67+ "Application Menu handling has been disabled (" + e + ")");
68+
69+ } catch (ClassNotFoundException e) {
70+ // This shouldn't be reached; if there's a problem with the OSXAdapter
71+ // we should get the above NoClassDefFoundError first.
72+ System.err.println("This version of Mac OS X does not support the Apple EAWT. " +
73+ "Application Menu handling has been disabled (" + e + ")");
74+ } catch (Exception e) {
75+ System.err.println("Exception while loading BaseOSX:");
76+ e.printStackTrace();
77+ }
78+ */
79+ }
80+
81+
82+ public File getSettingsFolder () throws Exception {
83+ return new File (getLibraryFolder (), "Processing" );
84+ }
85+
86+
87+ public File getDefaultSketchbookFolder () throws Exception {
88+ return new File (getDocumentsFolder (), "Processing" );
89+ /*
90+ // looking for /Users/blah/Documents/Processing
91+ try {
92+ Class clazz = Class.forName("processing.app.BaseMacOS");
93+ Method m = clazz.getMethod("getDocumentsFolder", new Class[] { });
94+ String documentsPath = (String) m.invoke(null, new Object[] { });
95+ sketchbookFolder = new File(documentsPath, "Processing");
96+
97+ } catch (Exception e) {
98+ sketchbookFolder = promptSketchbookLocation();
99+ }
100+ */
101+ }
102+
103+
104+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
105+
106+
107+ // Some of these are supposedly constants in com.apple.eio.FileManager,
108+ // however they don't seem to link properly from Eclipse.
109+
110+ static final int kDocumentsFolderType =
111+ ('d' << 24 ) | ('o' << 16 ) | ('c' << 8 ) | 's' ;
112+ //static final int kPreferencesFolderType =
113+ // ('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
114+ static final int kDomainLibraryFolderType =
115+ ('d' << 24 ) | ('l' << 16 ) | ('i' << 8 ) | 'b' ;
116+ static final short kUserDomain = -32763 ;
117+
118+
119+ // apple java extensions documentation
120+ // http://developer.apple.com/documentation/Java/Reference/1.5.0
121+ // /appledoc/api/com/apple/eio/FileManager.html
122+
123+ // carbon folder constants
124+ // http://developer.apple.com/documentation/Carbon/Reference
125+ // /Folder_Manager/folder_manager_ref/constant_6.html#/
126+ // /apple_ref/doc/uid/TP30000238/C006889
127+
128+ // additional information found int the local file:
129+ // /System/Library/Frameworks/CoreServices.framework
130+ // /Versions/Current/Frameworks/CarbonCore.framework/Headers/
131+
132+
133+ protected String getLibraryFolder () throws FileNotFoundException {
134+ return FileManager .findFolder (kUserDomain , kDomainLibraryFolderType );
135+ }
136+
137+
138+ protected String getDocumentsFolder () throws FileNotFoundException {
139+ return FileManager .findFolder (kUserDomain , kDocumentsFolderType );
140+ }
141+ }
0 commit comments