Skip to content

Commit cf365d2

Browse files
committed
reworking platform-specific functions inside Base
1 parent 495e882 commit cf365d2

File tree

8 files changed

+423
-480
lines changed

8 files changed

+423
-480
lines changed

app/src/processing/app/Base.java

Lines changed: 48 additions & 404 deletions
Large diffs are not rendered by default.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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;
24+
25+
import java.io.File;
26+
27+
import javax.swing.UIManager;
28+
29+
30+
/**
31+
* Used by Base for platform-specific tweaking, for instance finding the
32+
* sketchbook location using the Windows registry, or OS X event handling.
33+
*/
34+
public class Platform {
35+
Base base;
36+
37+
38+
/**
39+
* Set the default L & F. While I enjoy the bounty of the sixteen possible
40+
* exception types that this UIManager method might throw, I feel that in
41+
* just this one particular case, I'm being spoiled by those engineers
42+
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
43+
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
44+
* ways to report to the user exactly what went wrong, and I'll bundle them
45+
* all into a single catch-all "Exception". Because in the end, all I really
46+
* care about is whether things worked or not. And even then, I don't care.
47+
*
48+
* @throws Exception Just like I said.
49+
*/
50+
public void setLookAndFeel() throws Exception {
51+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
52+
}
53+
54+
55+
public void init(Base base) {
56+
this.base = base;
57+
}
58+
59+
60+
public File getSettingsFolder() throws Exception {
61+
// otherwise make a .processing directory int the user's home dir
62+
File home = new File(System.getProperty("user.home"));
63+
File dataFolder = new File(home, ".processing");
64+
return dataFolder;
65+
66+
/*
67+
try {
68+
Class clazz = Class.forName("processing.app.macosx.ThinkDifferent");
69+
Method m = clazz.getMethod("getLibraryFolder", new Class[] { });
70+
String libraryPath = (String) m.invoke(null, new Object[] { });
71+
//String libraryPath = BaseMacOS.getLibraryFolder();
72+
File libraryFolder = new File(libraryPath);
73+
dataFolder = new File(libraryFolder, "Processing");
74+
75+
} catch (Exception e) {
76+
showError("Problem getting data folder",
77+
"Error getting the Processing data folder.", e);
78+
}
79+
*/
80+
}
81+
82+
83+
/**
84+
* @return null if not overridden, which will cause a prompt to show instead.
85+
* @throws Exception
86+
*/
87+
public File getDefaultSketchbookFolder() throws Exception {
88+
return null;
89+
}
90+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.linux;
24+
25+
import javax.swing.UIManager;
26+
27+
28+
/**
29+
* Used by Base for platform-specific tweaking, for instance finding the
30+
* sketchbook location using the Windows registry, or OS X event handling.
31+
*/
32+
public class Platform {
33+
34+
// TODO Need to be smarter here since KDE people ain't gonna like that GTK.
35+
// It may even throw a weird exception at 'em for their trouble.
36+
public void setLookAndFeel() throws Exception {
37+
// Linux is by default even uglier than metal (Motif?).
38+
// Actually, i'm using native menus, so they're even uglier
39+
// and Motif-looking (Lesstif?). Ick. Need to fix this.
40+
//String lfname = UIManager.getCrossPlatformLookAndFeelClassName();
41+
//UIManager.setLookAndFeel(lfname);
42+
43+
// For 0120, trying out the gtk+ look and feel as the default.
44+
// This is available in Java 1.4.2 and later, and it can't possibly
45+
// be any worse than Metal. (Ocean might also work, but that's for
46+
// Java 1.5, and we aren't going there yet)
47+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
48+
}
49+
}
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
}

app/src/processing/app/macosx/ThinkDifferent.java

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,19 @@
2222

2323
package processing.app.macosx;
2424

25-
import java.io.FileNotFoundException;
26-
2725
import processing.app.Base;
2826

2927
import com.apple.eawt.*;
30-
import com.apple.eio.FileManager;
3128

3229

3330
/**
34-
* Deal with issues connected to thinking different.
31+
* Deal with issues related to thinking different. This handles the basic
32+
* Mac OS X menu commands (and apple events) for open, about, prefs, etc.
33+
*
3534
* Based on OSXAdapter.java from Apple DTS.
3635
*
3736
* As of 0140, this code need not be built on platforms other than OS X,
38-
* because it is hit by only two accessor methods in processing.app.Base that
39-
* are now called via reflection.
37+
* because of the new platform structure which isolates through reflection.
4038
*/
4139
public class ThinkDifferent implements ApplicationListener {
4240

@@ -50,8 +48,18 @@ public class ThinkDifferent implements ApplicationListener {
5048
private Base base;
5149

5250

53-
private ThinkDifferent(Base base) {
51+
ThinkDifferent(Base base) {
5452
this.base = base;
53+
54+
if (application == null) {
55+
application = new com.apple.eawt.Application();
56+
}
57+
if (adapter == null) {
58+
adapter = new ThinkDifferent(base);
59+
}
60+
application.addApplicationListener(adapter);
61+
application.setEnabledAboutMenu(true);
62+
application.setEnabledPreferencesMenu(true);
5563
}
5664

5765

@@ -112,66 +120,4 @@ public void handleQuit(ApplicationEvent ae) {
112120

113121
public void handleReOpenApplication(ApplicationEvent arg0) {
114122
}
115-
116-
117-
// The main entry-point for this functionality. This is the only method
118-
// that needs to be called at runtime, and it can easily be done using
119-
// reflection (see Base.java)
120-
public static void register(Base base) {
121-
if (application == null) {
122-
application = new com.apple.eawt.Application();
123-
}
124-
if (adapter == null) {
125-
adapter = new ThinkDifferent(base);
126-
}
127-
application.addApplicationListener(adapter);
128-
application.setEnabledAboutMenu(true);
129-
application.setEnabledPreferencesMenu(true);
130-
}
131-
132-
133-
// Some of these are supposedly constants in com.apple.eio.FileManager,
134-
// however they don't seem to link properly from Eclipse.
135-
136-
static final int kDocumentsFolderType =
137-
('d' << 24) | ('o' << 16) | ('c' << 8) | 's';
138-
//static final int kPreferencesFolderType =
139-
// ('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
140-
static final int kDomainLibraryFolderType =
141-
('d' << 24) | ('l' << 16) | ('i' << 8) | 'b';
142-
static final short kUserDomain = -32763;
143-
144-
145-
// apple java extensions documentation
146-
// http://developer.apple.com/documentation/Java/Reference/1.5.0
147-
// /appledoc/api/com/apple/eio/FileManager.html
148-
149-
// carbon folder constants
150-
// http://developer.apple.com/documentation/Carbon/Reference
151-
// /Folder_Manager/folder_manager_ref/constant_6.html#/
152-
// /apple_ref/doc/uid/TP30000238/C006889
153-
154-
// additional information found int the local file:
155-
// /System/Library/Frameworks/CoreServices.framework
156-
// /Versions/Current/Frameworks/CarbonCore.framework/Headers/
157-
158-
159-
static public String getLibraryFolder() {
160-
try {
161-
return FileManager.findFolder(kUserDomain, kDomainLibraryFolderType);
162-
} catch (FileNotFoundException e) {
163-
e.printStackTrace();
164-
}
165-
return null;
166-
}
167-
168-
169-
static public String getDocumentsFolder() {
170-
try {
171-
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
172-
} catch (FileNotFoundException e) {
173-
e.printStackTrace();
174-
}
175-
return null;
176-
}
177123
}

0 commit comments

Comments
 (0)