29
29
import processing .app .legacy .PConstants ;
30
30
31
31
import javax .swing .*;
32
- import java .io .*;
33
- import java .util .*;
32
+ import java .io .File ;
33
+ import java .io .IOException ;
34
+ import java .util .HashMap ;
35
+ import java .util .LinkedList ;
36
+ import java .util .List ;
37
+ import java .util .Map ;
34
38
35
39
import static processing .app .I18n ._ ;
36
40
37
41
38
42
/**
39
43
* Used by Base for platform-specific tweaking, for instance finding the
40
44
* sketchbook location using the Windows registry, or OS X event handling.
41
- *
42
- * The methods in this implementation are used by default, and can be
43
- * overridden by a subclass, if loaded by Base.main().
44
- *
45
+ * <p/>
46
+ * The methods in this implementation are used by default, and can be
47
+ * overridden by a subclass, if loaded by Base.main().
48
+ * <p/>
45
49
* These methods throw vanilla-flavored Exceptions, so that error handling
46
- * occurs inside Base.
47
- *
48
- * There is currently no mechanism for adding new platforms, as the setup is
49
- * not automated. We could use getProperty("os.arch") perhaps, but that's
50
- * debatable (could be upper/lowercase, have spaces, etc.. basically we don't
50
+ * occurs inside Base.
51
+ * <p/>
52
+ * There is currently no mechanism for adding new platforms, as the setup is
53
+ * not automated. We could use getProperty("os.arch") perhaps, but that's
54
+ * debatable (could be upper/lowercase, have spaces, etc.. basically we don't
51
55
* know if name is proper Java package syntax.)
52
56
*/
53
57
public class Platform {
54
-
55
-
58
+
59
+
56
60
/**
57
61
* Set the default L & F. While I enjoy the bounty of the sixteen possible
58
- * exception types that this UIManager method might throw, I feel that in
62
+ * exception types that this UIManager method might throw, I feel that in
59
63
* just this one particular case, I'm being spoiled by those engineers
60
64
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
61
65
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
62
66
* ways to report to the user exactly what went wrong, and I'll bundle them
63
- * all into a single catch-all "Exception". Because in the end, all I really
67
+ * all into a single catch-all "Exception". Because in the end, all I really
64
68
* care about is whether things worked or not. And even then, I don't care.
65
- *
69
+ *
66
70
* @throws Exception Just like I said.
67
71
*/
68
72
public void setLookAndFeel () throws Exception {
69
73
UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
70
74
}
71
-
72
-
75
+
76
+
73
77
public void init () throws IOException {
74
78
}
75
-
76
-
79
+
80
+
77
81
public File getSettingsFolder () throws Exception {
78
82
// otherwise make a .processing directory int the user's home dir
79
83
File home = new File (System .getProperty ("user.home" ));
@@ -95,37 +99,46 @@ public File getSettingsFolder() throws Exception {
95
99
}
96
100
*/
97
101
}
98
-
102
+
99
103
100
104
/**
101
- * @return null if not overridden, which will cause a prompt to show instead.
105
+ * @return null if not overridden, which will cause a prompt to show instead.
102
106
* @throws Exception
103
107
*/
104
108
public File getDefaultSketchbookFolder () throws Exception {
105
109
return null ;
106
110
}
107
-
108
-
111
+
112
+ public void openURL (File folder , String url ) throws Exception {
113
+ if (!url .startsWith ("file://./" )) {
114
+ openURL (url );
115
+ return ;
116
+ }
117
+
118
+ url = url .replaceAll ("file://./" , folder .getCanonicalFile ().toURI ().toASCIIString ());
119
+ openURL (url );
120
+ }
121
+
109
122
public void openURL (String url ) throws Exception {
110
123
String launcher = PreferencesData .get ("launcher" );
111
124
if (launcher != null ) {
112
- Runtime .getRuntime ().exec (new String [] { launcher , url });
125
+ Runtime .getRuntime ().exec (new String []{ launcher , url });
113
126
} else {
114
127
showLauncherWarning ();
115
- }
128
+ }
116
129
}
117
130
118
131
119
132
public boolean openFolderAvailable () {
120
133
return PreferencesData .get ("launcher" ) != null ;
121
134
}
122
-
123
-
135
+
136
+
124
137
public void openFolder (File file ) throws Exception {
125
138
String launcher = PreferencesData .get ("launcher" );
126
139
if (launcher != null ) {
127
140
String folder = file .getAbsolutePath ();
128
- Runtime .getRuntime ().exec (new String [] { launcher , folder });
141
+ Runtime .getRuntime ().exec (new String []{ launcher , folder });
129
142
} else {
130
143
showLauncherWarning ();
131
144
}
@@ -184,14 +197,14 @@ public String getName() {
184
197
return PConstants .platformNames [PConstants .OTHER ];
185
198
}
186
199
187
-
200
+
188
201
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
189
202
190
203
191
204
protected void showLauncherWarning () {
192
- BaseNoGui .showWarning (_ ("No launcher available" ),
193
- _ ("Unspecified platform, no launcher available.\n To enable opening URLs or folders, add a \n \" launcher=/path/to/app\" line to preferences.txt" ),
194
- null );
205
+ BaseNoGui .showWarning (_ ("No launcher available" ),
206
+ _ ("Unspecified platform, no launcher available.\n To enable opening URLs or folders, add a \n \" launcher=/path/to/app\" line to preferences.txt" ),
207
+ null );
195
208
}
196
209
197
210
public List <BoardPort > filterPorts (List <BoardPort > ports , boolean aBoolean ) {
0 commit comments