use of processing.app.Problem in project processing by processing.
the class Editor method updateEditorStatus.
/**
* Updates editor status bar, depending on whether the caret is on an error
* line or not
*/
public void updateEditorStatus() {
Problem problem = findProblem(textarea.getCaretLine());
if (problem != null) {
int type = problem.isError() ? EditorStatus.CURSOR_LINE_ERROR : EditorStatus.CURSOR_LINE_WARNING;
statusMessage(problem.getMessage(), type);
} else {
switch(getStatusMode()) {
case EditorStatus.CURSOR_LINE_ERROR:
case EditorStatus.CURSOR_LINE_WARNING:
statusEmpty();
break;
}
}
}
use of processing.app.Problem in project processing by processing.
the class Editor method updateErrorTable.
/**
* Updates the error table in the Error Window.
*/
public void updateErrorTable(List<Problem> problems) {
if (errorTable != null) {
errorTable.clearRows();
for (Problem p : problems) {
String message = p.getMessage();
errorTable.addRow(p, message, sketch.getCode(p.getTabIndex()).getPrettyName(), Integer.toString(p.getLineNumber() + 1));
// Added +1 because lineNumbers internally are 0-indexed
}
}
}
use of processing.app.Problem in project processing by processing.
the class Editor method findProblem.
/**
* @return the Problem for the first error or warning on 'line'
*/
Problem findProblem(int line) {
int currentTab = getSketch().getCurrentCodeIndex();
return problems.stream().filter(p -> p.getTabIndex() == currentTab).filter(p -> {
int pStartLine = p.getLineNumber();
int pEndOffset = p.getStopOffset();
int pEndLine = textarea.getLineOfOffset(pEndOffset);
return line >= pStartLine && line <= pEndLine;
}).findFirst().orElse(null);
}
use of processing.app.Problem in project processing by processing.
the class PdeTextAreaPainter method paintErrorLine.
/**
* Paints the underline for an error/warning line
*/
protected void paintErrorLine(Graphics gfx, int line, int x) {
List<Problem> problems = getEditor().findProblems(line);
for (Problem problem : problems) {
int startOffset = problem.getStartOffset();
int stopOffset = problem.getStopOffset();
int lineOffset = textArea.getLineStartOffset(line);
int wiggleStart = Math.max(startOffset, lineOffset);
int wiggleStop = Math.min(stopOffset, textArea.getLineStopOffset(line));
int y = textArea.lineToY(line) + fm.getLeading() + fm.getMaxDescent();
try {
String badCode = null;
String goodCode = null;
try {
SyntaxDocument doc = textArea.getDocument();
badCode = doc.getText(wiggleStart, wiggleStop - wiggleStart);
goodCode = doc.getText(lineOffset, wiggleStart - lineOffset);
//log("paintErrorLine() LineText GC: " + goodCode);
//log("paintErrorLine() LineText BC: " + badCode);
} catch (BadLocationException bl) {
// log((ta.getLineStopOffset(line) - start - 1));
return;
}
int trimmedLength = badCode.trim().length();
int rightTrimmedLength = trimRight(badCode).length();
int leftTrimLength = rightTrimmedLength - trimmedLength;
// Fix offsets when bad code is just whitespace
if (trimmedLength == 0) {
leftTrimLength = 0;
rightTrimmedLength = badCode.length();
}
int x1 = textArea.offsetToX(line, goodCode.length() + leftTrimLength);
int x2 = textArea.offsetToX(line, goodCode.length() + rightTrimmedLength);
if (x1 == x2)
x2 += fm.stringWidth(" ");
int y1 = y + fm.getHeight() - 2;
if (line != problem.getLineNumber()) {
// on the following lines, wiggle extends to the left border
x1 = Editor.LEFT_GUTTER;
}
gfx.setColor(errorUnderlineColor);
if (problem.isWarning()) {
gfx.setColor(warningUnderlineColor);
}
paintSquiggle(gfx, y1, x1, x2);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of processing.app.Problem in project processing by processing.
the class PdeTextAreaPainter method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
int line = event.getY() / getFontMetrics().getHeight() + textArea.getFirstLine();
if (line >= 0 || line < textArea.getLineCount()) {
List<Problem> problems = getEditor().findProblems(line);
for (Problem problem : problems) {
int lineStart = textArea.getLineStartOffset(line);
int lineEnd = textArea.getLineStopOffset(line);
int errorStart = problem.getStartOffset();
int errorEnd = problem.getStopOffset() + 1;
int startOffset = Math.max(errorStart, lineStart) - lineStart;
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;
int x = event.getX();
if (x >= textArea.offsetToX(line, startOffset) && x <= textArea.offsetToX(line, stopOffset)) {
getEditor().statusToolTip(this, problem.getMessage(), problem.isError());
return super.getToolTipText(event);
}
}
}
setToolTipText(null);
return super.getToolTipText(event);
}
Aggregations