KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > util > text > EditDocumentInterface


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.util.text;
35
36 import java.awt.print.Pageable JavaDoc;
37 import java.awt.print.PrinterException JavaDoc;
38 import java.io.Serializable JavaDoc;
39
40 /** Provides a toolkit-independent way to interact with a console document. Allows components to use
41  * documents that can be supplied by Swing, SWT (Eclipse), or other toolkits. The document also has the
42  * ability to restrict edits based on a conditional object, unless a separate method is called
43  * to force the edit.
44  *
45  * @version $Id: EditDocumentInterface.java 4035 2006-11-17 15:19:13Z rcartwright $
46  */

47 public interface EditDocumentInterface extends ReadersWritersLocking, Serializable JavaDoc {
48
49   /** Gets the object which can determine whether an insert or remove edit should be applied, based on the inputs.
50    * @return an Object to determine legality of inputs
51    */

52   public DocumentEditCondition getEditCondition();
53
54   /** Provides an object which can determine whether an insert or remove edit should be applied, based on the inputs.
55    * @param condition Object to determine legality of inputs
56    */

57   public void setEditCondition(DocumentEditCondition condition);
58
59   /** Inserts a string into the document at the given offset and the given named style, if the edit condition allows it.
60    * @param offs Offset into the document
61    * @param str String to be inserted
62    * @param style Name of the style to use. Must have been added using addStyle.
63    * @throws EditDocumentException if the offset is illegal
64    */

65   public void insertText(int offs, String JavaDoc str, String JavaDoc style);
66
67   /** Inserts a string into the document at the given offset and named style, regardless of the edit condition.
68    * @param offs Offset into the document
69    * @param str String to be inserted
70    * @param style Name of the style to use. Must have been
71    * added using addStyle.
72    * @throws EditDocumentException if the offset is illegal
73    */

74   public void forceInsertText(int offs, String JavaDoc str, String JavaDoc style);
75
76   /** Removes a portion of the document, if the edit condition allows it.
77    * @param offs Offset to start deleting from
78    * @param len Number of characters to remove
79    * @throws EditDocumentException if the offset or length are illegal
80    */

81   public void removeText(int offs, int len);
82
83   /** Removes a portion of the document, regardless of the edit condition.
84    * @param offs Offset to start deleting from
85    * @param len Number of characters to remove
86    * @throws EditDocumentException if the offset or length are illegal
87    */

88   public void forceRemoveText(int offs, int len);
89
90   /** Returns the length of the document. */
91   public int getLength();
92
93   /** Returns a portion of the document. Differs from getText in AbstractDocumentInterface by throwing
94    * EditDocumentException instead of BadLocationException. (Why bother? It avoids referencing a Swing class.)
95    * @param offs First offset of the desired text
96    * @param len Number of characters to return
97    * @throws EditDocumentException if the offset or length are illegal
98    */

99   public String JavaDoc getDocText(int offs, int len);
100   
101   /** Appends a string to this in the given named style, if the edit condition allows it.
102    * @param str String to be inserted
103    * @param style Name of the style to use. Must have been added using addStyle.
104    * @throws EditDocumentException if the offset is illegal
105    */

106   public void append(String JavaDoc str, String JavaDoc style);
107   
108   /** Gets the String identifying the default style for this document if one exists; null otherwise. */
109   public String JavaDoc getDefaultStyle();
110   
111   /** Returns the Pageable object for printing.
112    * @return A Pageable representing this document.
113    */

114   public Pageable JavaDoc getPageable() throws IllegalStateException JavaDoc;
115   
116   /** Prints the given console document */
117   public void print() throws PrinterException JavaDoc;
118 }
119
Popular Tags