001: /*
002: * CompilationErrorBuffer.java
003: *
004: * Copyright (C) 2003 Peter Graves
005: * $Id: CompilationErrorBuffer.java,v 1.3 2003/06/12 13:47:45 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import javax.swing.Icon;
025:
026: public abstract class CompilationErrorBuffer extends Buffer {
027: private CompilationError currentError;
028:
029: protected CompilationErrorBuffer() {
030: supportsUndo = false;
031: mode = PlainTextMode.getMode();
032: formatter = new PlainTextFormatter(this );
033: lineSeparator = System.getProperty("line.separator");
034: readOnly = true;
035: setTransient(true);
036: setProperty(Property.VERTICAL_RULE, 0);
037: setProperty(Property.SHOW_LINE_NUMBERS, false);
038: setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
039: setProperty(Property.HIGHLIGHT_BRACKETS, false);
040: setInitialized(true);
041: }
042:
043: public int load() {
044: if (!isLoaded()) {
045: if (getFirstLine() == null) {
046: try {
047: lockWrite();
048: } catch (InterruptedException e) {
049: Log.debug(e);
050: return LOAD_FAILED; // Shouldn't happen.
051: }
052: try {
053: appendLine("");
054: renumber();
055: } finally {
056: unlockWrite();
057: }
058: }
059: setLoaded(true);
060: }
061: return LOAD_COMPLETED;
062: }
063:
064: public CompilationError getCurrentError() {
065: return currentError;
066: }
067:
068: public void setCurrentError(CompilationError ce) {
069: currentError = ce;
070: }
071:
072: protected CompilationError nextError() {
073: Line line;
074: if (currentError != null) {
075: line = currentError.getErrorLine();
076: if (line != null)
077: line = line.next();
078: } else
079: line = getFirstLine();
080: while (line != null) {
081: CompilationError ce = CompilationError
082: .parseLineAsErrorMessage(line);
083: if (ce != null) {
084: currentError = ce;
085: return ce;
086: }
087: line = line.next();
088: }
089: return null;
090: }
091:
092: protected CompilationError previousError() {
093: Line line;
094: if (currentError != null) {
095: line = currentError.getErrorLine();
096: if (line != null)
097: line = line.previous();
098: } else
099: line = getLastLine();
100: while (line != null) {
101: CompilationError ce = CompilationError
102: .parseLineAsErrorMessage(line);
103: if (ce != null) {
104: currentError = ce;
105: return ce;
106: }
107: line = line.previous();
108: }
109: return null;
110: }
111:
112: public String getMessage() {
113: if (currentError != null) {
114: String message = currentError.getMessage();
115: if (message != null)
116: return message;
117: // Message on following line.
118: Line line = currentError.getErrorLine();
119: if (line != null && line.next() != null)
120: return line.next().trim();
121: }
122: return null;
123: }
124:
125: public boolean isModified() {
126: return false;
127: }
128:
129: // For the buffer list.
130: public Icon getIcon() {
131: return Utilities.getIconFromFile("jpty.png");
132: }
133: }
|