Skip to content

Commit 05f3cb0

Browse files
committed
move link() calls that use Desktop into PSurface
1 parent b27d971 commit 05f3cb0

File tree

7 files changed

+58
-22
lines changed

7 files changed

+58
-22
lines changed

core/src/processing/awt/ShimAWT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package processing.awt;
22

3+
import java.awt.Desktop;
34
import java.awt.EventQueue;
45
import java.awt.FileDialog;
56
import java.awt.Frame;
@@ -11,6 +12,8 @@
1112
import java.io.File;
1213
import java.io.IOException;
1314
import java.io.InputStream;
15+
import java.net.URI;
16+
import java.net.URISyntaxException;
1417

1518
import javax.imageio.ImageIO;
1619
import javax.swing.ImageIcon;
@@ -459,4 +462,19 @@ static private void checkLookAndFeel() {
459462
static public File getWindowsDesktop() {
460463
return FileSystemView.getFileSystemView().getHomeDirectory();
461464
}
465+
466+
467+
static public boolean openLink(String url) {
468+
try {
469+
if (Desktop.isDesktopSupported()) {
470+
Desktop.getDesktop().browse(new URI(url));
471+
return true;
472+
}
473+
} catch (IOException e) {
474+
e.printStackTrace();
475+
} catch (URISyntaxException e) {
476+
e.printStackTrace();
477+
}
478+
return false;
479+
}
462480
}

core/src/processing/core/PApplet.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
import java.awt.GraphicsEnvironment;
3333
import java.awt.geom.AffineTransform;
3434

35-
// used by link()
36-
import java.awt.Desktop;
37-
3835
// loadXML() error handling
3936
import javax.xml.parsers.ParserConfigurationException;
4037

@@ -3271,17 +3268,9 @@ public void frameRate(float fps) {
32713268
* @param url the complete URL, as a String in quotes
32723269
*/
32733270
public void link(String url) {
3274-
try {
3275-
if (Desktop.isDesktopSupported()) {
3276-
Desktop.getDesktop().browse(new URI(url));
3277-
} else {
3278-
// Just pass it off to open() and hope for the best
3279-
launch(url);
3280-
}
3281-
} catch (IOException e) {
3282-
printStackTrace(e);
3283-
} catch (URISyntaxException e) {
3284-
printStackTrace(e);
3271+
if (!surface.openLink(url)) {
3272+
// Just pass it off to launch() and hope for the best
3273+
launch(url);
32853274
}
32863275
}
32873276

core/src/processing/core/PSurface.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public interface PSurface {
3535
static public final int MIN_WINDOW_WIDTH = 128;
3636
static public final int MIN_WINDOW_HEIGHT = 128;
3737

38+
//public int displayDensity();
39+
40+
//public int displayDensity(int display);
41+
42+
//
43+
3844
// renderer that doesn't draw to the screen
3945
public void initOffscreen(PApplet sketch);
4046

@@ -47,9 +53,7 @@ public interface PSurface {
4753
// int deviceIndex, boolean fullScreen, boolean spanDisplays);
4854
public void initFrame(PApplet sketch);
4955

50-
// public int displayDensity();
51-
52-
// public int displayDensity(int display);
56+
//
5357

5458
public void selectInput(String prompt, String callback,
5559
File file, Object callbackObject);
@@ -60,6 +64,8 @@ public void selectOutput(String prompt, String callback,
6064
public void selectFolder(String prompt, String callback,
6165
File file, Object callbackObject);
6266

67+
//
68+
6369
/**
6470
* Get the native window object associated with this drawing surface.
6571
* For Java2D, this will be an AWT Frame object. For OpenGL, the window.
@@ -153,6 +159,14 @@ public void selectFolder(String prompt, String callback,
153159

154160
//
155161

162+
/**
163+
* @param url the link to open
164+
* @return false if unable to find a viable way to open
165+
*/
166+
public boolean openLink(String url);
167+
168+
//
169+
156170
/** Start the animation thread */
157171
public void startThread();
158172

core/src/processing/core/PSurfaceNone.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ public void hideCursor() { }
204204
//
205205

206206

207+
public boolean openLink(String url) {
208+
return false;
209+
}
210+
211+
212+
//
213+
214+
207215
public Thread createThread() {
208216
return new AnimationThread();
209217
}

core/src/processing/javafx/PSurfaceFX.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,6 @@ public void initOffscreen(PApplet sketch) {
249249
}
250250

251251

252-
// public Component initComponent(PApplet sketch) {
253-
// return null;
254-
// }
255-
256-
257252
static public class PApplicationFX extends Application {
258253
static public PSurfaceFX surface;
259254
// static String title; // title set at launch
@@ -728,6 +723,11 @@ public void hideCursor() {
728723
}
729724

730725

726+
public boolean openLink(String url) {
727+
return ShimAWT.openLink(url);
728+
}
729+
730+
731731
public void startThread() {
732732
animation.play();
733733
}

core/src/processing/opengl/PSurfaceJOGL.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,4 +1395,9 @@ public void run() {
13951395
}
13961396
});
13971397
}
1398+
1399+
1400+
public boolean openLink(String url) {
1401+
return ShimAWT.openLink(url);
1402+
}
13981403
}

core/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ _ or even that it inits a surface-specific class for getting that info
3131
before final release
3232
_ implement selectInput/Output/Folder methods in PSurfaceJOGL
3333
_ implement selectInput/Output/Folder methods in PSurfaceFX
34+
_ implement openLink() in PSurfaceFX
35+
_ implement openLink() in PSurfaceJOGL
3436
_ Intel HD Graphics 3000 workaround is causing a big fat warning
3537
_ https://github.com/processing/processing4/issues/50
3638
_ ThinkDifferent unavailable with --disable-awt, needs workaround

0 commit comments

Comments
 (0)