001: /*
002: * AbstractLine.java
003: *
004: * Copyright (C) 1999-2002 Peter Graves
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: */
020:
021: package org.armedbear.j;
022:
023: public abstract class AbstractLine implements Line {
024: private Line prev;
025: private Line next;
026: private int lineNumber = -1;
027: private int originalLineNumber = -1;
028: private int hidden;
029: private Annotation annotation;
030:
031: public final synchronized Line previous() {
032: return prev;
033: }
034:
035: public final synchronized void setPrevious(Line line) {
036: prev = line;
037: }
038:
039: public final synchronized Line next() {
040: return next;
041: }
042:
043: public final synchronized void setNext(Line line) {
044: next = line;
045: }
046:
047: public final synchronized void insertAfter(Line line) {
048: if (line != null) {
049: Line n = line.next();
050: setNext(n);
051: if (n != null)
052: n.setPrevious(this );
053: line.setNext(this );
054: setPrevious(line);
055: } else
056: Debug.bug();
057: }
058:
059: public final synchronized int lineNumber() {
060: return lineNumber;
061: }
062:
063: public final synchronized void setLineNumber(int n) {
064: lineNumber = n;
065: }
066:
067: public final synchronized int originalLineNumber() {
068: return originalLineNumber;
069: }
070:
071: public final synchronized void setOriginalLineNumber(int n) {
072: originalLineNumber = n;
073: }
074:
075: public int getHeight() {
076: return Display.getCharHeight();
077: }
078:
079: public int getWidth() {
080: return 0;
081: }
082:
083: // Derived classes override this!
084: public String getText() {
085: return null;
086: }
087:
088: // Derived classes override this!
089: public String getOriginalText() {
090: return null;
091: }
092:
093: // Derived classes override this!
094: public void setOriginalText(String s) {
095: // Do nothing.
096: }
097:
098: // Derived classes override this!
099: public boolean isModified() {
100: return false;
101: }
102:
103: // Derived classes override this!
104: public boolean isNew() {
105: return false;
106: }
107:
108: // Derived classes override this!
109: public void setNew(boolean b) {
110: // Do nothing.
111: }
112:
113: // Derived classes override this!
114: public boolean isSaved() {
115: return false;
116: }
117:
118: // Derived classes override this!
119: public void setSaved(boolean b) {
120: // Do nothing.
121: }
122:
123: // Derived classes override this!
124: public void unmodified() {
125: // Do nothing.
126: }
127:
128: // Returns offset (not column) of first non-whitespace character.
129: public int getIndentation() {
130: String text = getText();
131: if (text == null)
132: return 0;
133: int limit = text.length();
134: for (int i = 0; i < limit; i++)
135: if (!Character.isWhitespace(text.charAt(i)))
136: return i;
137: return limit;
138: }
139:
140: public final boolean isHidden() {
141: return hidden > 0;
142: }
143:
144: public final void hide() {
145: ++hidden;
146: }
147:
148: public final void unhide() {
149: --hidden;
150: if (Editor.isDebugEnabled() && hidden < 0)
151: Debug.bug("hidden < 0");
152: }
153:
154: public final void show() {
155: hidden = 0;
156: }
157:
158: public final int getHidden() {
159: return hidden;
160: }
161:
162: public final void setHidden(int hidden) {
163: this .hidden = hidden;
164: }
165:
166: public final synchronized Line previousVisible() {
167: Line line = previous();
168: while (line != null && line.isHidden())
169: line = line.previous();
170: return line;
171: }
172:
173: public final synchronized Line nextVisible() {
174: Line line = next();
175: while (line != null && line.isHidden())
176: line = line.next();
177: return line;
178: }
179:
180: public final boolean isBefore(Line line) {
181: return lineNumber < line.lineNumber();
182: }
183:
184: // Derived classes override this!
185: public Line copy() {
186: return null;
187: }
188:
189: // Derived classes override this!
190: public void copy(Line line) {
191: // Do nothing.
192: }
193:
194: public final Annotation getAnnotation() {
195: return annotation;
196: }
197:
198: public final void setAnnotation(Annotation annotation) {
199: this .annotation = annotation;
200: }
201:
202: public final String toString() {
203: FastStringBuffer sb = new FastStringBuffer();
204: sb.append("line ");
205: sb.append(lineNumber() + 1);
206: String s = getText();
207: if (s != null) {
208: sb.append(" text = \"");
209: sb.append(s);
210: sb.append('"');
211: } else
212: sb.append(" text = null");
213: return sb.toString();
214: }
215: }
|