From 68aa116c0b99cdc4bf2dda1512e7f5196191117f Mon Sep 17 00:00:00 2001 From: Pawel Golinski Date: Tue, 23 Feb 2016 14:55:38 +0100 Subject: [PATCH 1/2] Move updateErrorPoints background work to UI thread --- .../processing/mode/java/MarkerColumn.java | 50 ++++++------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/java/src/processing/mode/java/MarkerColumn.java b/java/src/processing/mode/java/MarkerColumn.java index ae883004c..42866befe 100644 --- a/java/src/processing/mode/java/MarkerColumn.java +++ b/java/src/processing/mode/java/MarkerColumn.java @@ -32,7 +32,6 @@ import java.util.Collections; import java.util.List; import javax.swing.JPanel; -import javax.swing.SwingWorker; import javax.swing.text.BadLocationException; import processing.app.Mode; @@ -115,40 +114,21 @@ public class MarkerColumn extends JPanel { } - synchronized public void updateErrorPoints(final List problems) { - // NOTE: ErrorMarkers are calculated for the present tab only Error Marker - // index in the arraylist is LOCALIZED for current tab. Also, update is in - // the UI thread via SwingWorker to prevent concurrency issues. [Manindra] - try { - new SwingWorker() { - protected Object doInBackground() throws Exception { - Sketch sketch = editor.getSketch(); - int currentTab = sketch.getCurrentCodeIndex(); - errorPoints = new ArrayList<>(); - - // 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) { - errorPoints.add(new LineMarker(problem, problem.isError())); - } - } - } - - recalculateMarkerPositions(); - return null; - } - - protected void done() { - repaint(); - editor.getErrorChecker().updateEditorStatus(); - } - }.execute(); - - } catch (Exception ex) { - ex.printStackTrace(); - } + public void updateErrorPoints(final List problems) { + // NOTE: ErrorMarkers are calculated for the present tab only Error Marker + // index in the arraylist is LOCALIZED for current tab. + Sketch sketch = editor.getSketch(); + int currentTab = sketch.getCurrentCodeIndex(); + errorPoints = Collections.synchronizedList(new ArrayList()); + // Each problem.getSourceLine() will have an extra line added because + // of class declaration in the beginning as well as default imports + for (Problem problem : problems) { + if (problem.getTabIndex() == currentTab) { + errorPoints.add(new LineMarker(problem, problem.isError())); + } + } + repaint(); + editor.getErrorChecker().updateEditorStatus(); } From 749a4f287a546bfb3e79185f618ab55f9e111383 Mon Sep 17 00:00:00 2001 From: Pawel Golinski Date: Wed, 24 Feb 2016 13:55:30 +0100 Subject: [PATCH 2/2] Use normal ArrayList instead of synchronizedList for errorPoints --- java/src/processing/mode/java/MarkerColumn.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java/src/processing/mode/java/MarkerColumn.java b/java/src/processing/mode/java/MarkerColumn.java index 42866befe..fea97eb0c 100644 --- a/java/src/processing/mode/java/MarkerColumn.java +++ b/java/src/processing/mode/java/MarkerColumn.java @@ -62,8 +62,7 @@ public class MarkerColumn extends JPanel { private Color warningColor; // Stores error markers displayed PER TAB along the error bar. - private List errorPoints = - Collections.synchronizedList(new ArrayList()); + private List errorPoints = new ArrayList(); public MarkerColumn(JavaEditor editor, int height) { @@ -119,7 +118,7 @@ public class MarkerColumn extends JPanel { // index in the arraylist is LOCALIZED for current tab. Sketch sketch = editor.getSketch(); int currentTab = sketch.getCurrentCodeIndex(); - errorPoints = Collections.synchronizedList(new ArrayList()); + errorPoints.clear(); // Each problem.getSourceLine() will have an extra line added because // of class declaration in the beginning as well as default imports for (Problem problem : problems) {