make the File > Examples link work

This commit is contained in:
Ben Fry
2022-08-09 06:29:58 -04:00
parent 87ff6227fe
commit f79e345957
+41 -17
View File
@@ -35,10 +35,8 @@ import javax.swing.JComponent;
import javax.swing.border.EmptyBorder;
import processing.app.Base;
import processing.app.Language;
import processing.app.Platform;
import processing.app.Preferences;
import processing.awt.ShimAWT;
public class Welcome {
@@ -74,6 +72,9 @@ public class Welcome {
button.addActionListener(e -> view.handleClose());
panel.add(button);
File indexFile = getIndexFile();
if (indexFile == null) return; // giving up; error already printed
view = new WebFrame(getIndexFile(), 420, panel) {
/*
@Override
@@ -97,15 +98,40 @@ public class Welcome {
@Override
public void handleLink(String link) {
// The link will already have the full URL prefix
/*
if (link.endsWith("#sketchbook")) {
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
ShimAWT.selectFolder(Language.text("preferences.sketchbook_location.popup"),
"sketchbookCallback", folder, this);
*/
if (link.endsWith("#examples")) {
base.getDefaultMode().showExamplesFrame();
} else if (link.endsWith("#mouse")) {
openExample("Basics/Input/Mouse2D/Mouse2D.pde");
} else if (link.endsWith("#arctan")) {
openExample("Basics/Math/Arctangent/Arctangent.pde");
} else if (link.endsWith("#flocking")) {
openExample("Topics/Simulate/Flocking/Flocking.pde");
} else if (link.endsWith("#rotating")) {
openExample("Demos/Graphics/RotatingArcs/RotatingArcs.pde");
} else {
super.handleLink(link);
}
}
private void openExample(String examplePath) {
File examplesFolder =
Platform.getContentFile("modes/java/examples");
File pdeFile = new File(examplesFolder, examplePath);
base.handleOpen(pdeFile.getAbsolutePath());
}
@Override
public void handleClose() {
Preferences.setBoolean("welcome.four.seen", true);
@@ -117,14 +143,14 @@ public class Welcome {
}
/** Callback for the folder selector. */
public void sketchbookCallback(File folder) {
if (folder != null) {
if (base != null) {
base.setSketchbookFolder(folder);
}
}
}
// /** Callback for the folder selector. */
// public void sketchbookCallback(File folder) {
// if (folder != null) {
// if (base != null) {
// base.setSketchbookFolder(folder);
// }
// }
// }
static private File getIndexFile() {
@@ -163,13 +189,11 @@ public class Welcome {
}
Preferences.init();
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
new Welcome(null);
} catch (IOException e) {
e.printStackTrace();
}
EventQueue.invokeLater(() -> {
try {
new Welcome(null);
} catch (IOException e) {
e.printStackTrace();
}
});
}