diff --git a/build/shared/lib/theme.txt b/build/shared/lib/theme.txt index 6e40e2935..5258df487 100644 --- a/build/shared/lib/theme.txt +++ b/build/shared/lib/theme.txt @@ -111,12 +111,25 @@ editor.gutter.text.font = processing.mono,plain,11 #editor.gutter.text.color = #587478 editor.gutter.text.color = #bbd6d5 +# marker for breakpointed lines in left hand gutter (2 ascii characters) +editor.gutter.breakpoint.marker = <> +editor.gutter.breakpoint.marker.color = #4a545e + +# marker for the current line in left hand gutter (2 ascii characters) +editor.gutter.currentline.marker = -> +editor.gutter.currentline.marker.color = #e27500 + # bgcolor for the current (highlighted) line editor.gutter.linehighlight.color=#587478 # left- and right-hand gutter color editor.gutter.bgcolor = #122535 +# color of vertical separation line +#gutter.linecolor = #e9e9e9 +# space (in px) added to left and right of gutter markers +editor.gutter.padding = 3 + # squiggly line underneath errors in the editor editor.error.underline.color = #C40E0E # squiggly line underneath warnings @@ -125,23 +138,6 @@ editor.warning.underline.color = #ffc30e editor.column.error.color = #9F1613 editor.column.warning.color = #ffc30e - -# DEBUGGER - -# breakpointed line background color -breakpoint.bgcolor = #f0f0f0 -# marker for breakpointed lines in left hand gutter (2 ascii characters) -breakpoint.marker = <> -breakpoint.marker.color = #4a545e - -# current line background color -currentline.bgcolor = #ffff96 -# marker for the current line in left hand gutter (2 ascii characters) -currentline.marker = -> -currentline.marker.color = #e27500 - -# color of vertical separation line -#gutter.linecolor = #e9e9e9 -# space (in px) added to left and right of gutter markers -gutter.padding = 3 - +# not in use? +#breakpoint.bgcolor = #f0f0f0 +#currentline.bgcolor = #ffff96 diff --git a/java/src/processing/mode/java/ErrorColumn.java b/java/src/processing/mode/java/ErrorColumn.java index e477869da..24cff032b 100644 --- a/java/src/processing/mode/java/ErrorColumn.java +++ b/java/src/processing/mode/java/ErrorColumn.java @@ -24,8 +24,6 @@ import java.awt.Color; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; @@ -36,110 +34,84 @@ import java.util.List; import javax.swing.JPanel; import javax.swing.SwingWorker; import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import processing.app.Mode; +import processing.app.Sketch; import processing.app.SketchCode; import processing.app.Util; import processing.mode.java.pdex.ErrorCheckerService; -import processing.mode.java.pdex.ErrorMarker; +import processing.mode.java.pdex.LineMarker; import processing.mode.java.pdex.Problem; import processing.app.Language; + /** - * The bar on the left of the text area which displays all errors as rectangles.
+ * Implements the column to the right of the editor window that displays ticks + * for errors and warnings. *
* All errors and warnings of a sketch are drawn on the bar, clicking on one, * scrolls to the tab and location. Error messages displayed on hover. Markers * are not in sync with the error line. Similar to eclipse's right error bar * which displays the overall errors in a document - * - * @author Manindra Moharana <me@mkmoharana.com> - * */ public class ErrorColumn extends JPanel { - /** - * Preferred height of the component - */ - protected int preferredHeight; + protected JavaEditor editor; + protected ErrorCheckerService errorCheckerService; - /** - * Preferred height of the component - */ - protected int preferredWidth = 12; + static final int WIDE = 12; +// protected int preferredHeight; +// protected int preferredWidth = 12; - /** - * Height of marker - */ - public static final int errorMarkerHeight = 4; +// static final int errorMarkerHeight = 4; - /** - * Color of Error Marker - */ - public Color errorColor; // = new Color(0xED2630); + private Color errorColor; + private Color warningColor; + private Color backgroundColor; - /** - * Color of Warning Marker - */ - public Color warningColor; // = new Color(0xFFC30E); + /** Stores error markers displayed PER TAB along the error bar. */ + private List errorPoints = + Collections.synchronizedList(new ArrayList()); - /** - * Background color of the component - */ - public Color backgroundColor; // = new Color(0x2C343D); + /** Stores previous list of error markers. */ + private List errorPointsOld = new ArrayList(); - /** - * JavaEditor instance - */ - protected JavaEditor editor; - - /** - * ErrorCheckerService instance - */ - protected ErrorCheckerService errorCheckerService; - - /** - * Stores error markers displayed PER TAB along the error bar. - */ - protected List errorPoints = - Collections.synchronizedList(new ArrayList()); - - /** - * Stores previous list of error markers. - */ - protected ArrayList errorPointsOld = new ArrayList(); public void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); +// Graphics2D g2d = (Graphics2D) g; +// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, +// RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(backgroundColor); g.fillRect(0, 0, getWidth(), getHeight()); - for (ErrorMarker emarker : errorPoints) { - if (emarker.getType() == ErrorMarker.Error) { + for (LineMarker m : errorPoints) { + if (m.getType() == LineMarker.ERROR) { g.setColor(errorColor); } else { g.setColor(warningColor); } - g.fillRect(2, emarker.getY(), (getWidth() - 3), errorMarkerHeight); + //g.fillRect(2, emarker.getY(), (getWidth() - 3), errorMarkerHeight); + g.drawLine(2, m.getY(), getWidth() - 2, m.getY()); } } - public Dimension getPreferredSize() { - return new Dimension(preferredWidth, preferredHeight); - } +// public Dimension getPreferredSize() { +// return new Dimension(preferredWidth, preferredHeight); +// } - public Dimension getMinimumSize() { - return getPreferredSize(); - } +// public Dimension getMinimumSize() { +// return getPreferredSize(); +// } - public ErrorColumn(JavaEditor editor, int height, JavaMode mode) { + public ErrorColumn(JavaEditor editor, int height) { this.editor = editor; - this.preferredHeight = height; +// this.preferredHeight = height; this.errorCheckerService = editor.errorCheckerService; + Mode mode = editor.getMode(); errorColor = mode.getColor("editor.column.error.color"); warningColor = mode.getColor("editor.column.warning.color"); backgroundColor = mode.getColor("editor.gutter.bgcolor"); @@ -147,12 +119,12 @@ public class ErrorColumn extends JPanel { addListeners(); } - /** - * Update error markers in the error bar. - * - * @param problems - * - List of problems. - */ + + public List getErrorPoints() { + return errorPoints; + } + + synchronized public void updateErrorPoints(final List problems) { // NOTE TO SELF: ErrorMarkers are calculated for the present tab only // Error Marker index in the arraylist is LOCALIZED for current tab. @@ -162,43 +134,45 @@ public class ErrorColumn extends JPanel { SwingWorker worker = new SwingWorker() { protected Object doInBackground() throws Exception { - SketchCode sc = editor.getSketch().getCurrentCode(); - int totalLines = 0, currentTab = editor.getSketch() - .getCurrentCodeIndex(); + Sketch sketch = editor.getSketch(); + SketchCode sc = sketch.getCurrentCode(); + int totalLines = 0; + int currentTab = sketch.getCurrentCodeIndex(); try { - totalLines = Util.countLines(sc.getDocument() - .getText(0, sc.getDocument().getLength())) + 1; + Document doc = sc.getDocument(); + totalLines = Util.countLines(doc.getText(0, doc.getLength())) + 1; } catch (BadLocationException e) { e.printStackTrace(); } // System.out.println("Total lines: " + totalLines); - synchronized (errorPoints) { - errorPointsOld.clear(); - for (ErrorMarker marker : errorPoints) { - errorPointsOld.add(marker); - } - errorPoints.clear(); +// synchronized (errorPoints) { + errorPointsOld = errorPoints; + errorPoints = new ArrayList<>(); +// errorPointsOld.clear(); +// for (ErrorMarker marker : errorPoints) { +// errorPointsOld.add(marker); +// } +// errorPoints.clear(); // Each problem.getSourceLine() will have an extra line added // because of // class declaration in the beginning as well as default imports - synchronized (problems) { - for (Problem problem : problems) { - if (problem.getTabIndex() == currentTab) { - // Ratio of error line to total lines - float y = (problem.getLineNumber() + 1) - / ((float) totalLines); - // Ratio multiplied by height of the error bar - y *= fheight - 15; // -15 is just a vertical offset - errorPoints - .add(new ErrorMarker(problem, (int) y, - problem.isError() ? ErrorMarker.Error - : ErrorMarker.Warning)); + synchronized (problems) { + for (Problem problem : problems) { + if (problem.getTabIndex() == currentTab) { + // Ratio of error line to total lines + float y = (problem.getLineNumber() + 1) / ((float) totalLines); + // Ratio multiplied by height of the error bar + y *= fheight - 15; // -15 is just a vertical offset + errorPoints.add(new LineMarker(problem, (int) y, + problem.isError() ? + LineMarker.ERROR + : LineMarker.WARNING)); // System.out.println("Y: " + y); } } } - } +// } return null; } @@ -255,11 +229,11 @@ public class ErrorColumn extends JPanel { SwingWorker worker = new SwingWorker() { protected Object doInBackground() throws Exception { - for (ErrorMarker eMarker : errorPoints) { + for (LineMarker eMarker : errorPoints) { // -2 and +2 are extra allowance, clicks in the // vicinity of the markers register that way if (e.getY() >= eMarker.getY() - 2 - && e.getY() <= eMarker.getY() + 2 + errorMarkerHeight) { + && e.getY() <= eMarker.getY() + 2) { errorCheckerService.scrollToErrorLine(eMarker.getProblem()); return null; } @@ -285,9 +259,9 @@ public class ErrorColumn extends JPanel { SwingWorker worker = new SwingWorker() { protected Object doInBackground() throws Exception { - for (ErrorMarker eMarker : errorPoints) { + for (LineMarker eMarker : errorPoints) { if (evt.getY() >= eMarker.getY() - 2 && - evt.getY() <= eMarker.getY() + 2 + errorMarkerHeight) { + evt.getY() <= eMarker.getY() + 2) { Problem p = eMarker.getProblem(); String msg = ((p.isError() ? Language.text("editor.status.error") @@ -314,4 +288,14 @@ public class ErrorColumn extends JPanel { } }); } + + + public Dimension getPreferredSize() { + return new Dimension(WIDE, super.getPreferredSize().height); + } + + + public Dimension getMinimumSize() { + return new Dimension(WIDE, super.getMinimumSize().height); + } } diff --git a/java/src/processing/mode/java/JavaEditor.java b/java/src/processing/mode/java/JavaEditor.java index 4ade62a2e..93bbeb3d6 100644 --- a/java/src/processing/mode/java/JavaEditor.java +++ b/java/src/processing/mode/java/JavaEditor.java @@ -45,7 +45,7 @@ import processing.mode.java.debug.LineBreakpoint; import processing.mode.java.debug.LineHighlight; import processing.mode.java.debug.LineID; import processing.mode.java.pdex.ErrorCheckerService; -import processing.mode.java.pdex.ErrorMarker; +import processing.mode.java.pdex.LineMarker; import processing.mode.java.pdex.ErrorMessageSimplifier; import processing.mode.java.pdex.JavaTextArea; import processing.mode.java.pdex.Problem; @@ -164,7 +164,7 @@ public class JavaEditor extends Editor { // remove the text area temporarily box.remove(2); textAndError.setLayout(new BorderLayout()); - errorColumn = new ErrorColumn(this, textarea.getMinimumSize().height, jmode); + errorColumn = new ErrorColumn(this, textarea.getMinimumSize().height); textAndError.add(errorColumn, BorderLayout.EAST); textarea.setBounds(0, 0, errorColumn.getX() - 1, textarea.getHeight()); textAndError.add(textarea); @@ -2547,8 +2547,8 @@ public class JavaEditor extends Editor { } - public List getErrorPoints() { - return errorColumn.errorPoints; + public List getErrorPoints() { + return errorColumn.getErrorPoints(); } diff --git a/java/src/processing/mode/java/pdex/ErrorCheckerService.java b/java/src/processing/mode/java/pdex/ErrorCheckerService.java index 0c15cf869..12235ac31 100644 --- a/java/src/processing/mode/java/pdex/ErrorCheckerService.java +++ b/java/src/processing/mode/java/pdex/ErrorCheckerService.java @@ -988,9 +988,9 @@ public class ErrorCheckerService implements Runnable { // editor.getTextArea().getCaretLine()); if (JavaMode.errorCheckEnabled) { synchronized (editor.getErrorPoints()) { - for (ErrorMarker emarker : editor.getErrorPoints()) { + for (LineMarker emarker : editor.getErrorPoints()) { if (emarker.getProblem().getLineNumber() == editor.getTextArea().getCaretLine()) { - if (emarker.getType() == ErrorMarker.Warning) { + if (emarker.getType() == LineMarker.WARNING) { editor.statusMessage(emarker.getProblem().getMessage(), JavaEditor.STATUS_INFO); } else { @@ -1579,12 +1579,9 @@ public class ErrorCheckerService implements Runnable { return new String(p2, 0, index); } - public void handleErrorCheckingToggle(){ + public void handleErrorCheckingToggle() { if (!JavaMode.errorCheckEnabled) { - // unticked Menu Item - // pauseThread(); - Messages.log(editor.getSketch().getName() - + " - Error Checker paused."); + Messages.log(editor.getSketch().getName() + " Error Checker paused."); editor.getErrorPoints().clear(); problemsList.clear(); updateErrorTable(); @@ -1592,9 +1589,7 @@ public class ErrorCheckerService implements Runnable { editor.getTextArea().repaint(); editor.repaintErrorBar(); } else { - //resumeThread(); - Messages.log(editor.getSketch().getName() - + " - Error Checker resumed."); + Messages.log(editor.getSketch().getName() + " Error Checker resumed."); runManualErrorCheck(); } } diff --git a/java/src/processing/mode/java/pdex/JavaTextArea.java b/java/src/processing/mode/java/pdex/JavaTextArea.java index f74df6dda..aa9b432dd 100644 --- a/java/src/processing/mode/java/pdex/JavaTextArea.java +++ b/java/src/processing/mode/java/pdex/JavaTextArea.java @@ -132,12 +132,12 @@ public class JavaTextArea extends JEditTextArea { // load settings from theme.txt Mode mode = editor.getMode(); - gutterBgColor = mode.getColor("gutter.bgcolor"); //, gutterBgColor); - gutterLineColor = mode.getColor("gutter.linecolor"); //, gutterLineColor); - gutterPadding = mode.getInteger("gutter.padding"); - breakpointMarker = mode.getString("breakpoint.marker"); //, breakpointMarker); + gutterBgColor = mode.getColor("editor.gutter.bgcolor"); //, gutterBgColor); + gutterLineColor = mode.getColor("editor.gutter.linecolor"); //, gutterLineColor); + gutterPadding = mode.getInteger("editor.gutter.padding"); + breakpointMarker = mode.getString("editor.gutter.breakpoint.marker"); //, breakpointMarker); // breakpointMarker = "\u2666"; - currentLineMarker = mode.getString("currentline.marker"); //, currentLineMarker); + currentLineMarker = mode.getString("editor.gutter.currentline.marker"); //, currentLineMarker); // TweakMode code prevCompListeners = painter.getComponentListeners(); diff --git a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java index 587a68854..faca922df 100644 --- a/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java +++ b/java/src/processing/mode/java/pdex/JavaTextAreaPainter.java @@ -57,11 +57,12 @@ import processing.app.syntax.TokenMarker; import processing.app.ui.Editor; +// TODO Most of this needs to be merged into the main TextAreaPainter, +// since it's not specific to Java. [fry 150821] + /** * Customized line painter. Adds support for background colors, * left hand gutter area with background color and text. - * TODO Most of this needs to be merged into the main TextAreaPainter, - * since it has nothing to do with Java. [fry] */ public class JavaTextAreaPainter extends TextAreaPainter implements MouseListener, MouseMotionListener { @@ -314,17 +315,12 @@ public class JavaTextAreaPainter extends TextAreaPainter y += fm.getLeading() + fm.getMaxDescent(); int height = fm.getHeight(); - // get the color Color col = getTextArea().getLineBgColor(line); - //System.out.print("bg line " + line + ": "); - // no need to paint anything - if (col == null) { - //log("none"); - return; + if (col != null) { + // paint line background + gfx.setColor(col); + gfx.fillRect(0, y, getWidth(), height); } - // paint line background - gfx.setColor(col); - gfx.fillRect(0, y, getWidth(), height); } @@ -351,10 +347,10 @@ public class JavaTextAreaPainter extends TextAreaPainter errorLineCoords.clear(); // Check if current line contains an error. If it does, find if it's an // error or warning - for (ErrorMarker emarker : getEditor().getErrorPoints()) { + for (LineMarker emarker : getEditor().getErrorPoints()) { if (emarker.getProblem().getLineNumber() == line) { notFound = false; - if (emarker.getType() == ErrorMarker.Warning) { + if (emarker.getType() == LineMarker.WARNING) { isWarning = true; } problem = emarker.getProblem(); @@ -463,9 +459,6 @@ public class JavaTextAreaPainter extends TextAreaPainter /** * Sets ErrorCheckerService and loads theme for TextAreaPainter(XQMode) - * - * @param ecs - * @param mode */ public void setMode(JavaMode mode) { errorUnderlineColor = mode.getColor("editor.error.underline.color"); diff --git a/java/src/processing/mode/java/pdex/ErrorMarker.java b/java/src/processing/mode/java/pdex/LineMarker.java similarity index 84% rename from java/src/processing/mode/java/pdex/ErrorMarker.java rename to java/src/processing/mode/java/pdex/LineMarker.java index 56fb1727a..f1a070968 100644 --- a/java/src/processing/mode/java/pdex/ErrorMarker.java +++ b/java/src/processing/mode/java/pdex/LineMarker.java @@ -20,13 +20,11 @@ along with this program; if not, write to the Free Software Foundation, Inc. package processing.mode.java.pdex; + /** - * Error markers displayed on the Error Bar. - * - * @author Manindra Moharana <me@mkmoharana.com> - * + * Line markers displayed on the Error Column. */ -public class ErrorMarker { +public class LineMarker { /** * y co-ordinate of the marker */ @@ -38,25 +36,25 @@ public class ErrorMarker { /** * Error Type constant */ - public static final int Error = 1; + public static final int ERROR = 1; /** * Warning Type constant */ - public static final int Warning = 2; + public static final int WARNING = 2; /** * Problem that the error marker represents * @see Problem */ private Problem problem; - - public ErrorMarker(Problem problem, int y, int type) { + + public LineMarker(Problem problem, int y, int type) { this.problem = problem; this.y = y; this.type = type; } - + /** * y co-ordinate of the marker */ @@ -64,7 +62,7 @@ public class ErrorMarker { return y; } - + /** * Type of marker: ErrorMarker.Error or ErrorMarker.Warning? */ @@ -72,7 +70,7 @@ public class ErrorMarker { return type; } - + /** * Problem that the error marker represents * @see Problem