KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > CompilationErrorBuffer


1 /*
2  * CompilationErrorBuffer.java
3  *
4  * Copyright (C) 2003 Peter Graves
5  * $Id: CompilationErrorBuffer.java,v 1.3 2003/06/12 13:47:45 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import javax.swing.Icon JavaDoc;
25
26 public abstract class CompilationErrorBuffer extends Buffer
27 {
28     private CompilationError currentError;
29
30     protected CompilationErrorBuffer()
31     {
32         supportsUndo = false;
33         mode = PlainTextMode.getMode();
34         formatter = new PlainTextFormatter(this);
35         lineSeparator = System.getProperty("line.separator");
36         readOnly = true;
37         setTransient(true);
38         setProperty(Property.VERTICAL_RULE, 0);
39         setProperty(Property.SHOW_LINE_NUMBERS, false);
40         setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
41         setProperty(Property.HIGHLIGHT_BRACKETS, false);
42         setInitialized(true);
43     }
44
45     public int load()
46     {
47         if (!isLoaded()) {
48             if (getFirstLine() == null) {
49                 try {
50                     lockWrite();
51                 }
52                 catch (InterruptedException JavaDoc e) {
53                     Log.debug(e);
54                     return LOAD_FAILED; // Shouldn't happen.
55
}
56                 try {
57                     appendLine("");
58                     renumber();
59                 }
60                 finally {
61                     unlockWrite();
62                 }
63             }
64             setLoaded(true);
65         }
66         return LOAD_COMPLETED;
67     }
68
69     public CompilationError getCurrentError()
70     {
71         return currentError;
72     }
73
74     public void setCurrentError(CompilationError ce)
75     {
76         currentError = ce;
77     }
78
79     protected CompilationError nextError()
80     {
81         Line line;
82         if (currentError != null) {
83             line = currentError.getErrorLine();
84             if (line != null)
85                 line = line.next();
86         } else
87             line = getFirstLine();
88         while (line != null) {
89             CompilationError ce =
90                 CompilationError.parseLineAsErrorMessage(line);
91             if (ce != null) {
92                 currentError = ce;
93                 return ce;
94             }
95             line = line.next();
96         }
97         return null;
98     }
99
100     protected CompilationError previousError()
101     {
102         Line line;
103         if (currentError != null) {
104             line = currentError.getErrorLine();
105             if (line != null)
106                 line = line.previous();
107         } else
108             line = getLastLine();
109         while (line != null) {
110             CompilationError ce =
111                 CompilationError.parseLineAsErrorMessage(line);
112             if (ce != null) {
113                 currentError = ce;
114                 return ce;
115             }
116             line = line.previous();
117         }
118         return null;
119     }
120
121     public String JavaDoc getMessage()
122     {
123         if (currentError != null) {
124             String JavaDoc message = currentError.getMessage();
125             if (message != null)
126                 return message;
127             // Message on following line.
128
Line line = currentError.getErrorLine();
129             if (line != null && line.next() != null)
130                 return line.next().trim();
131         }
132         return null;
133     }
134
135     public boolean isModified()
136     {
137         return false;
138     }
139
140     // For the buffer list.
141
public Icon JavaDoc getIcon()
142     {
143         return Utilities.getIconFromFile("jpty.png");
144     }
145 }
146
Popular Tags