From 05f3cb0b2d595bbd27a6810caae7b31972423e65 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 19 Jan 2020 20:50:04 -0500 Subject: [PATCH] move link() calls that use Desktop into PSurface --- core/src/processing/awt/ShimAWT.java | 18 ++++++++++++++++++ core/src/processing/core/PApplet.java | 17 +++-------------- core/src/processing/core/PSurface.java | 20 +++++++++++++++++--- core/src/processing/core/PSurfaceNone.java | 8 ++++++++ core/src/processing/javafx/PSurfaceFX.java | 10 +++++----- core/src/processing/opengl/PSurfaceJOGL.java | 5 +++++ core/todo.txt | 2 ++ 7 files changed, 58 insertions(+), 22 deletions(-) diff --git a/core/src/processing/awt/ShimAWT.java b/core/src/processing/awt/ShimAWT.java index 6c7c2003b..b37504226 100644 --- a/core/src/processing/awt/ShimAWT.java +++ b/core/src/processing/awt/ShimAWT.java @@ -1,5 +1,6 @@ package processing.awt; +import java.awt.Desktop; import java.awt.EventQueue; import java.awt.FileDialog; import java.awt.Frame; @@ -11,6 +12,8 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import javax.imageio.ImageIO; import javax.swing.ImageIcon; @@ -459,4 +462,19 @@ public class ShimAWT implements PConstants { static public File getWindowsDesktop() { return FileSystemView.getFileSystemView().getHomeDirectory(); } + + + static public boolean openLink(String url) { + try { + if (Desktop.isDesktopSupported()) { + Desktop.getDesktop().browse(new URI(url)); + return true; + } + } catch (IOException e) { + e.printStackTrace(); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + return false; + } } \ No newline at end of file diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 5e9a5664f..94d210f66 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -32,9 +32,6 @@ import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.geom.AffineTransform; -// used by link() -import java.awt.Desktop; - // loadXML() error handling import javax.xml.parsers.ParserConfigurationException; @@ -3271,17 +3268,9 @@ public class PApplet implements PConstants { * @param url the complete URL, as a String in quotes */ public void link(String url) { - try { - if (Desktop.isDesktopSupported()) { - Desktop.getDesktop().browse(new URI(url)); - } else { - // Just pass it off to open() and hope for the best - launch(url); - } - } catch (IOException e) { - printStackTrace(e); - } catch (URISyntaxException e) { - printStackTrace(e); + if (!surface.openLink(url)) { + // Just pass it off to launch() and hope for the best + launch(url); } } diff --git a/core/src/processing/core/PSurface.java b/core/src/processing/core/PSurface.java index 3c9b8eb68..9b380a0cf 100644 --- a/core/src/processing/core/PSurface.java +++ b/core/src/processing/core/PSurface.java @@ -35,6 +35,12 @@ public interface PSurface { static public final int MIN_WINDOW_WIDTH = 128; static public final int MIN_WINDOW_HEIGHT = 128; + //public int displayDensity(); + + //public int displayDensity(int display); + + // + // renderer that doesn't draw to the screen public void initOffscreen(PApplet sketch); @@ -47,9 +53,7 @@ public interface PSurface { // int deviceIndex, boolean fullScreen, boolean spanDisplays); public void initFrame(PApplet sketch); -// public int displayDensity(); - -// public int displayDensity(int display); + // public void selectInput(String prompt, String callback, File file, Object callbackObject); @@ -60,6 +64,8 @@ public interface PSurface { public void selectFolder(String prompt, String callback, File file, Object callbackObject); + // + /** * Get the native window object associated with this drawing surface. * For Java2D, this will be an AWT Frame object. For OpenGL, the window. @@ -153,6 +159,14 @@ public interface PSurface { // + /** + * @param url the link to open + * @return false if unable to find a viable way to open + */ + public boolean openLink(String url); + + // + /** Start the animation thread */ public void startThread(); diff --git a/core/src/processing/core/PSurfaceNone.java b/core/src/processing/core/PSurfaceNone.java index 5367c385f..f0934df81 100644 --- a/core/src/processing/core/PSurfaceNone.java +++ b/core/src/processing/core/PSurfaceNone.java @@ -204,6 +204,14 @@ public class PSurfaceNone implements PSurface { // + public boolean openLink(String url) { + return false; + } + + + // + + public Thread createThread() { return new AnimationThread(); } diff --git a/core/src/processing/javafx/PSurfaceFX.java b/core/src/processing/javafx/PSurfaceFX.java index 98f85ff1c..eb9514e5e 100644 --- a/core/src/processing/javafx/PSurfaceFX.java +++ b/core/src/processing/javafx/PSurfaceFX.java @@ -249,11 +249,6 @@ public class PSurfaceFX implements PSurface { } -// public Component initComponent(PApplet sketch) { -// return null; -// } - - static public class PApplicationFX extends Application { static public PSurfaceFX surface; // static String title; // title set at launch @@ -728,6 +723,11 @@ public class PSurfaceFX implements PSurface { } + public boolean openLink(String url) { + return ShimAWT.openLink(url); + } + + public void startThread() { animation.play(); } diff --git a/core/src/processing/opengl/PSurfaceJOGL.java b/core/src/processing/opengl/PSurfaceJOGL.java index b52a3882e..194bd4fdd 100644 --- a/core/src/processing/opengl/PSurfaceJOGL.java +++ b/core/src/processing/opengl/PSurfaceJOGL.java @@ -1395,4 +1395,9 @@ public class PSurfaceJOGL implements PSurface { } }); } + + + public boolean openLink(String url) { + return ShimAWT.openLink(url); + } } diff --git a/core/todo.txt b/core/todo.txt index 9188498b8..be2fd32c7 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -31,6 +31,8 @@ _ or even that it inits a surface-specific class for getting that info before final release _ implement selectInput/Output/Folder methods in PSurfaceJOGL _ implement selectInput/Output/Folder methods in PSurfaceFX +_ implement openLink() in PSurfaceFX +_ implement openLink() in PSurfaceJOGL _ Intel HD Graphics 3000 workaround is causing a big fat warning _ https://github.com/processing/processing4/issues/50 _ ThinkDifferent unavailable with --disable-awt, needs workaround