Move LineMarker into MarkerColumn

This commit is contained in:
Jakub Valtar
2016-05-06 12:48:15 +02:00
parent 7e1517f4b7
commit 27a61d05a2
2 changed files with 27 additions and 84 deletions

View File

@@ -38,7 +38,6 @@ import processing.app.Sketch;
import processing.app.SketchCode;
import processing.app.ui.Editor;
import processing.core.PApplet;
import processing.mode.java.pdex.LineMarker;
import processing.mode.java.pdex.Problem;
@@ -99,13 +98,14 @@ public class MarkerColumn extends JPanel {
int currentTabIndex = editor.getSketch().getCurrentCodeIndex();
for (LineMarker m : errorPoints) {
if (m.getProblem().getTabIndex() != currentTabIndex) continue;
if (m.getType() == LineMarker.ERROR) {
Problem problem = m.problem;
if (problem.getTabIndex() != currentTabIndex) continue;
if (problem.isError()) {
g.setColor(errorColor);
} else {
g.setColor(warningColor);
}
g.drawLine(2, m.getY(), getWidth() - 2, m.getY());
g.drawLine(2, m.y, getWidth() - 2, m.y);
}
}
@@ -123,7 +123,7 @@ public class MarkerColumn extends JPanel {
try {
LineMarker m = findClosestMarker(y);
if (m != null) {
editor.highlight(m.getProblem());
editor.highlight(m.problem);
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -144,7 +144,7 @@ public class MarkerColumn extends JPanel {
try {
LineMarker m = findClosestMarker(y);
if (m != null) {
Problem p = m.getProblem();
Problem p = m.problem;
// String kind = p.isError() ?
// Language.text("editor.status.error") :
// Language.text("editor.status.warning");
@@ -172,13 +172,14 @@ public class MarkerColumn extends JPanel {
int height = getHeight() - topMargin - bottomMargin;
for (LineMarker m : errorPoints) {
if (m.getProblem().getTabIndex() != currentTab) continue;
Problem problem = m.problem;
if (problem.getTabIndex() != currentTab) continue;
// Ratio of error line to total lines
float ratio = (m.getLineNumber() + 1) / ((float) totalLines);
float ratio = (problem.getLineNumber() + 1) / ((float) totalLines);
// Ratio multiplied by height of the error bar
float y = topMargin + ratio * height;
m.setY((int) y);
m.y = (int) y;
}
}
}
@@ -188,7 +189,7 @@ public class MarkerColumn extends JPanel {
LineMarker closest = null;
int closestDist = Integer.MAX_VALUE;
for (LineMarker m : errorPoints) {
int dist = Math.abs(y - m.getY());
int dist = Math.abs(y - m.y);
if (dist < 3 && dist < closestDist) {
closest = m;
closestDist = dist;
@@ -206,4 +207,20 @@ public class MarkerColumn extends JPanel {
public Dimension getMinimumSize() {
return new Dimension(Editor.RIGHT_GUTTER, super.getMinimumSize().height);
}
/**
* Line markers displayed on the Error Column.
*/
private static class LineMarker {
/** y co-ordinate of the marker */
int y;
/** Problem that the error marker represents */
final Problem problem;
LineMarker(Problem problem) {
this.problem = problem;
}
}
}

View File

@@ -1,74 +0,0 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package processing.mode.java.pdex;
/**
* Line markers displayed on the Error Column.
*/
public class LineMarker {
/** y co-ordinate of the marker */
private int y;
/** Type of marker: Error or Warning? */
private int type = -1;
/** Error Type constant */
public static final int ERROR = 1;
/** Warning Type constant */
public static final int WARNING = 2;
/** Problem that the error marker represents */
private Problem problem;
public LineMarker(Problem problem) {
this.problem = problem;
this.type = problem.isError() ? ERROR : WARNING;
}
public void setY(int y) {
this.y = y;
}
public int getY() {
return y;
}
public int getLineNumber() {
return problem.getLineNumber();
}
/** @return ERROR or WARNING */
public int getType() {
return type;
}
public Problem getProblem() {
return problem;
}
}