Skip to content

Commit efefa88

Browse files
committed
Recalculate positions in error marker column on resize
Fixes processing#3619
1 parent cf7cb8e commit efefa88

2 files changed

Lines changed: 51 additions & 14 deletions

File tree

‎java/src/processing/mode/java/MarkerColumn.java‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

‎java/src/processing/mode/java/pdex/LineMarker.java‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,20 @@ public class LineMarker {
4848
private Problem problem;
4949

5050

51-
public LineMarker(Problem problem, int y, boolean error) {
51+
public LineMarker(Problem problem, boolean error) {
5252
this.problem = problem;
53-
this.y = y;
5453
this.type = error ? ERROR : WARNING;
5554
}
5655

5756

57+
/**
58+
* set y co-ordinate of the marker
59+
*/
60+
public void setY(int y) {
61+
this.y = y;
62+
}
63+
64+
5865
/**
5966
* y co-ordinate of the marker
6067
*/
@@ -63,6 +70,14 @@ public int getY() {
6370
}
6471

6572

73+
/**
74+
* line number of the marker
75+
*/
76+
public int getLineNumber() {
77+
return problem.getLineNumber();
78+
}
79+
80+
6681
/**
6782
* Type of marker: ErrorMarker.Error or ErrorMarker.Warning?
6883
*/

0 commit comments

Comments
 (0)