javax.swing.text

Class AbstractDocument

Implemented Interfaces:
Document, Serializable
Known Direct Subclasses:
DefaultStyledDocument, PlainDocument

public abstract class AbstractDocument
extends Object
implements Document, Serializable

See Also:
Serialized Form

Nested Class Summary

abstract class
AbstractDocument.AbstractElement
static interface
AbstractDocument.AttributeContext
class
AbstractDocument.BranchElement
static interface
AbstractDocument.Content
class
AbstractDocument.DefaultDocumentEvent
static class
AbstractDocument.ElementEdit
class
AbstractDocument.LeafElement

Field Summary

protected static String
BAD_LOCATION
static String
BidiElementName
static String
ContentElementName
static String
ElementNameAttribute
static String
ParagraphElementName
static String
SectionElementName
protected EventListenerList
listenerList

Fields inherited from interface javax.swing.text.Document

StreamDescriptionProperty, TitleProperty

Constructor Summary

AbstractDocument(AbstractDocument.Content doc)
AbstractDocument(AbstractDocument.Content doc, AbstractDocument.AttributeContext ctx)

Method Summary

void
addDocumentListener(DocumentListener listener)
Adds a DocumentListener object to this document.
void
addUndoableEditListener(UndoableEditListener listener)
Adds a UndoableEditListener object to this document.
protected Element
createBranchElement(Element parent, AttributeSet attributes)
protected Element
createLeafElement(Element parent, AttributeSet attributes, int start, int end)
Position
createPosition(int offset)
Creates a mark in the character content at the specified offset.
void
dump(PrintStream out)
protected void
fireChangedUpdate(DocumentEvent event)
protected void
fireInsertUpdate(DocumentEvent event)
protected void
fireRemoveUpdate(DocumentEvent event)
protected void
fireUndoableEditUpdate(UndoableEditEvent event)
int
getAsynchronousLoadPriority()
protected AbstractDocument.AttributeContext
getAttributeContext()
Element
getBidiRootElement()
protected AbstractDocument.Content
getContent()
protected Thread
getCurrentWriter()
Element
getDefaultRootElement()
Returns the default root element.
DocumentFilter
getDocumentFilter()
DocumentListener[]
getDocumentListeners()
Returns add added DocumentListener objects.
Dictionary
getDocumentProperties()
Position
getEndPosition()
Returns the position that marks the end of the document.
int
getLength()
Returns the length of the document content.
EventListener[]
getListeners(Class listenerType)
Element
getParagraphElement(int pos)
Object
getProperty(Object key)
Returns a document property with the specified key.
Element[]
getRootElements()
Returns the root elements of the document content.
Position
getStartPosition()
Returns the position that marks the beginning of the document content.
String
getText(int offset, int length)
Returns the textual content starting at offset with a length of length.
void
getText(int offset, int length, Segment segment)
Fetch the textual content starting at offset with a length of length and store it in txt.
UndoableEditListener[]
getUndoableEditListeners()
Returns add added UndoableEditListener objects.
void
insertString(int offset, String text, AttributeSet attributes)
Inserts a piece of text with an AttributeSet at the specified offset.
protected void
insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
protected void
postRemoveUpdate(AbstractDocument.DefaultDocumentEvent chng)
void
putProperty(Object key, Object value)
Sets a document property.
void
readLock()
void
readUnlock()
void
remove(int offset, int length)
Removes a piece of content.
void
removeDocumentListener(DocumentListener listener)
Removes a DocumentListener object from this document.
void
removeUndoableEditListener(UndoableEditListener listener)
Removes a UndoableEditListener object from this document.
protected void
removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
void
render(Runnable r)
This allows the Document to be rendered safely.
void
replace(int offset, int length, String text, AttributeSet attributes)
Replaces some text in the document.
void
setAsynchronousLoadPriority(int p)
void
setDocumentFilter(DocumentFilter filter)
void
setDocumentProperties(Dictionary x)
protected void
writeLock()
protected void
writeUnlock()

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

BAD_LOCATION

protected static final String BAD_LOCATION

Field Value:
""


BidiElementName

public static final String BidiElementName

Field Value:
""


ContentElementName

public static final String ContentElementName

Field Value:
""


ElementNameAttribute

public static final String ElementNameAttribute

Field Value:
""


ParagraphElementName

public static final String ParagraphElementName

Field Value:
""


SectionElementName

public static final String SectionElementName

Field Value:
""


listenerList

protected EventListenerList listenerList

Constructor Details

AbstractDocument

protected AbstractDocument(AbstractDocument.Content doc)


AbstractDocument

protected AbstractDocument(AbstractDocument.Content doc,
                           AbstractDocument.AttributeContext ctx)

Method Details

addDocumentListener

public void addDocumentListener(DocumentListener listener)
Adds a DocumentListener object to this document.
Specified by:
addDocumentListener in interface Document

Parameters:
listener - the listener to add


addUndoableEditListener

public void addUndoableEditListener(UndoableEditListener listener)
Adds a UndoableEditListener object to this document.
Specified by:
addUndoableEditListener in interface Document

Parameters:
listener - the listener to add


createBranchElement

protected Element createBranchElement(Element parent,
                                      AttributeSet attributes)


createLeafElement

protected Element createLeafElement(Element parent,
                                    AttributeSet attributes,
                                    int start,
                                    int end)


createPosition

public Position createPosition(int offset)
            throws BadLocationException
Creates a mark in the character content at the specified offset.
Specified by:
createPosition in interface Document

Parameters:

Returns:
the created Position object

Throws:
BadLocationException - of the specified offset is not a valid position in the documents content


dump

public void dump(PrintStream out)


fireChangedUpdate

protected void fireChangedUpdate(DocumentEvent event)


fireInsertUpdate

protected void fireInsertUpdate(DocumentEvent event)


fireRemoveUpdate

protected void fireRemoveUpdate(DocumentEvent event)


fireUndoableEditUpdate

protected void fireUndoableEditUpdate(UndoableEditEvent event)


getAsynchronousLoadPriority

public int getAsynchronousLoadPriority()


getAttributeContext

protected AbstractDocument.AttributeContext getAttributeContext()


getBidiRootElement

public Element getBidiRootElement()


getContent

protected AbstractDocument.Content getContent()


getCurrentWriter

protected Thread getCurrentWriter()


getDefaultRootElement

public Element getDefaultRootElement()
Returns the default root element. Views should be using this element unless other mechanisms for assigning views to element structure is provided.
Specified by:
getDefaultRootElement in interface Document

Returns:
the default root element


getDocumentFilter

public DocumentFilter getDocumentFilter()

Since:
1.4


getDocumentListeners

public DocumentListener[] getDocumentListeners()
Returns add added DocumentListener objects.

Returns:
an array of listeners


getDocumentProperties

public Dictionary getDocumentProperties()


getEndPosition

public Position getEndPosition()
Returns the position that marks the end of the document.
Specified by:
getEndPosition in interface Document

Returns:
the position that marks the end of the document


getLength

public int getLength()
Returns the length of the document content.
Specified by:
getLength in interface Document

Returns:
the length of the document content


getListeners

public EventListener[] getListeners(Class listenerType)


getParagraphElement

public Element getParagraphElement(int pos)


getProperty

public Object getProperty(Object key)
Returns a document property with the specified key.
Specified by:
getProperty in interface Document

Parameters:
key - the (non-null) key for the property to fetch

Returns:
the property for key or null if no such property is stored


getRootElements

public Element[] getRootElements()
Returns the root elements of the document content.
Specified by:
getRootElements in interface Document

Returns:
the root elements of the document content


getStartPosition

public Position getStartPosition()
Returns the position that marks the beginning of the document content.
Specified by:
getStartPosition in interface Document

Returns:
the start position


getText

public String getText(int offset,
                      int length)
            throws BadLocationException
Returns the textual content starting at offset with a length of length.
Specified by:
getText in interface Document

Parameters:
offset - the beginning of the text fragment to fetch
length - the length of the text fragment to fetch

Returns:
the text fragment starting at offset with a length of length

Throws:
BadLocationException - if offset or length are no valid locations in the document content


getText

public void getText(int offset,
                    int length,
                    Segment segment)
            throws BadLocationException
Fetch the textual content starting at offset with a length of length and store it in txt.
Specified by:
getText in interface Document

Parameters:
offset - the beginning of the text fragment to fetch
length - the length of the text fragment to fetch

Throws:
BadLocationException - if offset or length are no valid locations in the document content


getUndoableEditListeners

public UndoableEditListener[] getUndoableEditListeners()
Returns add added UndoableEditListener objects.

Returns:
an array of listeners


insertString

public void insertString(int offset,
                         String text,
                         AttributeSet attributes)
            throws BadLocationException
Inserts a piece of text with an AttributeSet at the specified offset.
Specified by:
insertString in interface Document

Parameters:
offset - the location where to insert the content

Throws:
BadLocationException - if offset is not a valid location in the document content


insertUpdate

protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng,
                            AttributeSet attr)


postRemoveUpdate

protected void postRemoveUpdate(AbstractDocument.DefaultDocumentEvent chng)


putProperty

public void putProperty(Object key,
                        Object value)
Sets a document property.
Specified by:
putProperty in interface Document

Parameters:
key - the key of the property
value - the value of the property


readLock

public void readLock()


readUnlock

public void readUnlock()


remove

public void remove(int offset,
                   int length)
            throws BadLocationException
Removes a piece of content.
Specified by:
remove in interface Document

Parameters:

Throws:
BadLocationException - if offs or len are no valid locations in the document content


removeDocumentListener

public void removeDocumentListener(DocumentListener listener)
Removes a DocumentListener object from this document.
Specified by:
removeDocumentListener in interface Document

Parameters:
listener - the listener to remove


removeUndoableEditListener

public void removeUndoableEditListener(UndoableEditListener listener)
Removes a UndoableEditListener object from this document.
Specified by:
removeUndoableEditListener in interface Document

Parameters:
listener - the listener to remove


removeUpdate

protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)


render

public void render(Runnable r)
This allows the Document to be rendered safely. It is made sure that the Runnable can read the document without any changes while reading. The Runnable is not allowed to change the Document itself.
Specified by:
render in interface Document

Parameters:
r - the Runnable that renders the Document


replace

public void replace(int offset,
                    int length,
                    String text,
                    AttributeSet attributes)
            throws BadLocationException
Replaces some text in the document.

Since:
1.4


setAsynchronousLoadPriority

public void setAsynchronousLoadPriority(int p)


setDocumentFilter

public void setDocumentFilter(DocumentFilter filter)

Since:
1.4


setDocumentProperties

public void setDocumentProperties(Dictionary x)


writeLock

protected void writeLock()


writeUnlock

protected void writeUnlock()


AbstractDocument.java -- Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.