From e483323c61be4c5f185e3ec6382007f89bb29a8f Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 20 Sep 2015 13:05:54 -0400 Subject: [PATCH] looking into erratic placement of error squiggle for #3759 --- .../mode/java/pdex/JavaTextAreaPainter.java | 188 ++++++++---------- todo.txt | 72 ++++--- 2 files changed, 120 insertions(+), 140 deletions(-) diff --git a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java index 98f50d1d7..752ff2969 100644 --- a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java +++ b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java @@ -322,6 +322,34 @@ public class JavaTextAreaPainter extends TextAreaPainter } + /** + * Remove all trailing whitespace from a line + */ + static private String trimRight(String str) { + int i = str.length() - 1; + while (i >= 0 && Character.isWhitespace(str.charAt(i))) { + i--; + } + return str.substring(0, i+1); + } + + + /** + * @return the LineMarker for the first error or warning on 'line' + */ + private LineMarker findError(int line) { + List errorPoints = getJavaEditor().getErrorPoints(); + synchronized (errorPoints) { + for (LineMarker emarker : errorPoints) { + if (emarker.getProblem().getLineNumber() == line) { + return emarker; + } + } + } + return null; + } + + /** * Paints the underline for an error/warning line * @@ -338,123 +366,67 @@ public class JavaTextAreaPainter extends TextAreaPainter return; } - boolean notFound = true; - boolean isWarning = false; - Problem problem = null; - errorLineCoords.clear(); - // Check if current line contains an error. If it does, find if it's an - // error or warning - List errorPoints = getJavaEditor().getErrorPoints(); - synchronized (errorPoints) { - for (LineMarker emarker : errorPoints) { - if (emarker.getProblem().getLineNumber() == line) { - notFound = false; - if (emarker.getType() == LineMarker.WARNING) { - isWarning = true; - } - problem = emarker.getProblem(); - //log(problem.toString()); - break; - } - } - } + LineMarker marker = findError(line); + if (marker != null) { + Problem problem = marker.getProblem(); - if (notFound) { - return; - } + int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent(); + int start = textArea.getLineStartOffset(line) + problem.getPDELineStartOffset(); + int length = 1 + problem.getPDELineStopOffset() - problem.getPDELineStartOffset(); - // Determine co-ordinates - // log("Hoff " + ta.getHorizontalOffset() + ", " + - // horizontalAdjustment); - int y = textArea.lineToY(line); - y += fm.getLeading() + fm.getMaxDescent(); -// int height = fm.getHeight(); - int start = textArea.getLineStartOffset(line) + problem.getPDELineStartOffset(); - int pLength = problem.getPDELineStopOffset() + 1 - problem.getPDELineStartOffset(); - - try { - String badCode = null; - String goodCode = null; try { - SyntaxDocument doc = textArea.getDocument(); - badCode = doc.getText(start, pLength); - goodCode = doc.getText(textArea.getLineStartOffset(line), problem.getPDELineStartOffset()); - //log("paintErrorLine() LineText GC: " + goodCode); - //log("paintErrorLine() LineText BC: " + badCode); - } catch (BadLocationException bl) { - // Error in the import statements or end of code. - // System.out.print("BL caught. " + ta.getLineCount() + " ," - // + line + " ,"); - // log((ta.getLineStopOffset(line) - start - 1)); - return; + String badCode = null; + String goodCode = null; + try { + SyntaxDocument doc = textArea.getDocument(); + badCode = doc.getText(start, length); + goodCode = doc.getText(textArea.getLineStartOffset(line), problem.getPDELineStartOffset()); + //log("paintErrorLine() LineText GC: " + goodCode); + //log("paintErrorLine() LineText BC: " + badCode); + } catch (BadLocationException bl) { + // Error in the import statements or end of code. + // System.out.print("BL caught. " + ta.getLineCount() + " ," + // + line + " ,"); + // log((ta.getLineStopOffset(line) - start - 1)); + return; + } + + // Take care of offsets + int aw = fm.stringWidth(trimRight(badCode)) + textArea.getHorizontalOffset(); + // to the left of line + text + // width + int rw = fm.stringWidth(badCode.trim()); // real width + int x1 = fm.stringWidth(goodCode) + (aw - rw); + int y1 = y + fm.getHeight() - 2, x2 = x1 + rw; + // Adding offsets for the gutter + x1 += Editor.LEFT_GUTTER; + x2 += Editor.LEFT_GUTTER; + + errorLineCoords.add(new ErrorLineCoord(x1, x2, y, y1, problem)); + + gfx.setColor(errorUnderlineColor); + if (marker.getType() == LineMarker.WARNING) { + gfx.setColor(warningUnderlineColor); + } + paintSquiggle(gfx, y1, x1, x2); + + } catch (Exception e) { + e.printStackTrace(); } - - // Take care of offsets - int aw = fm.stringWidth(trimRight(badCode)) + textArea.getHorizontalOffset(); // apparent width. Whitespaces - // to the left of line + text - // width - int rw = fm.stringWidth(badCode.trim()); // real width - int x1 = fm.stringWidth(goodCode) + (aw - rw), y1 = y + fm.getHeight() - - 2, x2 = x1 + rw; - // Adding offsets for the gutter - x1 += Editor.LEFT_GUTTER; - x2 += Editor.LEFT_GUTTER; - - errorLineCoords.add(new ErrorLineCoord(x1, x2, y, y1, problem)); - - // gfx.fillRect(x1, y, rw, height); - - // Let the painting begin! - - // Little rect at starting of a line containing errors - disabling it for now -// gfx.setColor(errorMarkerColor); -// if (isWarning) { -// gfx.setColor(warningMarkerColor); -// } -// gfx.fillRect(1, y + 2, 3, height - 2); - - gfx.setColor(errorUnderlineColor); - if (isWarning) { - gfx.setColor(warningUnderlineColor); - } - int xx = x1; - - // Draw the jagged lines - while (xx < x2) { - gfx.drawLine(xx, y1, xx + 2, y1 + 1); - xx += 2; - gfx.drawLine(xx, y1 + 1, xx + 2, y1); - xx += 2; - } - } catch (Exception e) { - System.out - .println("Looks like I messed up! XQTextAreaPainter.paintLine() : " - + e); - //e.printStackTrace(); } - - // Won't highlight the line. Select the text instead. - // gfx.setColor(Color.RED); - // gfx.fillRect(2, y, 3, height); } - /** - * Trims out trailing whitespaces (to the right) - * - * @param string - * @return - String - */ - static private String trimRight(String string) { - String newString = ""; - for (int i = 0; i < string.length(); i++) { - if (string.charAt(i) != ' ') { - newString = string.substring(0, i) + string.trim(); - break; - } + static private void paintSquiggle(Graphics g, int y, int x1, int x2) { + int xx = x1; + + while (xx < x2) { + g.drawLine(xx, y, xx + 2, y + 1); + xx += 2; + g.drawLine(xx, y + 1, xx + 2, y); + xx += 2; } - return newString; } @@ -464,8 +436,6 @@ public class JavaTextAreaPainter extends TextAreaPainter public void setMode(Mode mode) { errorUnderlineColor = mode.getColor("editor.error.underline.color"); warningUnderlineColor = mode.getColor("editor.warning.underline.color"); -// errorMarkerColor = mode.getColor("editor.errormarkercolor"); -// warningMarkerColor = mode.getColor("editor.warningmarkercolor"); gutterTextFont = mode.getFont("editor.gutter.text.font"); gutterTextColor = mode.getColor("editor.gutter.text.color"); diff --git a/todo.txt b/todo.txt index 7199be92a..3d0105b23 100644 --- a/todo.txt +++ b/todo.txt @@ -16,24 +16,29 @@ X foundation icon below next to description when lib selected X icons on the install/update/remove buttons X search eyeglass icon X available/installed/incompatible icons +o change Tool API because it's not one Editor per Tool anymore? +X or just change the documentation? +X updated the FAQ and tool template +X items still show up in "Recent" if they no longer exist (on startup) +X checked code and this seems to be fine / can't reproduce -may be fixed -_ UnsatisfiedLinkError on startup "Access is denied" on Windows 10 -_ https://github.com/processing/processing/issues/3800 -_ administrator, but using Microsoft account to log in -_ JNA errors on startup when run from an account w/ non-ASCII characters -_ https://github.com/processing/processing/issues/3624 -_ set jna.tmpdir (or java.io.tmpdir) to another location -_ https://github.com/twall/jna/issues/124 -_ https://github.com/twall/jna/issues/238 -_ Sun says they won't fix: user locale and system locale probably different: -_ https://bugs.openjdk.java.net/browse/JDK-8017274 -_ https://bugs.openjdk.java.net/browse/JDK-4958170 -_ https://github.com/twall/jna/blob/master/test/com/sun/jna/JNALoadTest.java -_ http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/ -_ fix: get sun.jnu.encoding and make sure the user name is supported in it? -_ and if not, put up a warning for the user? -_ http://www.oracle.com/us/technologies/java/locale-140624.html +jna problems +X UnsatisfiedLinkError on startup "Access is denied" on Windows 10 +X https://github.com/processing/processing/issues/3800 +X administrator, but using Microsoft account to log in +X JNA errors on startup when run from an account w/ non-ASCII characters +X https://github.com/processing/processing/issues/3624 +X set jna.tmpdir (or java.io.tmpdir) to another location +X https://github.com/twall/jna/issues/124 +X https://github.com/twall/jna/issues/238 +X Sun says they won't fix: user locale and system locale probably different: +X https://bugs.openjdk.java.net/browse/JDK-8017274 +X https://bugs.openjdk.java.net/browse/JDK-4958170 +X https://github.com/twall/jna/blob/master/test/com/sun/jna/JNALoadTest.java +X http://happygiraffe.net/blog/2009/09/24/java-platform-encoding/ +X fix: get sun.jnu.encoding and make sure the user name is supported in it? +X and if not, put up a warning for the user? +X http://www.oracle.com/us/technologies/java/locale-140624.html manager X CM: Clicking item in Libraries list throws exception @@ -52,7 +57,7 @@ X prevent re-prompting users when they say "no" to "sketch modified" message X add more preferences for editor.watcher X cleaning up the logic in the watcher -gsoc +akarshit X prevent "updating" to a still-incompatible version of a contrib X https://github.com/processing/processing/issues/3801 X https://github.com/processing/processing/pull/3805 @@ -66,16 +71,20 @@ X CM list should be sortable by status and author name X https://github.com/processing/processing/issues/3608 _ All contributions listed after install button is clicked _ https://github.com/processing/processing/issues/3826 +_ "update all" button appears to do nothing in library manager +_ https://github.com/processing/processing/issues/3837 jakub X Make preprocessor scope-aware X https://github.com/processing/processing/issues/3799 X https://github.com/processing/processing/pull/3810 -_ auto-complete is broken on OS X +_ auto-complete is a mess (and broken on OS X) _ https://github.com/processing/processing/issues/3812 _ Hitting enter on code completion completes and then creates a new line _ https://github.com/processing/processing/issues/3741 _ found thread deadlock issues preventing it from working on OS X +_ Red error underline is sometimes at wrong location +_ https://github.com/processing/processing/issues/3759 _ ctrl-space first inserts space, then deletes it, with completion @@ -91,16 +100,7 @@ _ mouse events (i.e. toggle breakpoint) seem to be firing twice 3.0 final _ https://github.com/processing/processing/milestones/3.0%20final -_ Live error checking throws error when calling color() on a PGraphics -_ https://github.com/processing/processing/issues/3762 -_ "color type detected! this shouldn't be happening! please report" -_ happens when user does 'new color' instead of 'color' -_ https://github.com/processing/processing/issues/3739 -_ change Tool API because it's not one Editor per Tool anymore? -_ or just change the documentation? -_ items still show up in "Recent" if they no longer exist (on startup) -_ Red error underline is sometimes at wrong location -_ https://github.com/processing/processing/issues/3759 +_ remove the dated releases from download.processing.org sketch modified externally (3.0 final) @@ -115,7 +115,7 @@ o use watcher service after all? o https://docs.oracle.com/javase/tutorial/essential/io/notification.html -gui/James +gui / James _ Fix placement and visual design when showing error on hover _ https://github.com/processing/processing/issues/3173 _ import suggestions box needs design review @@ -139,7 +139,8 @@ _ https://github.com/processing/processing/issues/3072 gui / post 3.0 -_ different design of squiggly line? +_ different design of squiggly line +_ easy to do inside JavaTextAreaPainter.paintSquiggle() _ build custom scroll bar since the OS versions are so ugly? _ error/warning location is awkward when no scroll bar is in use _ when only one screen-full, show ticks at exact location @@ -180,6 +181,8 @@ _ Examples window closes and re-opens during library install/remove _ https://github.com/processing/processing/issues/3304 _ ArrayIndexOutOfBoundsException freak out when clicking the header line _ think this was on name, with libraries, but not sure +_ CM - Icon instead of an "X" for the "could not connect" message +_ https://github.com/processing/processing/issues/3706 gui/low @@ -538,7 +541,14 @@ _ http://i.msdn.microsoft.com/Aa511273.Confirmations03(en-us,MSDN.10).png PDE / Compiler & Preprocessor +live error checker +_ using "new color()" instead of "color()" results in "color type detected" +_ happens when user does 'new color' instead of 'color' +_ https://github.com/processing/processing/issues/3739 + medium (bugs/features) +_ preprocessor throws error when calling color() on a PGraphics +_ https://github.com/processing/processing/issues/3762 _ incorporate new preproc _ https://github.com/fjenett/processing-preprocessor-antlr4 _ https://github.com/processing/processing/issues/3055