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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,7 @@ bin-test

# VS Code Java project files
.project
.vscode/
.vscode/

# ANTLR intermediate files
java/src/processing/mode/java/preproc/.antlr
3 changes: 2 additions & 1 deletion app/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
lib/ant-launcher.jar;
lib/flatlaf.jar;
lib/jna.jar;
lib/jna-platform.jar"
lib/jna-platform;
lib/build-flexmark-all.jar"
debug="on"
nowarn="true">
<compilerarg value="-Xlint:deprecation" />
Expand Down
Binary file added app/lib/build-flexmark-all.jar
Binary file not shown.
176 changes: 171 additions & 5 deletions app/src/processing/app/ui/EditorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,30 @@
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Desktop;

import javax.swing.*;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import javax.swing.JScrollPane;
import javax.swing.event.*;
import javax.swing.border.Border;

import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.net.URI;

import java.io.IOException;

import processing.app.Platform;
import processing.app.Preferences;
import processing.core.PApplet;

import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.data.MutableDataSet;

/**
* Panel just below the editing area that contains status messages.
Expand All @@ -68,6 +83,7 @@ public class EditorStatus extends BasicSplitPaneDivider {

int mode;
String message = "";
String friendlyMessage = "";

int messageRight;
String url;
Expand All @@ -79,6 +95,8 @@ public class EditorStatus extends BasicSplitPaneDivider {
static final int COLLAPSE_PRESSED = 4;
static final int CLIPBOARD_ROLLOVER = 5;
static final int CLIPBOARD_PRESSED = 6;
static final int MORE_INFO_ROLLOVER = 7;
static final int MORE_INFO_PRESSED = 8;
int mouseState;

Font font;
Expand All @@ -91,6 +109,8 @@ public class EditorStatus extends BasicSplitPaneDivider {
ImageIcon[] searchIcon;
ImageIcon[] collapseIcon;
ImageIcon[] expandIcon;
ImageIcon[] moreInfoIcon;


float btnEnabledAlpha;
float btnRolloverAlpha;
Expand All @@ -106,8 +126,115 @@ public class EditorStatus extends BasicSplitPaneDivider {
boolean collapsed = false;

boolean indeterminate;
public boolean isFriendly = false;
Thread thread;

public class friendlyErrorPopup{

private String messageText = "It looks like either a class name or semicolon is missing near 'asdfsda' on line 2!<br><br><b>Hint:</b> <br>Either a [class](https://processing.org/reference/class.html) was not given a name or a [semicolon](https://processing.org/reference/semicolon.html) is missing.<br><br><b>Suggestion:</b> <br>If the name was forgotten, add it and ensure that it does not start with a number. Make sure it only includes letters, numbers, dollar signs ($) and underscores (_). Also check that the name is not a keyword that is part of the language like \"true\", \"class\" or \"setup\" . If you are missing a semicolon, check the ends of the [statements](https://processing.org/examples/statementscomments.html) near 'if (' and line '43234234'.<br><br><b>For more:</b> [Variable Examples](https://processing.org/examples/variables.html)";
private JFrame popupFrame;
final int PROCESSING_SAYS_OFFSET = 5;

String markdownToHtml(String target) {
MutableDataSet options = new MutableDataSet();
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(target);
String html = renderer.render(document);
html = "<div style=\"font-family: Source Code PRO;color:font-size: 15px " + "#0d335a" + ";\"> <br><b>🔵Processing says:</b>" + html + "</div>" ;
return html;
}

public friendlyErrorPopup(String messageText){

int firstLineIndex = messageText.indexOf("<br>");
String firstSentence = messageText.substring(0,firstLineIndex);
int lineCounter = 0;
int newLineCount = 0;
String pureText = messageText;

Pattern newLineCounter = Pattern.compile("<br>");
Matcher newLineMatcher = newLineCounter.matcher(pureText);

Pattern linkSkipper = Pattern.compile("\\[([^\\]]+)\\]\\([^\\)]+\\)");
Matcher linkSkipperMatcher = linkSkipper.matcher(pureText);

// allows for error messages with markdown links in the first line although there currently are none
while (linkSkipperMatcher.find()){

pureText = pureText.replace(linkSkipperMatcher.group(0),linkSkipperMatcher.group(1));

}

firstSentence = pureText.substring(0,pureText.indexOf("<br>"));
firstLineIndex = firstSentence.length();

int index = 0;

while (index < pureText.length()) {
lineCounter++;
int nextBreakIndex = pureText.indexOf("<br>", index);
index = (((nextBreakIndex - index) <= firstLineIndex) && nextBreakIndex != -1) ? nextBreakIndex + 4 : index + firstLineIndex;
}

pureText = pureText.replaceAll("<br>","");


messageText = markdownToHtml(messageText);

JEditorPane errorPane = new JEditorPane();
errorPane.setContentType("text/html");

JScrollPane scrollPane = new JScrollPane(errorPane);

//not actually necessary but it allows the window resizing to work
errorPane.setFont(new Font("Source Code PRO", Font.PLAIN, 15));
errorPane.setText(messageText);
errorPane.setBackground(Color.decode("#fafcff"));
errorPane.setEditable(false);
java.awt.FontMetrics fontMetrics = errorPane.getFontMetrics(errorPane.getFont());

int popupWidth = fontMetrics.stringWidth(firstSentence) - 25;
int popupHeight = (lineCounter + PROCESSING_SAYS_OFFSET) * fontMetrics.getHeight();

errorPane.addHyperlinkListener((event) -> {
HyperlinkEvent.EventType eventType = event.getEventType();
boolean linkClicked = eventType == HyperlinkEvent.EventType.ACTIVATED;
if (linkClicked) {
String url = event.getURL().toString();
URI targetUri = URI.create(url);

try {
Desktop.getDesktop().browse(targetUri);
}
catch(IOException e) {
}
}
}
);

JFrame frame = new JFrame("[classname.pde]");

Border paddingBorder = BorderFactory.createEmptyBorder(0, 20, 0, 0); // Customize the padding as needed
Border border = BorderFactory.createLineBorder(java.awt.Color.decode("#58a2d1"), 10); // Customize the border as needed\
Border compoundBorder = BorderFactory.createCompoundBorder(border, paddingBorder);
errorPane.setBorder(compoundBorder);

// Set the preferred size for the scroll pane
scrollPane.setBorder(null);
frame.setSize(popupWidth, popupHeight);

// Create a container panel to hold the scroll pane
JPanel containerPanel = new JPanel(new BorderLayout());
containerPanel.add(scrollPane, BorderLayout.CENTER);

frame.setContentPane(containerPanel);

frame.setVisible(true);

}

}

public EditorStatus(BasicSplitPaneUI ui, Editor editor) {
super(ui);
Expand Down Expand Up @@ -222,18 +349,26 @@ void updateMouse(MouseEvent e, boolean pressed) {
} else if (url != null && mouseX > LEFT_MARGIN && mouseX < messageRight) {
mouseState = pressed ? URL_PRESSED : URL_ROLLOVER;
}
else if (mouseX > sizeW - (buttonEach * 3) && mouseX < sizeW - (2 * buttonEach)) {
mouseState = pressed ? MORE_INFO_PRESSED : MORE_INFO_ROLLOVER;
}
}
}

// only change on the rollover, no need to update on press
switch (mouseState) {
case CLIPBOARD_ROLLOVER:
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
break;
case URL_ROLLOVER:
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
break;
case COLLAPSE_ROLLOVER:
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
break;
case MORE_INFO_ROLLOVER:
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
break;
case NONE:
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
break;
Expand Down Expand Up @@ -268,6 +403,8 @@ protected void updateTheme() {
searchIcon = renderIcons("status/search", stateColors);
collapseIcon = renderIcons("status/console-collapse", stateColors);
expandIcon = renderIcons("status/console-expand", stateColors);
moreInfoIcon = renderIcons("status/more-info", stateColors);


btnEnabledAlpha = Theme.getInteger("status.button.enabled.alpha") / 100f;
btnRolloverAlpha = Theme.getInteger("status.button.rollover.alpha") / 100f;
Expand Down Expand Up @@ -310,12 +447,20 @@ public void empty() {
repaint();
}

public void message(String message, int mode) {

String newMessage = message;
int indexOfNewLine = message.indexOf("<br>");
if (indexOfNewLine != -1) {
this.isFriendly = true;
this.friendlyMessage = message;
newMessage = message.substring(0,indexOfNewLine);

public void message(String message, int mode) {
this.message = message;
}
System.out.println("newMessage: "+newMessage);
this.message = newMessage;
this.mode = mode;

url = findURL(message);
url = findURL(newMessage);
repaint();
}

Expand Down Expand Up @@ -449,8 +594,29 @@ public void paint(Graphics g) {
alpha = btnEnabledAlpha;
}
drawButton(g, 0, glyph, alpha);
}

// draw more info button


if (isFriendly) {
ImageIcon glyph2;
glyph2 = moreInfoIcon[mode];
if (mouseState == MORE_INFO_ROLLOVER) {
alpha = btnRolloverAlpha;
} else if (mouseState == MORE_INFO_PRESSED) {
alpha = btnPressedAlpha;
friendlyErrorPopup friendlyPopup = new friendlyErrorPopup(friendlyMessage);
}
else {
alpha = btnEnabledAlpha;
}

drawButton(g,2,moreInfoIcon[mode],alpha);

}


}

/**
* @param pos A zero-based button index with 0 as the rightmost button
Expand Down
4 changes: 2 additions & 2 deletions build/shared/lib/languages/PDE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ editor.status.uninitialized_variable = The local variable “%s” may not have
editor.status.no_effect_assignment = The assignment to variable “%s” has no effect
editor.status.hiding_enclosing_type = The class “%s” cannot have the same name as your sketch or its enclosing class

editor.status.bad.assignment = Possible error on variable assignment near ‘%s’?
editor.status.bad.assignment = There seems to be some trouble with how a variable is being assigned near line 12!<br><br><b>Hint:</b> <br>There is an issue with how a variable is being set to a certain value. This is also known as variable [assignment](https://processing.org/reference/assign.html). We suspect that the problem is near ‘%s’.<br><br><b>Suggestion:</b> <br>It’s important to double check that the variable is named properly (see the variable example below) and that you have included all of the necessary parts of a variable assignment. You should also make sure that you chose an appropriate [datatype](https://processing.org/reference/#data) for your variable so that it can hold the value that you are assigning to it.<br><br><b>Example:</b>To assign variables you need the type, name, assignment operator (=), the value you want to assign the variable to and a semicolon. Here’s the basic format:<br>[data type] [name] = [value]; <br><b>Example:</b> <br>> int num = 4;<br><br>For more: [Variable Example](https://processing.org/examples/variables.html)
editor.status.bad.generic = Possibly missing type in generic near ‘%s’?
editor.status.bad.identifier = Bad identifier? Did you forget a variable or start an identifier with digits near ‘%s’?
editor.status.bad.parameter = Error on parameter or method declaration near ‘%s’?
Expand Down Expand Up @@ -654,4 +654,4 @@ movie_maker.progress.creating_output_file = Creating output file
movie_maker.progress.initializing = Initializing...
movie_maker.progress.processing = Processing %s.

movie_maker.progress.handling_frame = Converting frame %s of %s...
movie_maker.progress.handling_frame = Converting frame %s of %s...
5 changes: 5 additions & 0 deletions build/shared/lib/status/more-info.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions java/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<pathelement location="../app/lib/jna.jar" />
<pathelement location="../app/lib/jna-platform.jar" />


<pathelement location="mode/antlr-4.7.2-complete.jar" />
<pathelement location="mode/classpath-explorer-1.0.jar" />
<pathelement location="mode/jsoup-1.7.1.jar" />
Expand All @@ -116,6 +117,9 @@
<pathelement location="mode/org.eclipse.lsp4j.jsonrpc.jar" />
<pathelement location="mode/org.eclipse.osgi.jar" />
<pathelement location="mode/org.eclipse.text.jar" />
<pathelement location="mode/ST-4.3.4.jar" />
<pathelement location="mode/build-flexmark-all.jar" />

</path>

<path id="classpath.test">
Expand Down
Binary file added java/mode/ST-4.3.4.jar
Binary file not shown.
Binary file added java/mode/build-flexmark-all.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions java/src/processing/mode/java/debug/VariableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class VariableNode implements MutableTreeNode {
public static final int TYPE_BYTE = 9;
public static final int TYPE_SHORT = 10;
public static final int TYPE_VOID = 11;

private static final Pattern ARRAY_REGEX = Pattern.compile("^(?<prefix>[^\\[]+)(?<unbounded>(\\[\\])+)(?<bounded>(\\[\\d+\\])+)(?<unneeded>[^\\[]*)$");

protected String type;
protected String name;
protected Value value;
Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/preproc/PdeIssueEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int
int charPositionInLine, String msg, RecognitionException e) {

PreprocessIssueMessageSimplifier facade = PreprocessIssueMessageSimplifier.get();
IssueMessageSimplification simplification = facade.simplify(msg);
IssueMessageSimplification simplification = facade.simplify(msg, line);

IssueLocation issueLocation;

Expand Down
Loading