KickJava   Java API By Example, From Geeks To Geeks.

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


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

20
21 package org.armedbear.j;
22
23 public abstract class AbstractLine implements Line
24 {
25     private Line prev;
26     private Line next;
27     private int lineNumber = -1;
28     private int originalLineNumber = -1;
29     private int hidden;
30     private Annotation annotation;
31
32     public final synchronized Line previous()
33     {
34         return prev;
35     }
36
37     public final synchronized void setPrevious(Line line)
38     {
39         prev = line;
40     }
41
42     public final synchronized Line next()
43     {
44         return next;
45     }
46
47     public final synchronized void setNext(Line line)
48     {
49         next = line;
50     }
51
52     public final synchronized void insertAfter(Line line)
53     {
54         if (line != null) {
55             Line n = line.next();
56             setNext(n);
57             if (n != null)
58                 n.setPrevious(this);
59             line.setNext(this);
60             setPrevious(line);
61         } else
62             Debug.bug();
63     }
64
65     public final synchronized int lineNumber()
66     {
67         return lineNumber;
68     }
69
70     public final synchronized void setLineNumber(int n)
71     {
72         lineNumber = n;
73     }
74
75     public final synchronized int originalLineNumber()
76     {
77         return originalLineNumber;
78     }
79
80     public final synchronized void setOriginalLineNumber(int n)
81     {
82         originalLineNumber = n;
83     }
84
85     public int getHeight()
86     {
87         return Display.getCharHeight();
88     }
89
90     public int getWidth()
91     {
92         return 0;
93     }
94
95     // Derived classes override this!
96
public String JavaDoc getText()
97     {
98         return null;
99     }
100
101     // Derived classes override this!
102
public String JavaDoc getOriginalText()
103     {
104         return null;
105     }
106
107     // Derived classes override this!
108
public void setOriginalText(String JavaDoc s)
109     {
110         // Do nothing.
111
}
112
113     // Derived classes override this!
114
public boolean isModified()
115     {
116         return false;
117     }
118
119     // Derived classes override this!
120
public boolean isNew()
121     {
122         return false;
123     }
124
125     // Derived classes override this!
126
public void setNew(boolean b)
127     {
128         // Do nothing.
129
}
130
131     // Derived classes override this!
132
public boolean isSaved()
133     {
134         return false;
135     }
136
137     // Derived classes override this!
138
public void setSaved(boolean b)
139     {
140         // Do nothing.
141
}
142
143     // Derived classes override this!
144
public void unmodified()
145     {
146         // Do nothing.
147
}
148
149     // Returns offset (not column) of first non-whitespace character.
150
public int getIndentation()
151     {
152         String JavaDoc text = getText();
153         if (text == null)
154             return 0;
155         int limit = text.length();
156         for (int i = 0; i < limit; i++)
157             if (!Character.isWhitespace(text.charAt(i)))
158                 return i;
159         return limit;
160     }
161
162     public final boolean isHidden()
163     {
164         return hidden > 0;
165     }
166
167     public final void hide()
168     {
169         ++hidden;
170     }
171
172     public final void unhide()
173     {
174         --hidden;
175         if (Editor.isDebugEnabled() && hidden < 0)
176             Debug.bug("hidden < 0");
177     }
178
179     public final void show()
180     {
181         hidden = 0;
182     }
183
184     public final int getHidden()
185     {
186         return hidden;
187     }
188
189     public final void setHidden(int hidden)
190     {
191         this.hidden = hidden;
192     }
193
194     public final synchronized Line previousVisible()
195     {
196         Line line = previous();
197         while (line != null && line.isHidden())
198             line = line.previous();
199         return line;
200     }
201
202     public final synchronized Line nextVisible()
203     {
204         Line line = next();
205         while (line != null && line.isHidden())
206             line = line.next();
207         return line;
208     }
209
210     public final boolean isBefore(Line line)
211     {
212         return lineNumber < line.lineNumber();
213     }
214
215     // Derived classes override this!
216
public Line copy()
217     {
218         return null;
219     }
220
221     // Derived classes override this!
222
public void copy(Line line)
223     {
224         // Do nothing.
225
}
226
227     public final Annotation getAnnotation()
228     {
229         return annotation;
230     }
231
232     public final void setAnnotation(Annotation annotation)
233     {
234         this.annotation = annotation;
235     }
236
237     public final String JavaDoc toString()
238     {
239         FastStringBuffer sb = new FastStringBuffer();
240         sb.append("line ");
241         sb.append(lineNumber()+1);
242         String JavaDoc s = getText();
243         if (s != null) {
244             sb.append(" text = \"");
245             sb.append(s);
246             sb.append('"');
247         } else
248             sb.append(" text = null");
249         return sb.toString();
250     }
251 }
252
Popular Tags