Skip to content
Closed
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
93 changes: 44 additions & 49 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

package processing.app;

import java.awt.*;
import java.awt.event.ActionListener;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
Expand All @@ -34,19 +45,6 @@
import processing.core.PApplet;
import processing.data.StringList;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;

/**
* The base class for the main processing application.
* Primary role of this class is for platform identification and
Expand Down Expand Up @@ -231,7 +229,7 @@ static private void createAndShowGUI(String[] args) {
Messages.log("Base() constructor succeeded");

// 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 @@ -850,7 +848,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 @@ -870,43 +868,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 @@ -915,7 +882,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 @@ -963,12 +930,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
31 changes: 22 additions & 9 deletions app/src/processing/app/platform/DefaultPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

package processing.app.platform;

import java.awt.*;
import java.io.File;

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

import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatLightLaf;
import processing.app.Base;
Expand All @@ -31,10 +37,6 @@
import processing.awt.ShimAWT;
import processing.core.PApplet;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.io.File;


/**
Expand Down Expand Up @@ -110,18 +112,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 @@ -193,7 +193,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
Loading