Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 43 additions & 40 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ static private void createAndShowGUI(String[] args) {
// t6 = System.currentTimeMillis();

// Prevent more than one copy of the PDE from running.
SingleInstance.startServer(base);
new Thread(() -> { SingleInstance.startServer(base); } ).start();

handleWelcomeScreen(base);
handleCrustyDisplay();
Expand Down Expand Up @@ -485,20 +485,26 @@ static public boolean isCommandLine() {

public Base(String[] args) throws Exception {
long t1 = System.currentTimeMillis();
ContributionManager.init(this);
new Thread(() -> {
try {
ContributionManager.init(this);
} catch (Exception e) {
throw new RuntimeException(e);
}
}).start();

long t2 = System.currentTimeMillis();
buildCoreModes();
long t2b = System.currentTimeMillis();
rebuildContribModes();
new Thread(this::rebuildContribModes).start();
long t2c = System.currentTimeMillis();
rebuildContribExamples();

long t3 = System.currentTimeMillis();
// Needs to happen after the sketchbook folder has been located.
// Also relies on the modes to be loaded, so it knows what can be
// marked as an example.
Recent.init(this);
new Thread(() -> { Recent.init(this); }).start();

long t4 = System.currentTimeMillis();
String lastModeIdentifier = Preferences.get("mode.last"); //$NON-NLS-1$
Expand All @@ -523,7 +529,7 @@ public Base(String[] args) throws Exception {
long t5 = System.currentTimeMillis();

// Make sure ThinkDifferent has library examples too
nextMode.rebuildLibraryList();
// nextMode.rebuildLibraryList();

// Put this after loading the examples, so that building the default file
// menu works on Mac OS X (since it needs examplesFolder to be set).
Expand Down Expand Up @@ -863,7 +869,7 @@ public List<ToolContribution> getContribTools() {
return contribTools;
}


private List<Tool> toolsToInit = new ArrayList<>();
public void rebuildToolList() {
// Only do these once because the list of internal tools will never change
if (internalTools == null) {
Expand All @@ -883,43 +889,12 @@ public void rebuildToolList() {
// Only init() these the first time they're loaded
if (coreTools == null) {
coreTools = ToolContribution.loadAll(Base.getToolsFolder());
for (Tool tool : coreTools) {
tool.init(this);
}
toolsToInit.addAll(coreTools);
}

// Reset the contributed tools and re-init() all of them.
contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder());
for (Tool tool : contribTools) {
try {
tool.init(this);

// With the exceptions, we can't call statusError because the window
// isn't completely set up yet. Also not gonna pop up a warning because
// people may still be running different versions of Processing.

} catch (VerifyError | AbstractMethodError ve) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
Messages.err("Incompatible Tool found during tool.init()", ve);

} catch (NoSuchMethodError nsme) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + nsme.getMessage() + " method no longer exists.");
Messages.err("Incompatible Tool found during tool.init()", nsme);

} catch (NoClassDefFoundError ncdfe) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + ncdfe.getMessage() + " class is no longer available.");
Messages.err("Incompatible Tool found during tool.init()", ncdfe);

} catch (Error | Exception e) {
System.err.println("An error occurred inside \"" + tool.getMenuTitle() + "\"");
e.printStackTrace();
}
}
toolsToInit.addAll(contribTools);
}


Expand All @@ -928,7 +903,7 @@ protected void initInternalTool(Class<?> toolClass) {
final Tool tool = (Tool)
toolClass.getDeclaredConstructor().newInstance();

tool.init(this);
toolsToInit.add(tool);
internalTools.add(tool);

} catch (Exception e) {
Expand Down Expand Up @@ -976,12 +951,40 @@ public void populateToolsMenu(JMenu toolsMenu) {
toolsMenu.add(manageTools);
}

void initTool(Tool tool) {
if(!toolsToInit.contains(tool)) {return;}
try {
tool.init(this);
toolsToInit.remove(tool);
} catch (VerifyError | AbstractMethodError ve) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
Messages.err("Incompatible Tool found during tool.init()", ve);

} catch (NoSuchMethodError nsme) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + nsme.getMessage() + " method no longer exists.");
Messages.err("Incompatible Tool found during tool.init()", nsme);

} catch (NoClassDefFoundError ncdfe) {
System.err.println("\"" + tool.getMenuTitle() + "\" is not " +
"compatible with this version of Processing");
System.err.println("The " + ncdfe.getMessage() + " class is no longer available.");
Messages.err("Incompatible Tool found during tool.init()", ncdfe);

} catch (Error | Exception e) {
System.err.println("An error occurred inside \"" + tool.getMenuTitle() + "\"");
e.printStackTrace();
}
}

JMenuItem createToolItem(final Tool tool) { //, Map<String, JMenuItem> toolItems) {
String title = tool.getMenuTitle();
final JMenuItem item = new JMenuItem(title);
item.addActionListener(e -> {
try {
initTool(tool);
tool.run();

} catch (NoSuchMethodError | NoClassDefFoundError ne) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/Processing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Processing: SuspendingCliktCommand("processing"){

val subcommand = currentContext.invokedSubcommand
if (subcommand == null) {
Start.main(sketches.toTypedArray())
Base.main(sketches.toTypedArray())
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions app/src/processing/app/platform/DefaultPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.awt.Font;
import java.io.File;

import javax.swing.UIManager;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

import com.formdev.flatlaf.FlatLaf;
Expand Down Expand Up @@ -115,18 +115,29 @@ public void setLookAndFeel() throws Exception {
// (i.e. Nimbus on Linux) with our custom components is badness.

// dummy font call so that it's registered for FlatLaf
Font defaultFont = Toolkit.getSansFont(14, Font.PLAIN);
UIManager.put("defaultFont", defaultFont);
new Thread(() -> {
Font defaultFont = Toolkit.getSansFont(14, Font.PLAIN);
UIManager.put("defaultFont", defaultFont);
}).start();


// pull in FlatLaf.properties from the processing.app.laf folder
FlatLaf.registerCustomDefaultsSource("processing.app.laf");

// start with Light, but updateTheme() will be called soon
UIManager.setLookAndFeel(new FlatLightLaf());
new Thread(() -> {
// start with Light, but updateTheme() will be called soon
try {
UIManager.setLookAndFeel(new FlatLightLaf());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
}).start();

// Does not fully remove the gray hairline (probably from a parent
// Window object), but is an improvement from the heavier default.
UIManager.put("ToolTip.border", new EmptyBorder(0, 0, 0, 0));
new Thread(() -> {
UIManager.put("ToolTip.border", new EmptyBorder(0, 0, 0, 0));
}).start();

/*
javax.swing.UIDefaults defaults = UIManager.getDefaults();
Expand Down
2 changes: 1 addition & 1 deletion app/src/processing/app/ui/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void windowDeactivated(WindowEvent e) {

timer = new Timer();

buildMenuBar();
new Thread(this::buildMenuBar).start();

JPanel contentPain = new JPanel();
setContentPane(contentPain);
Expand Down
40 changes: 33 additions & 7 deletions app/src/processing/app/ui/Toolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

import javax.imageio.ImageIO;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
Expand All @@ -68,14 +71,12 @@
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;

import processing.app.Language;
import processing.app.Messages;
import processing.app.Platform;
import processing.app.Preferences;
import processing.app.Util;
import processing.app.*;
import processing.awt.PGraphicsJava2D;
import processing.awt.PShapeJava2D;
import processing.awt.ShimAWT;
import processing.core.PApplet;
import processing.core.PImage;
import processing.core.PShape;
import processing.data.StringDict;
import processing.data.StringList;
Expand Down Expand Up @@ -794,6 +795,7 @@ static private Image svgToImageMult(String xmlStr, int wide, int high) {
*/



static public Image svgToImageMult(String xmlStr, int wide, int high, StringDict replacements) {
/*
for (StringDict.Entry entry : replacements.entries()) {
Expand Down Expand Up @@ -823,8 +825,25 @@ static private Image svgToImage(String xmlStr, int wide, int high) {
pg.setSize(wide, high);
pg.smooth();





pg.beginDraw();

var cacheKey = (xmlStr + "|" + wide + "x" + high).hashCode();
var cachePath = Base.getSettingsFolder().toPath().resolve("svg_cache").resolve(String.valueOf(cacheKey) + ".png");
if(!Base.DEBUG || true){
if(Files.exists(cachePath)){
byte[] bytes = PApplet.loadBytes(cachePath.toFile());
if (bytes == null) {
return null;
} else {
return new ImageIcon(bytes).getImage();
}
}
}

try {
XML xml = XML.parse(xmlStr);
PShape shape = new PShapeJava2D(xml);
Expand All @@ -835,6 +854,12 @@ static private Image svgToImage(String xmlStr, int wide, int high) {
}

pg.endDraw();
try {
Files.createDirectories(cachePath.getParent());
pg.save(cachePath.toString());
} catch (IOException e) {
e.printStackTrace();
}
return pg.image;
}

Expand Down Expand Up @@ -1361,8 +1386,9 @@ static private Font initFont(String filename, int size) throws IOException, Font
Font font = Font.createFont(Font.TRUETYPE_FONT, input);
input.close();

// Register the font to be available for other function calls
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
new Thread(() -> {
GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
}).start();

return font.deriveFont((float) size);
}
Expand Down
23 changes: 2 additions & 21 deletions core/src/processing/core/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -6822,28 +6822,9 @@ static public String[] loadStrings(InputStream input) {

static public String[] loadStrings(BufferedReader reader) {
try {
String[] lines = new String[100];
int lineCount = 0;
String line;
while ((line = reader.readLine()) != null) {
if (lineCount == lines.length) {
String[] temp = new String[lineCount << 1];
System.arraycopy(lines, 0, temp, 0, lineCount);
lines = temp;
}
lines[lineCount++] = line;
}
var lines = reader.lines().toArray(String[]::new);
reader.close();

if (lineCount == lines.length) {
return lines;
}

// resize array to appropriate amount for these lines
String[] output = new String[lineCount];
System.arraycopy(lines, 0, output, 0, lineCount);
return output;

return lines;
} catch (IOException e) {
e.printStackTrace();
//throw new RuntimeException("Error inside loadStrings()");
Expand Down
4 changes: 3 additions & 1 deletion java/src/processing/mode/java/JavaTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class JavaTextArea extends PdeTextArea {
public JavaTextArea(TextAreaDefaults defaults, JavaEditor editor) {
super(defaults, new JavaInputHandler(editor), editor);

suggestionGenerator = new CompletionGenerator((JavaMode) editor.getMode());
new Thread(() -> {
suggestionGenerator = new CompletionGenerator((JavaMode) editor.getMode());
}).start();
tweakMode = false;
}

Expand Down
5 changes: 4 additions & 1 deletion java/src/processing/mode/java/PreprocService.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class PreprocService {
protected final JavaMode javaMode;
protected final Sketch sketch;

protected final ASTParser parser = ASTParser.newParser(AST.JLS11);
protected ASTParser parser;

private final Thread preprocessingThread;
private final BlockingQueue<Boolean> requestQueue = new ArrayBlockingQueue<>(1);
Expand Down Expand Up @@ -116,6 +116,9 @@ public PreprocService(JavaMode javaMode, Sketch sketch) {
* The "main loop" for the background thread that checks for code issues.
*/
private void mainLoop() {
if(parser == null) {
parser = ASTParser.newParser(AST.JLS11);
}
running = true;
PreprocSketch prevResult = null;
CompletableFuture<?> runningCallbacks = null;
Expand Down
6 changes: 5 additions & 1 deletion java/src/processing/mode/java/debug/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class Debugger {

public Debugger(JavaEditor editor) {
this.editor = editor;
inspector = new VariableInspector(editor);
// inspector = new VariableInspector(editor);
}


Expand Down Expand Up @@ -206,6 +206,9 @@ public void toggleEnabled() {
} else {
debugItem.setText(Language.text("menu.debug.enable"));
}
if(inspector == null) {
inspector = new VariableInspector(editor);
}
inspector.setVisible(enabled);

for (Component item : debugMenu.getMenuComponents()) {
Expand Down Expand Up @@ -297,6 +300,7 @@ public void removeClassLoadListener(ClassLoadListener listener) {


public void dispose() {
if(inspector == null) return;
inspector.dispose();
}

Expand Down