@@ -89,6 +89,12 @@ public void mouseMoved(final MouseEvent e) {
8989 }
9090
9191
92+ @ Override
93+ public void repaint () {
94+ recalculateMarkerPositions ();
95+ super .repaint ();
96+ }
97+
9298 public void paintComponent (Graphics g ) {
9399 g .setColor (backgroundColor );
94100 g .fillRect (0 , 0 , getWidth (), getHeight ());
@@ -117,29 +123,20 @@ synchronized public void updateErrorPoints(final List<Problem> problems) {
117123 new SwingWorker () {
118124 protected Object doInBackground () throws Exception {
119125 Sketch sketch = editor .getSketch ();
120- SketchCode code = sketch .getCurrentCode ();
121- int totalLines = 0 ;
122126 int currentTab = sketch .getCurrentCodeIndex ();
123- try {
124- totalLines = Util .countLines (code .getDocumentText ());
125- } catch (BadLocationException e ) {
126- e .printStackTrace ();
127- }
128127 errorPoints = new ArrayList <>();
129128
130129 // Each problem.getSourceLine() will have an extra line added because
131130 // of class declaration in the beginning as well as default imports
132131 synchronized (problems ) {
133132 for (Problem problem : problems ) {
134133 if (problem .getTabIndex () == currentTab ) {
135- // Ratio of error line to total lines
136- float y = (problem .getLineNumber () + 1 ) / ((float ) totalLines );
137- // Ratio multiplied by height of the error bar
138- y *= getHeight () - 15 ; // -15 is just a vertical offset
139- errorPoints .add (new LineMarker (problem , (int ) y , problem .isError ()));
134+ errorPoints .add (new LineMarker (problem , problem .isError ()));
140135 }
141136 }
142137 }
138+
139+ recalculateMarkerPositions ();
143140 return null ;
144141 }
145142
@@ -195,6 +192,31 @@ protected Object doInBackground() throws Exception {
195192 }
196193
197194
195+ private void recalculateMarkerPositions () {
196+ List <LineMarker > errorPoints = getErrorPoints ();
197+ if (errorPoints != null && errorPoints .size () > 0 ) {
198+ Sketch sketch = editor .getSketch ();
199+ SketchCode code = sketch .getCurrentCode ();
200+ int totalLines ;
201+ try {
202+ totalLines = Util .countLines (code .getDocumentText ());
203+ } catch (BadLocationException e ) {
204+ e .printStackTrace ();
205+ totalLines = 1 ; // do not divide by zero
206+ }
207+
208+ for (LineMarker m : errorPoints ) {
209+ // Ratio of error line to total lines
210+ float y = (m .getLineNumber () + 1 ) / ((float ) totalLines );
211+ // Ratio multiplied by height of the error bar
212+ y *= getHeight () - 15 ; // -15 is just a vertical offset
213+
214+ m .setY ((int ) y );
215+ }
216+ }
217+ }
218+
219+
198220 private LineMarker findClosestMarker (final int y ) {
199221 LineMarker closest = null ;
200222 int closestDist = Integer .MAX_VALUE ;
0 commit comments