javax.swing.text
Class AbstractDocument

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.swing.text.AbstractDocument
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable , Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Direct Known Subclasses:
DefaultStyledDocument sample code for javax.swing.text.DefaultStyledDocument definition code for javax.swing.text.DefaultStyledDocument , PlainDocument sample code for javax.swing.text.PlainDocument definition code for javax.swing.text.PlainDocument

public abstract class AbstractDocument
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document , Serializable sample code for java.io.Serializable definition code for java.io.Serializable

An implementation of the document interface to serve as a basis for implementing various kinds of documents. At this level there is very little policy, so there is a corresponding increase in difficulty of use.

This class implements a locking mechanism for the document. It allows multiple readers or one writer, and writers must wait until all observers of the document have been notified of a previous change before beginning another mutation to the document. The read lock is acquired and released using the render method. A write lock is aquired by the methods that mutate the document, and are held for the duration of the method call. Notification is done on the thread that produced the mutation, and the thread has full read access to the document for the duration of the notification, but other readers are kept out until the notification has finished. The notification is a beans event notification which does not allow any further mutations until all listeners have been notified.

Any models subclassed from this class and used in conjunction with a text component that has a look and feel implementation that is derived from BasicTextUI may be safely updated asynchronously, because all access to the View hierarchy is serialized by BasicTextUI if the document is of type AbstractDocument. The locking assumes that an independant thread will access the View hierarchy only from the DocumentListener methods, and that there will be only one event thread active at a time.

If concurrency support is desired, there are the following additional implications. The code path for any DocumentListener implementation and any UndoListener implementation must be threadsafe, and not access the component lock if trying to be safe from deadlocks. The repaint and revalidate methods on JComponent are safe.

AbstractDocument models an implied break at the end of the document. Among other things this allows you to position the caret after the last character. As a result of this, getLength returns one less than the length of the Content. If you create your own Content, be sure and initialize it to have an additional character. Refer to StringContent and GapContent for examples of this. Another implication of this is that Elements that model the implied end character will have an endOffset == (getLength() + 1). For example, in DefaultStyledDocument getParagraphElement(getLength()).getEndOffset() == getLength() + 1 .

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder sample code for java.beans.XMLEncoder definition code for java.beans.XMLEncoder .

See Also:
Serialized Form

Nested Class Summary
 class AbstractDocument.AbstractElement sample code for javax.swing.text.AbstractDocument.AbstractElement definition code for javax.swing.text.AbstractDocument.AbstractElement
          Implements the abstract part of an element.
static interface AbstractDocument.AttributeContext sample code for javax.swing.text.AbstractDocument.AttributeContext definition code for javax.swing.text.AbstractDocument.AttributeContext
          An interface that can be used to allow MutableAttributeSet implementations to use pluggable attribute compression techniques.
 class AbstractDocument.BranchElement sample code for javax.swing.text.AbstractDocument.BranchElement definition code for javax.swing.text.AbstractDocument.BranchElement
          Implements a composite element that contains other elements.
static interface AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content
          Interface to describe a sequence of character content that can be edited.
 class AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent
          Stores document changes as the document is being modified.
static class AbstractDocument.ElementEdit sample code for javax.swing.text.AbstractDocument.ElementEdit definition code for javax.swing.text.AbstractDocument.ElementEdit
          An implementation of ElementChange that can be added to the document event.
 class AbstractDocument.LeafElement sample code for javax.swing.text.AbstractDocument.LeafElement definition code for javax.swing.text.AbstractDocument.LeafElement
          Implements an element that directly represents content of some kind.
 
Field Summary
protected static String sample code for java.lang.String definition code for java.lang.String BAD_LOCATION sample code for javax.swing.text.AbstractDocument.BAD_LOCATION definition code for javax.swing.text.AbstractDocument.BAD_LOCATION
          Error message to indicate a bad location.
static String sample code for java.lang.String definition code for java.lang.String BidiElementName sample code for javax.swing.text.AbstractDocument.BidiElementName definition code for javax.swing.text.AbstractDocument.BidiElementName
          Name of elements used to hold a unidirectional run
static String sample code for java.lang.String definition code for java.lang.String ContentElementName sample code for javax.swing.text.AbstractDocument.ContentElementName definition code for javax.swing.text.AbstractDocument.ContentElementName
          Name of elements used to represent content
static String sample code for java.lang.String definition code for java.lang.String ElementNameAttribute sample code for javax.swing.text.AbstractDocument.ElementNameAttribute definition code for javax.swing.text.AbstractDocument.ElementNameAttribute
          Name of the attribute used to specify element names.
protected  EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList listenerList sample code for javax.swing.text.AbstractDocument.listenerList definition code for javax.swing.text.AbstractDocument.listenerList
          The event listener list for the document.
static String sample code for java.lang.String definition code for java.lang.String ParagraphElementName sample code for javax.swing.text.AbstractDocument.ParagraphElementName definition code for javax.swing.text.AbstractDocument.ParagraphElementName
          Name of elements used to represent paragraphs
static String sample code for java.lang.String definition code for java.lang.String SectionElementName sample code for javax.swing.text.AbstractDocument.SectionElementName definition code for javax.swing.text.AbstractDocument.SectionElementName
          Name of elements used to hold sections (lines/paragraphs).
 
Fields inherited from interface javax.swing.text.Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
StreamDescriptionProperty sample code for javax.swing.text.Document.StreamDescriptionProperty definition code for javax.swing.text.Document.StreamDescriptionProperty , TitleProperty sample code for javax.swing.text.Document.TitleProperty definition code for javax.swing.text.Document.TitleProperty
 
Constructor Summary
protected AbstractDocument sample code for javax.swing.text.AbstractDocument.AbstractDocument(javax.swing.text.AbstractDocument.Content) definition code for javax.swing.text.AbstractDocument.AbstractDocument(javax.swing.text.AbstractDocument.Content) (AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content  data)
          Constructs a new AbstractDocument, wrapped around some specified content storage mechanism.
protected AbstractDocument sample code for javax.swing.text.AbstractDocument.AbstractDocument(javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.AttributeContext) definition code for javax.swing.text.AbstractDocument.AbstractDocument(javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.AttributeContext) (AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content  data, AbstractDocument.AttributeContext sample code for javax.swing.text.AbstractDocument.AttributeContext definition code for javax.swing.text.AbstractDocument.AttributeContext  context)
          Constructs a new AbstractDocument, wrapped around some specified content storage mechanism.
 
Method Summary
 void addDocumentListener sample code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener) (DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener  listener)
          Adds a document listener for notification of any changes.
 void addUndoableEditListener sample code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener) (UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener  listener)
          Adds an undo listener for notification of any changes.
protected  Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element createBranchElement sample code for javax.swing.text.AbstractDocument.createBranchElement(javax.swing.text.Element, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.createBranchElement(javax.swing.text.Element, javax.swing.text.AttributeSet) (Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  parent, AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a)
          Creates a document branch element, that can contain other elements.
protected  Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element createLeafElement sample code for javax.swing.text.AbstractDocument.createLeafElement(javax.swing.text.Element, javax.swing.text.AttributeSet, int, int) definition code for javax.swing.text.AbstractDocument.createLeafElement(javax.swing.text.Element, javax.swing.text.AttributeSet, int, int) (Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  parent, AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a, int p0, int p1)
          Creates a document leaf element.
 Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position createPosition sample code for javax.swing.text.AbstractDocument.createPosition(int) definition code for javax.swing.text.AbstractDocument.createPosition(int) (int offs)
          Returns a position that will track change as the document is altered.
 void dump sample code for javax.swing.text.AbstractDocument.dump(java.io.PrintStream) definition code for javax.swing.text.AbstractDocument.dump(java.io.PrintStream) (PrintStream sample code for java.io.PrintStream definition code for java.io.PrintStream  out)
          Gives a diagnostic dump.
protected  void fireChangedUpdate sample code for javax.swing.text.AbstractDocument.fireChangedUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireChangedUpdate(javax.swing.event.DocumentEvent) (DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireInsertUpdate sample code for javax.swing.text.AbstractDocument.fireInsertUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireInsertUpdate(javax.swing.event.DocumentEvent) (DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireRemoveUpdate sample code for javax.swing.text.AbstractDocument.fireRemoveUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireRemoveUpdate(javax.swing.event.DocumentEvent) (DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireUndoableEditUpdate sample code for javax.swing.text.AbstractDocument.fireUndoableEditUpdate(javax.swing.event.UndoableEditEvent) definition code for javax.swing.text.AbstractDocument.fireUndoableEditUpdate(javax.swing.event.UndoableEditEvent) (UndoableEditEvent sample code for javax.swing.event.UndoableEditEvent definition code for javax.swing.event.UndoableEditEvent  e)
          Notifies all listeners that have registered interest for notification on this event type.
 int getAsynchronousLoadPriority sample code for javax.swing.text.AbstractDocument.getAsynchronousLoadPriority() definition code for javax.swing.text.AbstractDocument.getAsynchronousLoadPriority() ()
          Gets the asynchronous loading priority.
protected  AbstractDocument.AttributeContext sample code for javax.swing.text.AbstractDocument.AttributeContext definition code for javax.swing.text.AbstractDocument.AttributeContext getAttributeContext sample code for javax.swing.text.AbstractDocument.getAttributeContext() definition code for javax.swing.text.AbstractDocument.getAttributeContext() ()
          Fetches the context for managing attributes.
 Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element getBidiRootElement sample code for javax.swing.text.AbstractDocument.getBidiRootElement() definition code for javax.swing.text.AbstractDocument.getBidiRootElement() ()
          Returns the root element of the bidirectional structure for this document.
protected  AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content getContent sample code for javax.swing.text.AbstractDocument.getContent() definition code for javax.swing.text.AbstractDocument.getContent() ()
          Gets the content for the document.
protected  Thread sample code for java.lang.Thread definition code for java.lang.Thread getCurrentWriter sample code for javax.swing.text.AbstractDocument.getCurrentWriter() definition code for javax.swing.text.AbstractDocument.getCurrentWriter() ()
          Fetches the current writing thread if there is one.
abstract  Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element getDefaultRootElement sample code for javax.swing.text.AbstractDocument.getDefaultRootElement() definition code for javax.swing.text.AbstractDocument.getDefaultRootElement() ()
          Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided.
 DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.DocumentFilter getDocumentFilter sample code for javax.swing.text.AbstractDocument.getDocumentFilter() definition code for javax.swing.text.AbstractDocument.getDocumentFilter() ()
          Returns the DocumentFilter that is responsible for filtering of insertion/removal.
 DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener [] getDocumentListeners sample code for javax.swing.text.AbstractDocument.getDocumentListeners() definition code for javax.swing.text.AbstractDocument.getDocumentListeners() ()
          Returns an array of all the document listeners registered on this document.
 Dictionary sample code for java.util.Dictionary definition code for java.util.Dictionary <Object sample code for java.lang.Object definition code for java.lang.Object ,Object sample code for java.lang.Object definition code for java.lang.Object > getDocumentProperties sample code for javax.swing.text.AbstractDocument.getDocumentProperties() definition code for javax.swing.text.AbstractDocument.getDocumentProperties() ()
          Supports managing a set of properties.
 Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position getEndPosition sample code for javax.swing.text.AbstractDocument.getEndPosition() definition code for javax.swing.text.AbstractDocument.getEndPosition() ()
          Returns a position that represents the end of the document.
 int getLength sample code for javax.swing.text.AbstractDocument.getLength() definition code for javax.swing.text.AbstractDocument.getLength() ()
          Returns the length of the data.
<T extends EventListener sample code for java.util.EventListener definition code for java.util.EventListener >
T[]
getListeners sample code for javax.swing.text.AbstractDocument.getListeners(java.lang.Class) definition code for javax.swing.text.AbstractDocument.getListeners(java.lang.Class) (Class sample code for java.lang.Class definition code for java.lang.Class <T> listenerType)
          Returns an array of all the objects currently registered as FooListeners upon this document.
abstract  Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element getParagraphElement sample code for javax.swing.text.AbstractDocument.getParagraphElement(int) definition code for javax.swing.text.AbstractDocument.getParagraphElement(int) (int pos)
          Get the paragraph element containing the given position.
 Object sample code for java.lang.Object definition code for java.lang.Object getProperty sample code for javax.swing.text.AbstractDocument.getProperty(java.lang.Object) definition code for javax.swing.text.AbstractDocument.getProperty(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key)
          A convenience method for looking up a property value.
 Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element [] getRootElements sample code for javax.swing.text.AbstractDocument.getRootElements() definition code for javax.swing.text.AbstractDocument.getRootElements() ()
          Gets all root elements defined.
 Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position getStartPosition sample code for javax.swing.text.AbstractDocument.getStartPosition() definition code for javax.swing.text.AbstractDocument.getStartPosition() ()
          Returns a position that represents the start of the document.
 String sample code for java.lang.String definition code for java.lang.String getText sample code for javax.swing.text.AbstractDocument.getText(int, int) definition code for javax.swing.text.AbstractDocument.getText(int, int) (int offset, int length)
          Gets a sequence of text from the document.
 void getText sample code for javax.swing.text.AbstractDocument.getText(int, int, javax.swing.text.Segment) definition code for javax.swing.text.AbstractDocument.getText(int, int, javax.swing.text.Segment) (int offset, int length, Segment sample code for javax.swing.text.Segment definition code for javax.swing.text.Segment  txt)
          Fetches the text contained within the given portion of the document.
 UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener [] getUndoableEditListeners sample code for javax.swing.text.AbstractDocument.getUndoableEditListeners() definition code for javax.swing.text.AbstractDocument.getUndoableEditListeners() ()
          Returns an array of all the undoable edit listeners registered on this document.
 void insertString sample code for javax.swing.text.AbstractDocument.insertString(int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.insertString(int, java.lang.String, javax.swing.text.AttributeSet) (int offs, String sample code for java.lang.String definition code for java.lang.String  str, AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a)
          Inserts some content into the document.
protected  void insertUpdate sample code for javax.swing.text.AbstractDocument.insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet) (AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng, AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  attr)
          Updates document structure as a result of text insertion.
protected  void postRemoveUpdate sample code for javax.swing.text.AbstractDocument.postRemoveUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) definition code for javax.swing.text.AbstractDocument.postRemoveUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) (AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng)
          Updates any document structure as a result of text removal.
 void putProperty sample code for javax.swing.text.AbstractDocument.putProperty(java.lang.Object, java.lang.Object) definition code for javax.swing.text.AbstractDocument.putProperty(java.lang.Object, java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  key, Object sample code for java.lang.Object definition code for java.lang.Object  value)
          A convenience method for storing up a property value.
 void readLock sample code for javax.swing.text.AbstractDocument.readLock() definition code for javax.swing.text.AbstractDocument.readLock() ()
          Acquires a lock to begin reading some state from the document.
 void readUnlock sample code for javax.swing.text.AbstractDocument.readUnlock() definition code for javax.swing.text.AbstractDocument.readUnlock() ()
          Does a read unlock.
 void remove sample code for javax.swing.text.AbstractDocument.remove(int, int) definition code for javax.swing.text.AbstractDocument.remove(int, int) (int offs, int len)
          Removes some content from the document.
 void removeDocumentListener sample code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener) (DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener  listener)
          Removes a document listener.
 void removeUndoableEditListener sample code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener) (UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener  listener)
          Removes an undo listener.
protected  void removeUpdate sample code for javax.swing.text.AbstractDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) definition code for javax.swing.text.AbstractDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) (AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng)
          Updates any document structure as a result of text removal.
 void render sample code for javax.swing.text.AbstractDocument.render(java.lang.Runnable) definition code for javax.swing.text.AbstractDocument.render(java.lang.Runnable) (Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  r)
          This allows the model to be safely rendered in the presence of currency, if the model supports being updated asynchronously.
 void replace sample code for javax.swing.text.AbstractDocument.replace(int, int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.replace(int, int, java.lang.String, javax.swing.text.AttributeSet) (int offset, int length, String sample code for java.lang.String definition code for java.lang.String  text, AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  attrs)
          Deletes the region of text from offset to offset + length, and replaces it with text.
 void setAsynchronousLoadPriority sample code for javax.swing.text.AbstractDocument.setAsynchronousLoadPriority(int) definition code for javax.swing.text.AbstractDocument.setAsynchronousLoadPriority(int) (int p)
          Sets the asynchronous loading priority.
 void setDocumentFilter sample code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter) definition code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter) (DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.DocumentFilter  filter)
          Sets the DocumentFilter.
 void setDocumentProperties sample code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary) definition code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary) (Dictionary sample code for java.util.Dictionary definition code for java.util.Dictionary <Object sample code for java.lang.Object definition code for java.lang.Object ,Object sample code for java.lang.Object definition code for java.lang.Object > x)
          Replaces the document properties dictionary for this document.
protected  void writeLock sample code for javax.swing.text.AbstractDocument.writeLock() definition code for javax.swing.text.AbstractDocument.writeLock() ()
          Acquires a lock to begin mutating the document this lock protects.
protected  void writeUnlock sample code for javax.swing.text.AbstractDocument.writeUnlock() definition code for javax.swing.text.AbstractDocument.writeUnlock() ()
          Releases a write lock previously obtained via writeLock.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

listenerList sample code for javax.swing.text.AbstractDocument.listenerList

protected EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList  listenerList
The event listener list for the document.


BAD_LOCATION sample code for javax.swing.text.AbstractDocument.BAD_LOCATION

protected static final String sample code for java.lang.String definition code for java.lang.String  BAD_LOCATION
Error message to indicate a bad location.

See Also:
Constant Field Values

ParagraphElementName sample code for javax.swing.text.AbstractDocument.ParagraphElementName

public static final String sample code for java.lang.String definition code for java.lang.String  ParagraphElementName
Name of elements used to represent paragraphs

See Also:
Constant Field Values

ContentElementName sample code for javax.swing.text.AbstractDocument.ContentElementName

public static final String sample code for java.lang.String definition code for java.lang.String  ContentElementName
Name of elements used to represent content

See Also:
Constant Field Values

SectionElementName sample code for javax.swing.text.AbstractDocument.SectionElementName

public static final String sample code for java.lang.String definition code for java.lang.String  SectionElementName
Name of elements used to hold sections (lines/paragraphs).

See Also:
Constant Field Values

BidiElementName sample code for javax.swing.text.AbstractDocument.BidiElementName

public static final String sample code for java.lang.String definition code for java.lang.String  BidiElementName
Name of elements used to hold a unidirectional run

See Also:
Constant Field Values

ElementNameAttribute sample code for javax.swing.text.AbstractDocument.ElementNameAttribute

public static final String sample code for java.lang.String definition code for java.lang.String  ElementNameAttribute
Name of the attribute used to specify element names.

See Also:
Constant Field Values
Constructor Detail

AbstractDocument sample code for javax.swing.text.AbstractDocument(javax.swing.text.AbstractDocument.Content) definition code for javax.swing.text.AbstractDocument(javax.swing.text.AbstractDocument.Content)

protected AbstractDocument(AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content  data)
Constructs a new AbstractDocument, wrapped around some specified content storage mechanism.

Parameters:
data - the content

AbstractDocument sample code for javax.swing.text.AbstractDocument(javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.AttributeContext) definition code for javax.swing.text.AbstractDocument(javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.AttributeContext)

protected AbstractDocument(AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content  data,
                           AbstractDocument.AttributeContext sample code for javax.swing.text.AbstractDocument.AttributeContext definition code for javax.swing.text.AbstractDocument.AttributeContext  context)
Constructs a new AbstractDocument, wrapped around some specified content storage mechanism.

Parameters:
data - the content
context - the attribute context
Method Detail

getDocumentProperties sample code for javax.swing.text.AbstractDocument.getDocumentProperties() definition code for javax.swing.text.AbstractDocument.getDocumentProperties()

public Dictionary sample code for java.util.Dictionary definition code for java.util.Dictionary <Object sample code for java.lang.Object definition code for java.lang.Object ,Object sample code for java.lang.Object definition code for java.lang.Object > getDocumentProperties()
Supports managing a set of properties. Callers can use the documentProperties dictionary to annotate the document with document-wide properties.

Returns:
a non-null Dictionary
See Also:
setDocumentProperties(java.util.Dictionary) sample code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary) definition code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary)

setDocumentProperties sample code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary<java.lang.Object, java.lang.Object>) definition code for javax.swing.text.AbstractDocument.setDocumentProperties(java.util.Dictionary<java.lang.Object, java.lang.Object>)

public void setDocumentProperties(Dictionary sample code for java.util.Dictionary definition code for java.util.Dictionary <Object sample code for java.lang.Object definition code for java.lang.Object ,Object sample code for java.lang.Object definition code for java.lang.Object > x)
Replaces the document properties dictionary for this document.

Parameters:
x - the new dictionary
See Also:
getDocumentProperties() sample code for javax.swing.text.AbstractDocument.getDocumentProperties() definition code for javax.swing.text.AbstractDocument.getDocumentProperties()

fireInsertUpdate sample code for javax.swing.text.AbstractDocument.fireInsertUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireInsertUpdate(javax.swing.event.DocumentEvent)

protected void fireInsertUpdate(DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event
See Also:
EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList

fireChangedUpdate sample code for javax.swing.text.AbstractDocument.fireChangedUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireChangedUpdate(javax.swing.event.DocumentEvent)

protected void fireChangedUpdate(DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event
See Also:
EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList

fireRemoveUpdate sample code for javax.swing.text.AbstractDocument.fireRemoveUpdate(javax.swing.event.DocumentEvent) definition code for javax.swing.text.AbstractDocument.fireRemoveUpdate(javax.swing.event.DocumentEvent)

protected void fireRemoveUpdate(DocumentEvent sample code for javax.swing.event.DocumentEvent definition code for javax.swing.event.DocumentEvent  e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event
See Also:
EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList

fireUndoableEditUpdate sample code for javax.swing.text.AbstractDocument.fireUndoableEditUpdate(javax.swing.event.UndoableEditEvent) definition code for javax.swing.text.AbstractDocument.fireUndoableEditUpdate(javax.swing.event.UndoableEditEvent)

protected void fireUndoableEditUpdate(UndoableEditEvent sample code for javax.swing.event.UndoableEditEvent definition code for javax.swing.event.UndoableEditEvent  e)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

Parameters:
e - the event
See Also:
EventListenerList sample code for javax.swing.event.EventListenerList definition code for javax.swing.event.EventListenerList

getListeners sample code for javax.swing.text.AbstractDocument.<T extends java.util.EventListener>getListeners(java.lang.Class<T>) definition code for javax.swing.text.AbstractDocument.<T extends java.util.EventListener>getListeners(java.lang.Class<T>)

public <T extends EventListener sample code for java.util.EventListener definition code for java.util.EventListener > T[] getListeners(Class sample code for java.lang.Class definition code for java.lang.Class <T> listenerType)
Returns an array of all the objects currently registered as FooListeners upon this document. FooListeners are registered using the addFooListener method.

You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a document d for its document listeners with the following code:

DocumentListener[] mls = (DocumentListener[])(d.getListeners(DocumentListener.class));
If no such listeners exist, this method returns an empty array.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this component, or an empty array if no such listeners have been added
Throws:
ClassCastException sample code for java.lang.ClassCastException definition code for java.lang.ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since:
1.3
See Also:
getDocumentListeners() sample code for javax.swing.text.AbstractDocument.getDocumentListeners() definition code for javax.swing.text.AbstractDocument.getDocumentListeners() , getUndoableEditListeners() sample code for javax.swing.text.AbstractDocument.getUndoableEditListeners() definition code for javax.swing.text.AbstractDocument.getUndoableEditListeners()

getAsynchronousLoadPriority sample code for javax.swing.text.AbstractDocument.getAsynchronousLoadPriority() definition code for javax.swing.text.AbstractDocument.getAsynchronousLoadPriority()

public int getAsynchronousLoadPriority()
Gets the asynchronous loading priority. If less than zero, the document should not be loaded asynchronously.

Returns:
the asynchronous loading priority, or -1 if the document should not be loaded asynchronously

setAsynchronousLoadPriority sample code for javax.swing.text.AbstractDocument.setAsynchronousLoadPriority(int) definition code for javax.swing.text.AbstractDocument.setAsynchronousLoadPriority(int)

public void setAsynchronousLoadPriority(int p)
Sets the asynchronous loading priority.

Parameters:
p - the new asynchronous loading priority; a value less than zero indicates that the document should not be loaded asynchronously

setDocumentFilter sample code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter) definition code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter)

public void setDocumentFilter(DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.DocumentFilter  filter)
Sets the DocumentFilter. The DocumentFilter is passed insert and remove to conditionally allow inserting/deleting of the text. A null value indicates that no filtering will occur.

Parameters:
filter - the DocumentFilter used to constrain text
Since:
1.4
See Also:
getDocumentFilter() sample code for javax.swing.text.AbstractDocument.getDocumentFilter() definition code for javax.swing.text.AbstractDocument.getDocumentFilter()

getDocumentFilter sample code for javax.swing.text.AbstractDocument.getDocumentFilter() definition code for javax.swing.text.AbstractDocument.getDocumentFilter()

public DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.DocumentFilter  getDocumentFilter()
Returns the DocumentFilter that is responsible for filtering of insertion/removal. A null return value implies no filtering is to occur.

Returns:
the DocumentFilter
Since:
1.4
See Also:
setDocumentFilter(javax.swing.text.DocumentFilter) sample code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter) definition code for javax.swing.text.AbstractDocument.setDocumentFilter(javax.swing.text.DocumentFilter)

render sample code for javax.swing.text.AbstractDocument.render(java.lang.Runnable) definition code for javax.swing.text.AbstractDocument.render(java.lang.Runnable)

public void render(Runnable sample code for java.lang.Runnable definition code for java.lang.Runnable  r)
This allows the model to be safely rendered in the presence of currency, if the model supports being updated asynchronously. The given runnable will be executed in a way that allows it to safely read the model with no changes while the runnable is being executed. The runnable itself may not make any mutations.

This is implemented to aquire a read lock for the duration of the runnables execution. There may be multiple runnables executing at the same time, and all writers will be blocked while there are active rendering runnables. If the runnable throws an exception, its lock will be safely released. There is no protection against a runnable that never exits, which will effectively leave the document locked for it's lifetime.

If the given runnable attempts to make any mutations in this implementation, a deadlock will occur. There is no tracking of individual rendering threads to enable detecting this situation, but a subclass could incur the overhead of tracking them and throwing an error.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Specified by:
render sample code for javax.swing.text.Document.render(java.lang.Runnable) definition code for javax.swing.text.Document.render(java.lang.Runnable) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
r - the renderer to execute

getLength sample code for javax.swing.text.AbstractDocument.getLength() definition code for javax.swing.text.AbstractDocument.getLength()

public int getLength()
Returns the length of the data. This is the number of characters of content that represents the users data.

Specified by:
getLength sample code for javax.swing.text.Document.getLength() definition code for javax.swing.text.Document.getLength() in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Returns:
the length >= 0
See Also:
Document.getLength() sample code for javax.swing.text.Document.getLength() definition code for javax.swing.text.Document.getLength()

addDocumentListener sample code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener)

public void addDocumentListener(DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener  listener)
Adds a document listener for notification of any changes.

Specified by:
addDocumentListener sample code for javax.swing.text.Document.addDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.Document.addDocumentListener(javax.swing.event.DocumentListener) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
listener - the DocumentListener to add
See Also:
Document.addDocumentListener(javax.swing.event.DocumentListener) sample code for javax.swing.text.Document.addDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.Document.addDocumentListener(javax.swing.event.DocumentListener)

removeDocumentListener sample code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener)

public void removeDocumentListener(DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener  listener)
Removes a document listener.

Specified by:
removeDocumentListener sample code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
listener - the DocumentListener to remove
See Also:
Document.removeDocumentListener(javax.swing.event.DocumentListener) sample code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener)

getDocumentListeners sample code for javax.swing.text.AbstractDocument.getDocumentListeners() definition code for javax.swing.text.AbstractDocument.getDocumentListeners()

public DocumentListener sample code for javax.swing.event.DocumentListener definition code for javax.swing.event.DocumentListener [] getDocumentListeners()
Returns an array of all the document listeners registered on this document.

Returns:
all of this document's DocumentListeners or an empty array if no document listeners are currently registered
Since:
1.4
See Also:
addDocumentListener(javax.swing.event.DocumentListener) sample code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.addDocumentListener(javax.swing.event.DocumentListener) , removeDocumentListener(javax.swing.event.DocumentListener) sample code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.AbstractDocument.removeDocumentListener(javax.swing.event.DocumentListener)

addUndoableEditListener sample code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener)

public void addUndoableEditListener(UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener  listener)
Adds an undo listener for notification of any changes. Undo/Redo operations performed on the UndoableEdit will cause the appropriate DocumentEvent to be fired to keep the view(s) in sync with the model.

Specified by:
addUndoableEditListener sample code for javax.swing.text.Document.addUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.Document.addUndoableEditListener(javax.swing.event.UndoableEditListener) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
listener - the UndoableEditListener to add
See Also:
Document.addUndoableEditListener(javax.swing.event.UndoableEditListener) sample code for javax.swing.text.Document.addUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.Document.addUndoableEditListener(javax.swing.event.UndoableEditListener)

removeUndoableEditListener sample code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener)

public void removeUndoableEditListener(UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener  listener)
Removes an undo listener.

Specified by:
removeUndoableEditListener sample code for javax.swing.text.Document.removeUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.Document.removeUndoableEditListener(javax.swing.event.UndoableEditListener) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
listener - the UndoableEditListener to remove
See Also:
Document.removeDocumentListener(javax.swing.event.DocumentListener) sample code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener) definition code for javax.swing.text.Document.removeDocumentListener(javax.swing.event.DocumentListener)

getUndoableEditListeners sample code for javax.swing.text.AbstractDocument.getUndoableEditListeners() definition code for javax.swing.text.AbstractDocument.getUndoableEditListeners()

public UndoableEditListener sample code for javax.swing.event.UndoableEditListener definition code for javax.swing.event.UndoableEditListener [] getUndoableEditListeners()
Returns an array of all the undoable edit listeners registered on this document.

Returns:
all of this document's UndoableEditListeners or an empty array if no undoable edit listeners are currently registered
Since:
1.4
See Also:
addUndoableEditListener(javax.swing.event.UndoableEditListener) sample code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.addUndoableEditListener(javax.swing.event.UndoableEditListener) , removeUndoableEditListener(javax.swing.event.UndoableEditListener) sample code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener) definition code for javax.swing.text.AbstractDocument.removeUndoableEditListener(javax.swing.event.UndoableEditListener)

getProperty sample code for javax.swing.text.AbstractDocument.getProperty(java.lang.Object) definition code for javax.swing.text.AbstractDocument.getProperty(java.lang.Object)

public final Object sample code for java.lang.Object definition code for java.lang.Object  getProperty(Object sample code for java.lang.Object definition code for java.lang.Object  key)
A convenience method for looking up a property value. It is equivalent to:
 getDocumentProperties().get(key);
 

Specified by:
getProperty sample code for javax.swing.text.Document.getProperty(java.lang.Object) definition code for javax.swing.text.Document.getProperty(java.lang.Object) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
key - the non-null property key
Returns:
the value of this property or null
See Also:
getDocumentProperties() sample code for javax.swing.text.AbstractDocument.getDocumentProperties() definition code for javax.swing.text.AbstractDocument.getDocumentProperties()

putProperty sample code for javax.swing.text.AbstractDocument.putProperty(java.lang.Object, java.lang.Object) definition code for javax.swing.text.AbstractDocument.putProperty(java.lang.Object, java.lang.Object)

public final void putProperty(Object sample code for java.lang.Object definition code for java.lang.Object  key,
                              Object sample code for java.lang.Object definition code for java.lang.Object  value)
A convenience method for storing up a property value. It is equivalent to:
 getDocumentProperties().put(key, value);
 
If value is null this method will remove the property.

Specified by:
putProperty sample code for javax.swing.text.Document.putProperty(java.lang.Object, java.lang.Object) definition code for javax.swing.text.Document.putProperty(java.lang.Object, java.lang.Object) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
key - the non-null key
value - the property value
See Also:
getDocumentProperties() sample code for javax.swing.text.AbstractDocument.getDocumentProperties() definition code for javax.swing.text.AbstractDocument.getDocumentProperties()

remove sample code for javax.swing.text.AbstractDocument.remove(int, int) definition code for javax.swing.text.AbstractDocument.remove(int, int)

public void remove(int offs,
                   int len)
            throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Removes some content from the document. Removing content causes a write lock to be held while the actual changes are taking place. Observers are notified of the change on the thread that called this method.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Specified by:
remove sample code for javax.swing.text.Document.remove(int, int) definition code for javax.swing.text.Document.remove(int, int) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
offs - the starting offset >= 0
len - the number of characters to remove >= 0
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - the given remove position is not a valid position within the document
See Also:
Document.remove(int, int) sample code for javax.swing.text.Document.remove(int, int) definition code for javax.swing.text.Document.remove(int, int)

replace sample code for javax.swing.text.AbstractDocument.replace(int, int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.replace(int, int, java.lang.String, javax.swing.text.AttributeSet)

public void replace(int offset,
                    int length,
                    String sample code for java.lang.String definition code for java.lang.String  text,
                    AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  attrs)
             throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Deletes the region of text from offset to offset + length, and replaces it with text. It is up to the implementation as to how this is implemented, some implementations may treat this as two distinct operations: a remove followed by an insert, others may treat the replace as one atomic operation.

Parameters:
offset - index of child element
length - length of text to delete, may be 0 indicating don't delete anything
text - text to insert, null indicates no text to insert
attrs - AttributeSet indicating attributes of inserted text, null is legal, and typically treated as an empty attributeset, but exact interpretation is left to the subclass
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - the given position is not a valid position within the document
Since:
1.4

insertString sample code for javax.swing.text.AbstractDocument.insertString(int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.insertString(int, java.lang.String, javax.swing.text.AttributeSet)

public void insertString(int offs,
                         String sample code for java.lang.String definition code for java.lang.String  str,
                         AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a)
                  throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Inserts some content into the document. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Specified by:
insertString sample code for javax.swing.text.Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
offs - the starting offset >= 0
str - the string to insert; does nothing with null/empty strings
a - the attributes for the inserted content
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - the given insert position is not a valid position within the document
See Also:
Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet) sample code for javax.swing.text.Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet) definition code for javax.swing.text.Document.insertString(int, java.lang.String, javax.swing.text.AttributeSet)

getText sample code for javax.swing.text.AbstractDocument.getText(int, int) definition code for javax.swing.text.AbstractDocument.getText(int, int)

public String sample code for java.lang.String definition code for java.lang.String  getText(int offset,
                      int length)
               throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Gets a sequence of text from the document.

Specified by:
getText sample code for javax.swing.text.Document.getText(int, int) definition code for javax.swing.text.Document.getText(int, int) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
offset - the starting offset >= 0
length - the number of characters to retrieve >= 0
Returns:
the text
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - the range given includes a position that is not a valid position within the document
See Also:
Document.getText(int, int) sample code for javax.swing.text.Document.getText(int, int) definition code for javax.swing.text.Document.getText(int, int)

getText sample code for javax.swing.text.AbstractDocument.getText(int, int, javax.swing.text.Segment) definition code for javax.swing.text.AbstractDocument.getText(int, int, javax.swing.text.Segment)

public void getText(int offset,
                    int length,
                    Segment sample code for javax.swing.text.Segment definition code for javax.swing.text.Segment  txt)
             throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Fetches the text contained within the given portion of the document.

If the partialReturn property on the txt parameter is false, the data returned in the Segment will be the entire length requested and may or may not be a copy depending upon how the data was stored. If the partialReturn property is true, only the amount of text that can be returned without creating a copy is returned. Using partial returns will give better performance for situations where large parts of the document are being scanned. The following is an example of using the partial return to access the entire document:

   int nleft = doc.getDocumentLength();
   Segment text = new Segment();
   int offs = 0;
   text.setPartialReturn(true);   
   while (nleft > 0) {
       doc.getText(offs, nleft, text);
       // do something with text
       nleft -= text.count;
       offs += text.count;
   }
 

Specified by:
getText sample code for javax.swing.text.Document.getText(int, int, javax.swing.text.Segment) definition code for javax.swing.text.Document.getText(int, int, javax.swing.text.Segment) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
offset - the starting offset >= 0
length - the number of characters to retrieve >= 0
txt - the Segment object to retrieve the text into
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - the range given includes a position that is not a valid position within the document

createPosition sample code for javax.swing.text.AbstractDocument.createPosition(int) definition code for javax.swing.text.AbstractDocument.createPosition(int)

public Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position  createPosition(int offs)
                        throws BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException 
Returns a position that will track change as the document is altered.

This method is thread safe, although most Swing methods are not. Please see Threads and Swing for more information.

Specified by:
createPosition sample code for javax.swing.text.Document.createPosition(int) definition code for javax.swing.text.Document.createPosition(int) in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Parameters:
offs - the position in the model >= 0
Returns:
the position
Throws:
BadLocationException sample code for javax.swing.text.BadLocationException definition code for javax.swing.text.BadLocationException - if the given position does not represent a valid location in the associated document
See Also:
Document.createPosition(int) sample code for javax.swing.text.Document.createPosition(int) definition code for javax.swing.text.Document.createPosition(int)

getStartPosition sample code for javax.swing.text.AbstractDocument.getStartPosition() definition code for javax.swing.text.AbstractDocument.getStartPosition()

public final Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position  getStartPosition()
Returns a position that represents the start of the document. The position returned can be counted on to track change and stay located at the beginning of the document.

Specified by:
getStartPosition sample code for javax.swing.text.Document.getStartPosition() definition code for javax.swing.text.Document.getStartPosition() in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Returns:
the position

getEndPosition sample code for javax.swing.text.AbstractDocument.getEndPosition() definition code for javax.swing.text.AbstractDocument.getEndPosition()

public final Position sample code for javax.swing.text.Position definition code for javax.swing.text.Position  getEndPosition()
Returns a position that represents the end of the document. The position returned can be counted on to track change and stay located at the end of the document.

Specified by:
getEndPosition sample code for javax.swing.text.Document.getEndPosition() definition code for javax.swing.text.Document.getEndPosition() in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Returns:
the position

getRootElements sample code for javax.swing.text.AbstractDocument.getRootElements() definition code for javax.swing.text.AbstractDocument.getRootElements()

public Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element [] getRootElements()
Gets all root elements defined. Typically, there will only be one so the default implementation is to return the default root element.

Specified by:
getRootElements sample code for javax.swing.text.Document.getRootElements() definition code for javax.swing.text.Document.getRootElements() in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Returns:
the root element

getDefaultRootElement sample code for javax.swing.text.AbstractDocument.getDefaultRootElement() definition code for javax.swing.text.AbstractDocument.getDefaultRootElement()

public abstract Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  getDefaultRootElement()
Returns the root element that views should be based upon unless some other mechanism for assigning views to element structures is provided.

Specified by:
getDefaultRootElement sample code for javax.swing.text.Document.getDefaultRootElement() definition code for javax.swing.text.Document.getDefaultRootElement() in interface Document sample code for javax.swing.text.Document definition code for javax.swing.text.Document
Returns:
the root element
See Also:
Document.getDefaultRootElement() sample code for javax.swing.text.Document.getDefaultRootElement() definition code for javax.swing.text.Document.getDefaultRootElement()

getBidiRootElement sample code for javax.swing.text.AbstractDocument.getBidiRootElement() definition code for javax.swing.text.AbstractDocument.getBidiRootElement()

public Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  getBidiRootElement()
Returns the root element of the bidirectional structure for this document. Its children represent character runs with a given Unicode bidi level.


getParagraphElement sample code for javax.swing.text.AbstractDocument.getParagraphElement(int) definition code for javax.swing.text.AbstractDocument.getParagraphElement(int)

public abstract Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  getParagraphElement(int pos)
Get the paragraph element containing the given position. Sub-classes must define for themselves what exactly constitutes a paragraph. They should keep in mind however that a paragraph should at least be the unit of text over which to run the Unicode bidirectional algorithm.

Parameters:
pos - the starting offset >= 0
Returns:
the element

getAttributeContext sample code for javax.swing.text.AbstractDocument.getAttributeContext() definition code for javax.swing.text.AbstractDocument.getAttributeContext()

protected final AbstractDocument.AttributeContext sample code for javax.swing.text.AbstractDocument.AttributeContext definition code for javax.swing.text.AbstractDocument.AttributeContext  getAttributeContext()
Fetches the context for managing attributes. This method effectively establishes the strategy used for compressing AttributeSet information.

Returns:
the context

insertUpdate sample code for javax.swing.text.AbstractDocument.insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.insertUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AttributeSet)

protected void insertUpdate(AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng,
                            AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  attr)
Updates document structure as a result of text insertion. This will happen within a write lock. If a subclass of this class reimplements this method, it should delegate to the superclass as well.

Parameters:
chng - a description of the change
attr - the attributes for the change

removeUpdate sample code for javax.swing.text.AbstractDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) definition code for javax.swing.text.AbstractDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent)

protected void removeUpdate(AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng)
Updates any document structure as a result of text removal. This method is called before the text is actually removed from the Content. This will happen within a write lock. If a subclass of this class reimplements this method, it should delegate to the superclass as well.

Parameters:
chng - a description of the change

postRemoveUpdate sample code for javax.swing.text.AbstractDocument.postRemoveUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent) definition code for javax.swing.text.AbstractDocument.postRemoveUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent)

protected void postRemoveUpdate(AbstractDocument.DefaultDocumentEvent sample code for javax.swing.text.AbstractDocument.DefaultDocumentEvent definition code for javax.swing.text.AbstractDocument.DefaultDocumentEvent  chng)
Updates any document structure as a result of text removal. This method is called after the text has been removed from the Content. This will happen within a write lock. If a subclass of this class reimplements this method, it should delegate to the superclass as well.

Parameters:
chng - a description of the change

dump sample code for javax.swing.text.AbstractDocument.dump(java.io.PrintStream) definition code for javax.swing.text.AbstractDocument.dump(java.io.PrintStream)

public void dump(PrintStream sample code for java.io.PrintStream definition code for java.io.PrintStream  out)
Gives a diagnostic dump.

Parameters:
out - the output stream

getContent sample code for javax.swing.text.AbstractDocument.getContent() definition code for javax.swing.text.AbstractDocument.getContent()

protected final AbstractDocument.Content sample code for javax.swing.text.AbstractDocument.Content definition code for javax.swing.text.AbstractDocument.Content  getContent()
Gets the content for the document.

Returns:
the content

createLeafElement sample code for javax.swing.text.AbstractDocument.createLeafElement(javax.swing.text.Element, javax.swing.text.AttributeSet, int, int) definition code for javax.swing.text.AbstractDocument.createLeafElement(javax.swing.text.Element, javax.swing.text.AttributeSet, int, int)

protected Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  createLeafElement(Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  parent,
                                    AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a,
                                    int p0,
                                    int p1)
Creates a document leaf element. Hook through which elements are created to represent the document structure. Because this implementation keeps structure and content separate, elements grow automatically when content is extended so splits of existing elements follow. The document itself gets to decide how to generate elements to give flexibility in the type of elements used.

Parameters:
parent - the parent element
a - the attributes for the element
p0 - the beginning of the range >= 0
p1 - the end of the range >= p0
Returns:
the new element

createBranchElement sample code for javax.swing.text.AbstractDocument.createBranchElement(javax.swing.text.Element, javax.swing.text.AttributeSet) definition code for javax.swing.text.AbstractDocument.createBranchElement(javax.swing.text.Element, javax.swing.text.AttributeSet)

protected Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  createBranchElement(Element sample code for javax.swing.text.Element definition code for javax.swing.text.Element  parent,
                                      AttributeSet sample code for javax.swing.text.AttributeSet definition code for javax.swing.text.AttributeSet  a)
Creates a document branch element, that can contain other elements.

Parameters:
parent - the parent element
a - the attributes
Returns:
the element

getCurrentWriter sample code for javax.swing.text.AbstractDocument.getCurrentWriter() definition code for javax.swing.text.AbstractDocument.getCurrentWriter()

protected final Thread sample code for java.lang.Thread definition code for java.lang.Thread  getCurrentWriter()
Fetches the current writing thread if there is one. This can be used to distinguish whether a method is being called as part of an existing modification or if a lock needs to be acquired and a new transaction started.

Returns:
the thread actively modifying the document or null if there are no modifications in progress

writeLock sample code for javax.swing.text.AbstractDocument.writeLock() definition code for javax.swing.text.AbstractDocument.writeLock()

protected final void writeLock()
Acquires a lock to begin mutating the document this lock protects. There can be no writing, notification of changes, or reading going on in order to gain the lock. Additionally a thread is allowed to gain more than one writeLock, as long as it doesn't attempt to gain additional writeLocks from within document notification. Attempting to gain a writeLock from within a DocumentListener notification will result in an IllegalStateException. The ability to obtain more than one writeLock per thread allows subclasses to gain a writeLock, perform a number of operations, then release the lock.

Calls to writeLock must be balanced with calls to writeUnlock, else the Document will be left in a locked state so that no reading or writing can be done.

Throws:
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - thrown on illegal lock attempt. If the document is implemented properly, this can only happen if a document listener attempts to mutate the document. This situation violates the bean event model where order of delivery is not guaranteed and all listeners should be notified before further mutations are allowed.

writeUnlock sample code for javax.swing.text.AbstractDocument.writeUnlock() definition code for javax.swing.text.AbstractDocument.writeUnlock()

protected final void writeUnlock()
Releases a write lock previously obtained via writeLock. After decrementing the lock count if there are no oustanding locks this will allow a new writer, or readers.

See Also:
writeLock() sample code for javax.swing.text.AbstractDocument.writeLock() definition code for javax.swing.text.AbstractDocument.writeLock()

readLock sample code for javax.swing.text.AbstractDocument.readLock() definition code for javax.swing.text.AbstractDocument.readLock()

public final void readLock()
Acquires a lock to begin reading some state from the document. There can be multiple readers at the same time. Writing blocks the readers until notification of the change to the listeners has been completed. This method should be used very carefully to avoid unintended compromise of the document. It should always be balanced with a readUnlock.

See Also:
readUnlock() sample code for javax.swing.text.AbstractDocument.readUnlock() definition code for javax.swing.text.AbstractDocument.readUnlock()

readUnlock sample code for javax.swing.text.AbstractDocument.readUnlock() definition code for javax.swing.text.AbstractDocument.readUnlock()

public final void readUnlock()
Does a read unlock. This signals that one of the readers is done. If there are no more readers then writing can begin again. This should be balanced with a readLock, and should occur in a finally statement so that the balance is guaranteed. The following is an example.

     readLock();
     try {
         // do something
     } finally {
         readUnlock();
     }
 

See Also:
readLock() sample code for javax.swing.text.AbstractDocument.readLock() definition code for javax.swing.text.AbstractDocument.readLock()