Skip to content

Commit 05cc64d

Browse files
committed
switch to java.awt.Desktop methods in platform, other post-applet updates
1 parent 340383e commit 05cc64d

File tree

11 files changed

+274
-226
lines changed

11 files changed

+274
-226
lines changed

android/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
0207 android
2+
_ Support Native Code in Libraries for Android (includes fix)
3+
_ http://code.google.com/p/processing/issues/detail?id=1117
24

35

46
_ no ES2 in the emulator, and no error reported in the PDE

app/src/processing/app/Base.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ public boolean accept(File dir, String name) {
940940

941941
fc.setFileFilter(new javax.swing.filechooser.FileFilter() {
942942
public boolean accept(File file) {
943+
// JFileChooser requires you to explicitly say yes to directories
944+
// as well (unlike the AWT chooser). Useful, but... different.
945+
// http://code.google.com/p/processing/issues/detail?id=1151
946+
if (file.isDirectory()) {
947+
return true;
948+
}
943949
for (String ext : extensions) {
944950
if (file.getName().toLowerCase().endsWith("." + ext)) {
945951
return true;
@@ -1981,11 +1987,10 @@ static protected File getDefaultSketchbookFolder() {
19811987

19821988

19831989
/**
1984-
* Implements the cross-platform headache of opening URLs
1985-
* TODO This code should be replaced by PApplet.link(),
1986-
* however that's not a static method (because it requires
1987-
* an AppletContext when used as an applet), so it's mildly
1988-
* trickier than just removing this method.
1990+
* Implements the cross-platform headache of opening URLs. For 2.0, this
1991+
* requires the parameter to be an actual URL, meaning that you can't send
1992+
* it a file:// path without a prefix. It also just calls into Platform,
1993+
* which now uses java.awt.Desktop because we're requiring Java 6.
19891994
*/
19901995
static public void openURL(String url) {
19911996
try {

app/src/processing/app/Editor.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void windowDeactivated(WindowEvent e) {
178178
header = new EditorHeader(this);
179179
upper.add(header);
180180

181-
textarea = new JEditTextArea(new PdeTextAreaDefaults(mode));
181+
textarea = createTextArea();
182182
textarea.setRightClickPopup(new TextAreaPopup());
183183
textarea.setHorizontalOffset(JEditTextArea.leftHandGutter);
184184

@@ -280,6 +280,15 @@ public void windowGainedFocus(WindowEvent e) {
280280
}
281281

282282

283+
/**
284+
* Broken out to get modes working for GSOC, but this needs a longer-term
285+
* solution where the listeners are handled properly.
286+
*/
287+
protected JEditTextArea createTextArea() {
288+
return new JEditTextArea(new PdeTextAreaDefaults(mode));
289+
}
290+
291+
283292
public EditorState getEditorState() {
284293
return state;
285294
}
@@ -1072,7 +1081,7 @@ public void showReference(String filename) {
10721081
// File referenceFile = new File(referenceFolder, filename);
10731082
// Base.openURL(referenceFile.getAbsolutePath());
10741083
File file = new File(mode.getReferenceFolder(), filename);
1075-
Base.openURL(file.getAbsolutePath());
1084+
Base.openURL("file://" + file.getAbsolutePath());
10761085
}
10771086

10781087

app/src/processing/app/Platform.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
package processing.app;
2424

25+
import java.awt.Desktop;
2526
import java.io.File;
27+
import java.net.URI;
2628

2729
import javax.swing.UIManager;
2830

@@ -74,8 +76,7 @@ public void init(Base base) {
7476
public File getSettingsFolder() throws Exception {
7577
// otherwise make a .processing directory int the user's home dir
7678
File home = new File(System.getProperty("user.home"));
77-
File dataFolder = new File(home, ".processing");
78-
return dataFolder;
79+
return new File(home, ".processing");
7980

8081
/*
8182
try {
@@ -95,37 +96,46 @@ public File getSettingsFolder() throws Exception {
9596

9697

9798
/**
98-
* @return null if not overridden, which will cause a prompt to show instead.
99-
* @throws Exception
99+
* @return if not overridden, a folder named "sketchbook" in user.dir.
100+
* @throws Exception so that subclasses can throw a fit
100101
*/
101102
public File getDefaultSketchbookFolder() throws Exception {
102103
return new File(System.getProperty("user.dir"), "sketchbook");
103104
}
104105

105106

106107
public void openURL(String url) throws Exception {
108+
Desktop.getDesktop().browse(new URI(url));
109+
/*
107110
String launcher = Preferences.get("launcher");
108111
if (launcher != null) {
109112
Runtime.getRuntime().exec(new String[] { launcher, url });
110113
} else {
111114
showLauncherWarning();
112115
}
116+
*/
113117
}
114118

115119

116120
public boolean openFolderAvailable() {
121+
return Desktop.isDesktopSupported();
122+
/*
117123
return Preferences.get("launcher") != null;
124+
*/
118125
}
119126

120127

121128
public void openFolder(File file) throws Exception {
129+
Desktop.getDesktop().open(file);
130+
/*
122131
String launcher = Preferences.get("launcher");
123132
if (launcher != null) {
124133
String folder = file.getAbsolutePath();
125134
Runtime.getRuntime().exec(new String[] { launcher, folder });
126135
} else {
127136
showLauncherWarning();
128137
}
138+
*/
129139
}
130140

131141

@@ -162,11 +172,13 @@ public int unsetenv(String variable) {
162172
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
163173

164174

175+
/*
165176
protected void showLauncherWarning() {
166177
Base.showWarning("No launcher available",
167178
"Unspecified platform, no launcher available.\n" +
168179
"To enable opening URLs or folders, add a \n" +
169180
"\"launcher=/path/to/app\" line to preferences.txt",
170181
null);
171182
}
183+
*/
172184
}

app/src/processing/app/linux/Platform.java

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@
2222

2323
package processing.app.linux;
2424

25-
import java.io.File;
26-
2725
import javax.swing.UIManager;
2826

2927
import processing.app.Base;
30-
import processing.app.Preferences;
3128

3229

3330
public class Platform extends processing.app.Platform {
@@ -68,64 +65,64 @@ public void setLookAndFeel() throws Exception {
6865
}
6966

7067

71-
public void openURL(String url) throws Exception {
72-
if (openFolderAvailable()) {
73-
String launcher = Preferences.get("launcher");
74-
if (launcher != null) {
75-
Runtime.getRuntime().exec(new String[] { launcher, url });
76-
}
77-
}
78-
}
79-
80-
81-
public boolean openFolderAvailable() {
82-
if (Preferences.get("launcher") != null) {
83-
return true;
84-
}
85-
86-
// Attempt to use xdg-open
87-
try {
88-
Process p = Runtime.getRuntime().exec(new String[] { "xdg-open" });
89-
p.waitFor();
90-
Preferences.set("launcher", "xdg-open");
91-
return true;
92-
} catch (Exception e) { }
93-
94-
// Attempt to use gnome-open
95-
try {
96-
Process p = Runtime.getRuntime().exec(new String[] { "gnome-open" });
97-
p.waitFor();
98-
// Not installed will throw an IOException (JDK 1.4.2, Ubuntu 7.04)
99-
Preferences.set("launcher", "gnome-open");
100-
return true;
101-
} catch (Exception e) { }
102-
103-
// Attempt with kde-open
104-
try {
105-
Process p = Runtime.getRuntime().exec(new String[] { "kde-open" });
106-
p.waitFor();
107-
Preferences.set("launcher", "kde-open");
108-
return true;
109-
} catch (Exception e) { }
110-
111-
return false;
112-
}
113-
114-
115-
public void openFolder(File file) throws Exception {
116-
if (openFolderAvailable()) {
117-
String lunch = Preferences.get("launcher");
118-
try {
119-
String[] params = new String[] { lunch, file.getAbsolutePath() };
120-
//processing.core.PApplet.println(params);
121-
/*Process p =*/ Runtime.getRuntime().exec(params);
122-
/*int result =*/ //p.waitFor();
123-
} catch (Exception e) {
124-
e.printStackTrace();
125-
}
126-
} else {
127-
System.out.println("No launcher set, cannot open " +
128-
file.getAbsolutePath());
129-
}
130-
}
68+
// public void openURL(String url) throws Exception {
69+
// if (openFolderAvailable()) {
70+
// String launcher = Preferences.get("launcher");
71+
// if (launcher != null) {
72+
// Runtime.getRuntime().exec(new String[] { launcher, url });
73+
// }
74+
// }
75+
// }
76+
//
77+
//
78+
// public boolean openFolderAvailable() {
79+
// if (Preferences.get("launcher") != null) {
80+
// return true;
81+
// }
82+
//
83+
// // Attempt to use xdg-open
84+
// try {
85+
// Process p = Runtime.getRuntime().exec(new String[] { "xdg-open" });
86+
// p.waitFor();
87+
// Preferences.set("launcher", "xdg-open");
88+
// return true;
89+
// } catch (Exception e) { }
90+
//
91+
// // Attempt to use gnome-open
92+
// try {
93+
// Process p = Runtime.getRuntime().exec(new String[] { "gnome-open" });
94+
// p.waitFor();
95+
// // Not installed will throw an IOException (JDK 1.4.2, Ubuntu 7.04)
96+
// Preferences.set("launcher", "gnome-open");
97+
// return true;
98+
// } catch (Exception e) { }
99+
//
100+
// // Attempt with kde-open
101+
// try {
102+
// Process p = Runtime.getRuntime().exec(new String[] { "kde-open" });
103+
// p.waitFor();
104+
// Preferences.set("launcher", "kde-open");
105+
// return true;
106+
// } catch (Exception e) { }
107+
//
108+
// return false;
109+
// }
110+
//
111+
//
112+
// public void openFolder(File file) throws Exception {
113+
// if (openFolderAvailable()) {
114+
// String lunch = Preferences.get("launcher");
115+
// try {
116+
// String[] params = new String[] { lunch, file.getAbsolutePath() };
117+
// //processing.core.PApplet.println(params);
118+
// /*Process p =*/ Runtime.getRuntime().exec(params);
119+
// /*int result =*/ //p.waitFor();
120+
// } catch (Exception e) {
121+
// e.printStackTrace();
122+
// }
123+
// } else {
124+
// System.out.println("No launcher set, cannot open " +
125+
// file.getAbsolutePath());
126+
// }
127+
// }
131128
}

app/src/processing/app/macosx/Platform.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@
2525
import java.awt.Insets;
2626
import java.io.File;
2727
import java.io.FileNotFoundException;
28-
import java.lang.reflect.Method;
29-
import java.net.URI;
3028

3129
import javax.swing.UIManager;
3230

3331
import com.apple.eio.FileManager;
3432

3533
import processing.app.Base;
36-
import processing.core.PApplet;
3734

3835

3936
/**
@@ -106,6 +103,7 @@ public File getDefaultSketchbookFolder() throws Exception {
106103
}
107104

108105

106+
/*
109107
public void openURL(String url) throws Exception {
110108
if (PApplet.javaVersion < 1.6f) {
111109
if (url.startsWith("http://")) {
@@ -130,7 +128,7 @@ public void openURL(String url) throws Exception {
130128
Method getMethod = desktopClass.getMethod("getDesktop");
131129
Object desktop = getMethod.invoke(null, new Object[] { });
132130
133-
// for Java 1.6, replacing with java.awt.Desktop.browse()
131+
// for Java 1.6, replacing with java.awt.Desktop.browse()
134132
// and java.awt.Desktop.open()
135133
if (url.startsWith("http://")) { // browse to a location
136134
Method browseMethod =
@@ -157,6 +155,7 @@ public void openFolder(File file) throws Exception {
157155
//openURL(file.getAbsolutePath()); // handles char replacement, etc
158156
processing.core.PApplet.open(file.getAbsolutePath());
159157
}
158+
*/
160159

161160

162161
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

app/src/processing/app/windows/Platform.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public File getDefaultSketchbookFolder() throws Exception {
314314
}
315315

316316

317+
/*
317318
public void openURL(String url) throws Exception {
318319
// this is not guaranteed to work, because who knows if the
319320
// path will always be c:\progra~1 et al. also if the user has
@@ -362,6 +363,7 @@ public void openFolder(File file) throws Exception {
362363
// not tested
363364
//Runtime.getRuntime().exec("start explorer \"" + folder + "\"");
364365
}
366+
*/
365367

366368

367369
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

app/src/processing/mode/android/AndroidEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) {
246246
public void showReference(String filename) {
247247
File javaReferenceFolder = Base.getContentFile("modes/java/reference");
248248
File file = new File(javaReferenceFolder, filename);
249-
Base.openURL(file.getAbsolutePath());
249+
Base.openURL("file://" + file.getAbsolutePath());
250250
}
251251

252252

0 commit comments

Comments
 (0)