move link() calls that use Desktop into PSurface

This commit is contained in:
Ben Fry
2020-01-19 20:50:04 -05:00
parent b27d971aca
commit 05f3cb0b2d
7 changed files with 58 additions and 22 deletions
+18
View File
@@ -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;
}
}
+3 -14
View File
@@ -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);
}
}
+17 -3
View File
@@ -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();
@@ -204,6 +204,14 @@ public class PSurfaceNone implements PSurface {
//
public boolean openLink(String url) {
return false;
}
//
public Thread createThread() {
return new AnimationThread();
}
+5 -5
View File
@@ -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();
}
@@ -1395,4 +1395,9 @@ public class PSurfaceJOGL implements PSurface {
}
});
}
public boolean openLink(String url) {
return ShimAWT.openLink(url);
}
}
+2
View File
@@ -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