KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > DJDocument


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32 END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model;
35
36 import edu.rice.cs.drjava.model.definitions.reducedmodel.*;
37 import edu.rice.cs.util.text.SwingDocumentInterface;
38 import edu.rice.cs.util.OperationCanceledException;
39 import edu.rice.cs.drjava.model.definitions.ClassNameNotFoundException;
40
41 import java.util.Vector JavaDoc;
42 import javax.swing.text.AttributeSet JavaDoc;
43 import javax.swing.text.BadLocationException JavaDoc;
44 import javax.swing.text.StyledDocument JavaDoc;
45 import javax.swing.ProgressMonitor JavaDoc;
46
47 /** Interface to be collectively shared by the Definitions Document, Open Definitions Document,
48  * and the Interactions Document. Collectively represents a DrJava Document
49  */

50 public interface DJDocument extends SwingDocumentInterface {
51   
52   /** Gets the indent level.
53    * @return the indent level
54    */

55   public int getIndent();
56   
57   /** Set the indent to a particular number of spaces.
58    * @param indent the size of indent that you want for the document
59    */

60   public void setIndent(int indent);
61   
62   /**
63    * Return all highlight status info for text between start and end.
64    * This should collapse adjoining blocks with the same status into one.
65    */

66   public Vector JavaDoc<HighlightStatus> getHighlightStatus(int start, int end);
67   
68   /**
69    * Get the current location of the cursor in the document.
70    * Unlike the usual swing document model, which is stateless, because of our implementation
71    * of the underlying reduced model, we need to keep track of the current location.
72    * @return where the cursor is as the number of characters into the document
73    */

74   public int getCurrentLocation();
75   
76   /**
77    * Change the current location of the document
78    * @param loc the new absolute location
79    */

80   public void setCurrentLocation(int loc);
81   
82   /**
83    * The actual cursor movement logic. Helper for setCurrentLocation(int).
84    * @param dist the distance from the current location to the new location.
85    */

86   public void move(int dist);
87   
88   /**
89    * Forwarding method to find the match for the closing brace
90    * immediately to the left, assuming there is such a brace.
91    * @return the relative distance backwards to the offset before
92    * the matching brace.
93    */

94   public int balanceBackward();
95   
96   /**
97    * Forwarding method to find the match for the open brace
98    * immediately to the right, assuming there is such a brace.
99    * @return the relative distance forwards to the offset after
100    * the matching brace.
101    */

102   public int balanceForward();
103   
104   /** Returns the indent information for the current location. */
105   public IndentInfo getIndentInformation();
106   
107   public ReducedModelState stateAtRelLocation(int dist);
108   
109   public ReducedModelState getStateAtCurrent();
110   
111   public void resetReducedModelLocation();
112   
113   /**
114    * Searching backwards, finds the position of the enclosing brace.
115    * NB: ignores comments.
116    * @param pos Position to start from
117    * @param opening opening brace character
118    * @param closing closing brace character
119    * @return position of enclosing squiggly brace, or ERROR_INDEX if beginning
120    * of document is reached.
121    */

122   public int findPrevEnclosingBrace(int pos, char opening, char closing) throws BadLocationException JavaDoc;
123   
124   /**
125    * Searching forwards, finds the position of the enclosing brace.
126    * NB: ignores comments.
127    * @param pos Position to start from
128    * @param opening opening brace character
129    * @param closing closing brace character
130    * @return position of enclosing squiggly brace, or ERROR_INDEX if beginning
131    * of document is reached.
132    */

133   public int findNextEnclosingBrace(int pos, char opening, char closing) throws BadLocationException JavaDoc;
134   
135   /**
136    *
137    * Searching backwards, finds the position of the first character that is one
138    * of the given delimiters. Does not look for delimiters inside paren phrases.
139    * (eg. skips semicolons used inside for statements.)
140    * NB: ignores comments.
141    * @param pos Position to start from
142    * @param delims array of characters to search for
143    * @return position of first matching delimiter, or ERROR_INDEX if beginning
144    * of document is reached.
145    */

146   public int findPrevDelimiter(int pos, char[] delims) throws BadLocationException JavaDoc;
147   
148   /**
149    * Searching backwards, finds the position of the first character that is one
150    * of the given delimiters. Will not look for delimiters inside a paren
151    * phrase if skipParenPhrases is true.
152    * NB: ignores comments.
153    * @param pos Position to start from
154    * @param delims array of characters to search for
155    * @param skipParenPhrases whether to look for delimiters inside paren phrases
156    * (eg. semicolons in a for statement)
157    * @return position of first matching delimiter, or ERROR_INDEX if beginning
158    * of document is reached.
159    */

160   public int findPrevDelimiter(int pos, char[] delims, boolean skipParenPhrases) throws BadLocationException JavaDoc;
161   
162   /**
163    * This function finds the given character in the same statement as the given
164    * position, and before the given position. It is used by QuestionExistsCharInStmt and
165    * QuestionExistsCharInPrevStmt
166    */

167   public boolean findCharInStmtBeforePos(char findChar, int position);
168   
169   /**
170    * Finds the position of the first non-whitespace character before pos.
171    * NB: Skips comments and all whitespace, including newlines
172    * @param pos Position to start from
173    * @param whitespace chars considered as white space
174    * @return position of first non-whitespace character before pos,
175    * or ERROR_INDEX if begining of document is reached
176    */

177   public int findPrevCharPos(int pos, char[] whitespace) throws BadLocationException JavaDoc;
178   
179   /** Default indentation - uses OTHER flag and no progress indicator.
180    * @param selStart the offset of the initial character of the region to indent
181    * @param selEnd the offset of the last character of the region to indent
182    */

183   public void indentLines(int selStart, int selEnd);
184   
185   /** Parameterized indentation for special-case handling.
186    * @param selStart the offset of the initial character of the region to indent
187    * @param selEnd the offset of the last character of the region to indent
188    * @param reason a flag from {@link edu.rice.cs.drjava.model.definitions.indent.Indenter Indenter}
189    * to indicate the reason for the indent (indent logic may vary slightly based on the trigger action)
190    * @param pm used to display progress, null if no reporting is desired
191    */

192   public void indentLines(int selStart, int selEnd, int reason, ProgressMonitor JavaDoc pm)
193     throws OperationCanceledException;
194   
195   /**
196    * Returns the "intelligent" beginning of line. If currPos is to
197    * the right of the first non-whitespace character, the position of the
198    * first non-whitespace character is returned. If currPos is at or
199    * to the left of the first non-whitespace character, the beginning of
200    * the line is returned.
201    * @param currPos A position on the current line
202    */

203   public int getIntelligentBeginLinePos(int currPos) throws BadLocationException JavaDoc;;
204   
205   /**
206    * Returns the indent level of the start of the statement
207    * that the cursor is on. Uses a default set of delimiters.
208    * (';', '{', '}') and a default set of whitespace characters
209    * (' ', '\t', n', ',')
210    * @param pos Cursor position
211    */

212   public String JavaDoc getIndentOfCurrStmt(int pos) throws BadLocationException JavaDoc;
213   
214   /**
215    * Returns the indent level of the start of the statement
216    * that the cursor is on. Uses a default set of whitespace characters.
217    * (' ', '\t', '\n', ',')
218    * @param pos Cursor position
219    */

220   public String JavaDoc getIndentOfCurrStmt(int pos, char[] delims) throws BadLocationException JavaDoc;
221   
222   /**
223    * Returns the indent level of the start of the statement
224    * that the cursor is on.
225    * @param pos Cursor position
226    * @param delims Delimiter characters denoting end of statement
227    * @param whitespace characters to skip when looking for beginning of next statement
228    */

229   public String JavaDoc getIndentOfCurrStmt(int pos, char[] delims, char[] whitespace)
230      throws BadLocationException JavaDoc;
231   
232   /**
233    * Determines if the given character exists on the line where
234    * the given cursor position is. Does not search in quotes or comments.
235    * <p>
236    * <b>Does not work if character being searched for is a '/' or a '*'</b>
237    * @param pos Cursor position
238    * @param findChar Character to search for
239    * @return true if this node's rule holds.
240    */

241   public int findCharOnLine(int pos, char findChar);
242   
243   /**
244    * Returns the absolute position of the beginning of the
245    * current line. (Just after most recent newline, or DOCSTART)
246    * Doesn't ignore comments.
247    * @param pos Any position on the current line
248    * @return position of the beginning of this line
249    */

250   public int getLineStartPos(int pos);
251   
252   /**
253    * Returns the absolute position of the end of the current
254    * line. (At the next newline, or the end of the document.)
255    * @param pos Any position on the current line
256    * @return position of the end of this line
257    */

258   public int getLineEndPos(int pos);
259   
260   /**
261    * Returns the absolute position of the first non-whitespace character
262    * on the current line.
263    * NB: Doesn't ignore comments.
264    * @param pos position on the line
265    * @return position of first non-whitespace character on this line, or the end
266    * of the line if no non-whitespace character is found.
267    */

268   public int getLineFirstCharPos(int pos) throws BadLocationException JavaDoc;
269   
270   /**
271    * Finds the position of the first non-whitespace character after pos.
272    * NB: Skips comments and all whitespace, including newlines
273    * @param pos Position to start from
274    * @return position of first non-whitespace character after pos,
275    * or ERROR_INDEX if end of document is reached
276    */

277   public int getFirstNonWSCharPos(int pos) throws BadLocationException JavaDoc;
278   
279   /**
280    * Similar to the single-argument version, but allows including comments.
281    * @param pos Position to start from
282    * @param acceptComments if true, find non-whitespace chars in comments
283    * @return position of first non-whitespace character after pos,
284    * or ERROR_INDEX if end of document is reached
285    */

286   public int getFirstNonWSCharPos(int pos, boolean acceptComments)
287     throws BadLocationException JavaDoc;
288   
289   /**
290    * Finds the position of the first non-whitespace character after pos.
291    * NB: Skips comments and all whitespace, including newlines
292    * @param pos Position to start from
293    * @param whitespace array of whitespace chars to ignore
294    * @param acceptComments if true, find non-whitespace chars in comments
295    * @return position of first non-whitespace character after pos,
296    * or ERROR_INDEX if end of document is reached
297    */

298   public int getFirstNonWSCharPos (int pos, char[] whitespace, boolean acceptComments)
299      throws BadLocationException JavaDoc;
300   
301   public int findPrevNonWSCharPos(int pos) throws BadLocationException JavaDoc;
302   
303   /**
304    * Returns true if the given position is inside a paren phrase.
305    * @param pos the position we're looking at
306    * @return true if pos is immediately inside parentheses
307    */

308   public boolean posInParenPhrase(int pos);
309   
310   /** Returns true if the reduced model's current position is inside a paren phrase.
311    * @return true if pos is immediately inside parentheses
312    */

313   public boolean posInParenPhrase();
314   
315   /** Gets the number of whitespace characters between the current location and the rest of the document or the
316    * first non-whitespace character, whichever comes first.
317    * @return the number of whitespace characters
318    */

319   public int getWhiteSpace();
320   
321   /** Sets text between previous newline and first non-whitespace character of the line containing pos to tab.
322    * @param tab String to be placed between previous newline and first non-whitespace character
323    */

324   public void setTab(String JavaDoc tab, int pos);
325   
326   /** Inserts a string of text into the document. It turns out that this is not where we should do custom processing
327    * of the insert; that is done in {@link AbstractDJDocument#insertUpdate}.
328    */

329   public void insertString(int offset, String JavaDoc str, AttributeSet JavaDoc a)
330     throws BadLocationException JavaDoc;
331   
332   /** Removes a block of text from the specified location. We don't update the reduced model here; that happens
333    * in {@link AbstractDJDocument#removeUpdate}.
334    */

335   public void remove(int offset, int len) throws BadLocationException JavaDoc;
336   
337   /** Gets the entire text of the document. Without this operation, a client must use locking to perform this
338    * task safely.
339    */

340   public String JavaDoc getText();
341   
342   /** Clears the entire text of the document. Without this operation, a client must use locking to perform this
343    * task safely.
344    */

345   public void clear();
346   
347   /* Locking operations */
348   
349   /** Swing-style acquireReadLock(). */
350   public void acquireReadLock();
351   
352   /** Swing-style releaseReadLock(). */
353   public void releaseReadLock();
354
355   /** Swing-style writeLock(). */
356   public void acquireWriteLock();
357   
358   /** Swing-style writeUnlock(). */
359   public void releaseWriteLock();
360 }
Popular Tags