2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing.text;
40 import javax.swing.event.DocumentListener;
41 import javax.swing.event.UndoableEditListener;
44 * A Document is the model that backs up all text components in Swing.
45 * This interface supports different kinds of implementations, from
46 * simple plain text model up to complex styled HTML or RTF models.
48 public interface Document
51 * The key for the property that describes the source of a document.
53 String StreamDescriptionProperty = "stream";
56 * The key for the property that is the title of a document.
58 String TitleProperty = "title";
61 * Adds a {@link DocumentListener} to this document.
63 * @param listener the DocumentListener to add
65 void addDocumentListener(DocumentListener listener);
68 * Adds an {@link UndoableEditListener} to this document.
70 * @param listener the UndoableEditListener to add
72 void addUndoableEditListener(UndoableEditListener listener);
75 * Creates a mark in the character content at the specified offset.
77 * @param offs the offset where to place the mark
79 * @return the created Position object
81 * @throws BadLocationException of the specified offset is not a valid
82 * position in the documents content
84 Position createPosition(int offs)
85 throws BadLocationException;
88 * Returns the default root element. Views should be using this element
89 * unless other mechanisms for assigning views to element structure is
92 * @return the default root element
94 Element getDefaultRootElement();
97 * Returns the position that marks the end of the document.
99 * @return the position that marks the end of the document
101 Position getEndPosition();
104 * Returns the length of the document content.
106 * @return the length of the document content
111 * Returns a document property with the specified key.
113 * @param key the (non-null) key for the property to fetch
115 * @return the property for <code>key</code> or null if no such property
118 Object getProperty(Object key);
121 * Returns the root elements of the document content.
123 * @return the root elements of the document content
125 Element[] getRootElements();
128 * Returns the position that marks the beginning of the document
131 * @return the start position
133 Position getStartPosition();
136 * Returns the textual content starting at <code>offset</code> with
137 * a length of <code>length</code>.
139 * @param offset the beginning of the text fragment to fetch
140 * @param length the length of the text fragment to fetch
142 * @return the text fragment starting at <code>offset</code> with
143 * a length of <code>length</code>
145 * @throws BadLocationException if <code>offset</code> or <code>length</code>
146 * are no valid locations in the document content
148 String getText(int offset, int length)
149 throws BadLocationException;
152 * Fetch the textual content starting at <code>offset</code> with
153 * a length of <code>length</code> and store it in <code>txt</code>.
155 * @param offset the beginning of the text fragment to fetch
156 * @param length the length of the text fragment to fetch
157 * @param txt the Segment where to store the text fragment
159 * @throws BadLocationException if <code>offset</code> or <code>length</code>
160 * are no valid locations in the document content
162 void getText(int offset, int length, Segment txt)
163 throws BadLocationException;
166 * Inserts a piece of text with an AttributeSet at the specified
167 * <code>offset</code>.
169 * @param offset the location where to insert the content
170 * @param str the textual content to insert
171 * @param a the Attributes associated with the piece of text
173 * @throws BadLocationException if <code>offset</code>
174 * is not a valid location in the document content
176 void insertString(int offset, String str, AttributeSet a)
177 throws BadLocationException;
180 * Sets a document property.
182 * @param key the key of the property
183 * @param value the value of the property
185 void putProperty(Object key, Object value);
188 * Removes a piece of content.
190 * @param offs the location of the fragment to remove
191 * @param len the length of the fragment to remove
193 * @throws BadLocationException if <code>offs</code> or <code>len</code>
194 * are no valid locations in the document content
196 void remove(int offs, int len)
197 throws BadLocationException;
200 * Removes a DocumentListener from this Document.
202 * @param listener the DocumentListener to remove
204 void removeDocumentListener(DocumentListener listener);
207 * Removes an UndoableEditListener from this Document.
209 * @param listener the UndoableEditListener to remove
211 void removeUndoableEditListener(UndoableEditListener listener);
214 * This allows the Document to be rendered safely. It is made sure that
215 * the Runnable can read the document without any changes while reading.
216 * The Runnable is not allowed to change the Document itself.
218 * @param r the Runnable that renders the Document
220 void render(Runnable r);