2929import processing .app .legacy .PConstants ;
3030
3131import 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 ;
3438
3539import static processing .app .I18n ._ ;
3640
3741
3842/**
3943 * Used by Base for platform-specific tweaking, for instance finding the
4044 * 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/>
4549 * 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
5155 * know if name is proper Java package syntax.)
5256 */
5357public class Platform {
54-
55-
58+
59+
5660 /**
5761 * 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
5963 * just this one particular case, I'm being spoiled by those engineers
6064 * at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
6165 * and overweight. So instead, I'll pretend that I'm not offered eleven dozen
6266 * 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
6468 * care about is whether things worked or not. And even then, I don't care.
65- *
69+ *
6670 * @throws Exception Just like I said.
6771 */
6872 public void setLookAndFeel () throws Exception {
6973 UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
7074 }
71-
72-
75+
76+
7377 public void init () throws IOException {
7478 }
75-
76-
79+
80+
7781 public File getSettingsFolder () throws Exception {
7882 // otherwise make a .processing directory int the user's home dir
7983 File home = new File (System .getProperty ("user.home" ));
@@ -95,37 +99,46 @@ public File getSettingsFolder() throws Exception {
9599 }
96100 */
97101 }
98-
102+
99103
100104 /**
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.
102106 * @throws Exception
103107 */
104108 public File getDefaultSketchbookFolder () throws Exception {
105109 return null ;
106110 }
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+
109122 public void openURL (String url ) throws Exception {
110123 String launcher = PreferencesData .get ("launcher" );
111124 if (launcher != null ) {
112- Runtime .getRuntime ().exec (new String [] { launcher , url });
125+ Runtime .getRuntime ().exec (new String []{ launcher , url });
113126 } else {
114127 showLauncherWarning ();
115- }
128+ }
116129 }
117130
118131
119132 public boolean openFolderAvailable () {
120133 return PreferencesData .get ("launcher" ) != null ;
121134 }
122-
123-
135+
136+
124137 public void openFolder (File file ) throws Exception {
125138 String launcher = PreferencesData .get ("launcher" );
126139 if (launcher != null ) {
127140 String folder = file .getAbsolutePath ();
128- Runtime .getRuntime ().exec (new String [] { launcher , folder });
141+ Runtime .getRuntime ().exec (new String []{ launcher , folder });
129142 } else {
130143 showLauncherWarning ();
131144 }
@@ -184,14 +197,14 @@ public String getName() {
184197 return PConstants .platformNames [PConstants .OTHER ];
185198 }
186199
187-
200+
188201 // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
189202
190203
191204 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 );
195208 }
196209
197210 public List <BoardPort > filterPorts (List <BoardPort > ports , boolean aBoolean ) {
0 commit comments