GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — implement download option for offline reference · D-I-R-M/processing4@143fcfd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • build/shared/lib/languages
    • PDE.properties
  • java/src/processing/mode/java
    • JavaEditor.java
  • todo.txt
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎build/shared/lib/languages/PDE.properties‎

Copy file name to clipboardExpand all lines: build/shared/lib/languages/PDE.properties
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ menu.help.about = About Processing
138138
menu.help.environment = Environment
139139
menu.help.reference = Reference
140140
menu.help.find_in_reference = Find in Reference
141+
menu.help.reference.download = Download Offline Reference
141142
menu.help.libraries_reference = Libraries Reference
142143
menu.help.tools_reference = Tools Reference
143144
menu.help.empty = (empty)
Collapse file

‎java/src/processing/mode/java/JavaEditor.java‎

Copy file name to clipboardExpand all lines: java/src/processing/mode/java/JavaEditor.java
+63-5Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.awt.*;
2727
import java.awt.event.*;
2828
import java.io.*;
29+
import java.net.HttpURLConnection;
30+
import java.net.URL;
2931
import java.util.ArrayList;
3032
import java.util.List;
3133
import java.util.Map;
@@ -90,6 +92,9 @@ public class JavaEditor extends Editor {
9092

9193
/** P5 in decimal; if there are complaints, move to preferences.txt */
9294
static final int REFERENCE_PORT = 8053;
95+
// weird to link to a specific location like this, but it's versioned, so:
96+
static final String REFERENCE_URL =
97+
"https://github.com/processing/processing-website/releases/download/2022-10-05-1459/reference.zip";
9398
Boolean useReferenceServer;
9499
WebServer referenceServer;
95100

@@ -284,7 +289,6 @@ public JMenu buildHelpMenu() {
284289
item.addActionListener(e -> {
285290
try {
286291
new Welcome(base);
287-
//new Welcome(base, Preferences.getSketchbookPath().equals(Preferences.getOldSketchbookPath()));
288292
} catch (IOException ioe) {
289293
Messages.showWarning("Unwelcome Error",
290294
"Please report this error to\n" +
@@ -294,13 +298,11 @@ public JMenu buildHelpMenu() {
294298
menu.add(item);
295299

296300
item = new JMenuItem(Language.text("menu.help.environment"));
297-
//item.addActionListener(e -> showReference("environment/index.html"));
298-
item.addActionListener(e -> Platform.openURL("https://processing.org/environment/"));
301+
item.addActionListener(e -> showReference("../environment/index.html"));
299302
menu.add(item);
300303

301304
item = new JMenuItem(Language.text("menu.help.reference"));
302-
//item.addActionListener(e -> showReference("index.html"));
303-
item.addActionListener(e -> Platform.openURL("https://processing.org/reference/"));
305+
item.addActionListener(e -> showReference("index.html"));
304306
menu.add(item);
305307

306308
item = Toolkit.newJMenuItemShift(Language.text("menu.help.find_in_reference"), 'F');
@@ -313,6 +315,15 @@ public JMenu buildHelpMenu() {
313315
});
314316
menu.add(item);
315317

318+
// Not gonna use "update" since it's more about re-downloading:
319+
// it doesn't make sense to "update" the reference because it's
320+
// specific to a version of the software anyway. [fry 221125]
321+
// item = new JMenuItem(isReferenceDownloaded() ?
322+
// "menu.help.reference.update" : "menu.help.reference.download");
323+
item = new JMenuItem("menu.help.reference.download");
324+
item.addActionListener(e -> new Thread(this::downloadReference).start());
325+
menu.add(item);
326+
316327
menu.addSeparator();
317328

318329
final JMenu libRefSubmenu = new JMenu(Language.text("menu.help.libraries_reference"));
@@ -783,7 +794,15 @@ public void changedUpdate(DocumentEvent e) {
783794

784795
public void showReference(String name) {
785796
if (useReferenceServer == null) {
797+
// Because of this, it should be possible to create your own dist
798+
// that includes the reference by simply adding it to modes/java.
786799
File referenceZip = new File(mode.getFolder(), "reference.zip");
800+
if (!referenceZip.exists()) {
801+
// For Java Mode (the default), check for a reference.zip in the root
802+
// of the sketchbook folder. If other Modes subclass JavaEditor and
803+
// don't override this function, it may cause a little trouble.
804+
referenceZip = getOfflineReferenceFile();
805+
}
787806
if (referenceZip.exists()) {
788807
try {
789808
referenceServer = new WebServer(referenceZip, REFERENCE_PORT);
@@ -815,6 +834,45 @@ public void showReference(String name) {
815834
}
816835

817836

837+
private File getOfflineReferenceFile() {
838+
return new File(Base.getSketchbookFolder(), "reference.zip");
839+
}
840+
841+
842+
/*
843+
private boolean isReferenceDownloaded() {
844+
return getOfflineReferenceFile().exists();
845+
}
846+
*/
847+
848+
849+
private void downloadReference() {
850+
try {
851+
URL source = new URL(REFERENCE_URL);
852+
HttpURLConnection conn = (HttpURLConnection) source.openConnection();
853+
HttpURLConnection.setFollowRedirects(true);
854+
conn.setConnectTimeout(15 * 1000);
855+
conn.setReadTimeout(60 * 1000);
856+
conn.setRequestMethod("GET");
857+
conn.connect();
858+
859+
ProgressMonitorInputStream input =
860+
new ProgressMonitorInputStream(this,
861+
"Downloading reference…", conn.getInputStream());
862+
input.getProgressMonitor().setMaximum(conn.getContentLength());
863+
PApplet.saveStream(getOfflineReferenceFile(), input);
864+
useReferenceServer = null;
865+
866+
} catch (InterruptedIOException iioe) {
867+
// download canceled
868+
869+
} catch (IOException e) {
870+
Messages.showWarning("Error downloading reference",
871+
"Could not download the reference. Try again later.", e);
872+
}
873+
}
874+
875+
818876
public void statusError(String what) {
819877
super.statusError(what);
820878
// new Exception("deactivating RUN").printStackTrace();
Collapse file

‎todo.txt‎

Copy file name to clipboardExpand all lines: todo.txt
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ X https://github.com/processing/processing4/issues/600
99
_ update wiki
1010
_ https://github.com/processing/processing4/wiki/Translations
1111
_ https://www.oracle.com/java/technologies/javase/jdk17-suported-locales.html
12+
X implement offline reference download
13+
X https://github.com/processing/processing-website/releases/download/2022-10-05-1459/reference.zip
14+
_ add a note about the file size to the progress window
15+
_ document and grab other notes from elsewhere here
1216

1317

1418
_ "Show Sketch Folder" for libraries needs to treat the sketch as Untitled

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.