| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,6 +89,12 @@ public void mouseMoved(final MouseEvent e) { | |||
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | + @Override | ||
| 93 | + public void repaint() { | ||
| 94 | + recalculateMarkerPositions(); | ||
| 95 | + super.repaint(); | ||
| 96 | + } | ||
| 97 | + | ||
| 92 | 98 | public void paintComponent(Graphics g) { | |
| 93 | 99 | g.setColor(backgroundColor); | |
| 94 | 100 | g.fillRect(0, 0, getWidth(), getHeight()); | |
@@ -117,29 +123,20 @@ synchronized public void updateErrorPoints(final List<Problem> problems) { | |||
| 117 | 123 | new SwingWorker() { | |
| 118 | 124 | protected Object doInBackground() throws Exception { | |
| 119 | 125 | Sketch sketch = editor.getSketch(); | |
| 120 | - SketchCode code = sketch.getCurrentCode(); | ||
| 121 | - int totalLines = 0; | ||
| 122 | 126 | int currentTab = sketch.getCurrentCodeIndex(); | |
| 123 | - try { | ||
| 124 | - totalLines = Util.countLines(code.getDocumentText()); | ||
| 125 | - } catch (BadLocationException e) { | ||
| 126 | - e.printStackTrace(); | ||
| 127 | - } | ||
| 128 | 127 | errorPoints = new ArrayList<>(); | |
| 129 | 128 | ||
| 130 | 129 | // Each problem.getSourceLine() will have an extra line added because | |
| 131 | 130 | // of class declaration in the beginning as well as default imports | |
| 132 | 131 | synchronized (problems) { | |
| 133 | 132 | for (Problem problem : problems) { | |
| 134 | 133 | 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())); | ||
| 140 | 135 | } | |
| 141 | 136 | } | |
| 142 | 137 | } | |
| 138 | + | ||
| 139 | + recalculateMarkerPositions(); | ||
| 143 | 140 | return null; | |
| 144 | 141 | } | |
| 145 | 142 | ||
@@ -195,6 +192,31 @@ protected Object doInBackground() throws Exception { | |||
| 195 | 192 | } | |
| 196 | 193 | ||
| 197 | 194 | ||
| 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 | + | ||
| 198 | 220 | private LineMarker findClosestMarker(final int y) { | |
| 199 | 221 | LineMarker closest = null; | |
| 200 | 222 | int closestDist = Integer.MAX_VALUE; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,13 +48,20 @@ public class LineMarker { | |||
| 48 | 48 | private Problem problem; | |
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | - public LineMarker(Problem problem, int y, boolean error) { | ||
| 51 | + public LineMarker(Problem problem, boolean error) { | ||
| 52 | 52 | this.problem = problem; | |
| 53 | - this.y = y; | ||
| 54 | 53 | this.type = error ? ERROR : WARNING; | |
| 55 | 54 | } | |
| 56 | 55 | ||
| 57 | 56 | ||
| 57 | + /** | ||
| 58 | + * set y co-ordinate of the marker | ||
| 59 | + */ | ||
| 60 | + public void setY(int y) { | ||
| 61 | + this.y = y; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 58 | 65 | /** | |
| 59 | 66 | * y co-ordinate of the marker | |
| 60 | 67 | */ | |
@@ -63,6 +70,14 @@ public int getY() { | |||
| 63 | 70 | } | |
| 64 | 71 | ||
| 65 | 72 | ||
| 73 | + /** | ||
| 74 | + * line number of the marker | ||
| 75 | + */ | ||
| 76 | + public int getLineNumber() { | ||
| 77 | + return problem.getLineNumber(); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + | ||
| 66 | 81 | /** | |
| 67 | 82 | * Type of marker: ErrorMarker.Error or ErrorMarker.Warning? | |
| 68 | 83 | */ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments