Search in sources :

Example 1 with Problem

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;
        }
    }
}
Also used : Problem(processing.app.Problem) Point(java.awt.Point) java.awt.print(java.awt.print)

Example 2 with Problem

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
        }
    }
}
Also used : Problem(processing.app.Problem)

Example 3 with Problem

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);
}
Also used : Color(java.awt.Color) Platform(processing.app.Platform) Point(java.awt.Point) Timer(java.util.Timer) Stack(java.util.Stack) ArrayList(java.util.ArrayList) Formatter(processing.app.Formatter) Mode(processing.app.Mode) Preferences(processing.app.Preferences) BorderLayout(java.awt.BorderLayout) TimerTask(java.util.TimerTask) SketchCode(processing.app.SketchCode) Method(java.lang.reflect.Method) SketchException(processing.app.SketchException) EventQueue(java.awt.EventQueue) Problem(processing.app.Problem) Messages(processing.app.Messages) Sketch(processing.app.Sketch) Frame(java.awt.Frame) processing.core(processing.core) Image(java.awt.Image) Font(java.awt.Font) Window(java.awt.Window) javax.swing.event(javax.swing.event) javax.swing.text(javax.swing.text) Component(java.awt.Component) Collectors(java.util.stream.Collectors) processing.app.syntax(processing.app.syntax) Dimension(java.awt.Dimension) List(java.util.List) Language(processing.app.Language) java.awt.print(java.awt.print) javax.swing.undo(javax.swing.undo) RunnerListener(processing.app.RunnerListener) java.awt.datatransfer(java.awt.datatransfer) java.io(java.io) javax.swing.text.html(javax.swing.text.html) Base(processing.app.Base) java.awt.event(java.awt.event) javax.swing.plaf.basic(javax.swing.plaf.basic) Collections(java.util.Collections) Util(processing.app.Util) ContributionManager(processing.app.contrib.ContributionManager) javax.swing(javax.swing) Point(java.awt.Point) java.awt.print(java.awt.print)

Example 4 with Problem

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();
        }
    }
}
Also used : Problem(processing.app.Problem) BadLocationException(javax.swing.text.BadLocationException) BadLocationException(javax.swing.text.BadLocationException)

Example 5 with Problem

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);
}
Also used : Problem(processing.app.Problem)

Aggregations

Problem (processing.app.Problem)8 Point (java.awt.Point)2 java.awt.print (java.awt.print)2 Sketch (processing.app.Sketch)2 SketchCode (processing.app.SketchCode)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 EventQueue (java.awt.EventQueue)1 Font (java.awt.Font)1 Frame (java.awt.Frame)1 Image (java.awt.Image)1 Window (java.awt.Window)1 java.awt.datatransfer (java.awt.datatransfer)1 java.awt.event (java.awt.event)1 java.io (java.io)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1