com.jmex.bui.text
Class Document

java.lang.Object
  extended by com.jmex.bui.text.Document
Direct Known Subclasses:
IntegerDocument, LengthLimitedDocument

public class Document
extends Object

Defines the model that underlies the BUI text components.


Nested Class Summary
static interface Document.Listener
          Used to listen for changes to this document.
 
Field Summary
protected  ArrayList<Document.Listener> _listeners
           
protected  String _text
           
 
Constructor Summary
Document()
           
 
Method Summary
 void addListener(Document.Listener listener)
          Registers a document listener.
 int getLength()
          Returns the number of characters in the document.
 String getText()
          Returns the entire text of the document.
 String getText(int offset, int length)
          Returns a subset of the text of the document.
 boolean insert(int offset, String text)
          Inserts the specified text at the specified offset.
protected  void notify(boolean inserted, int offset, int length)
          Notifies document listeners.
 boolean remove(int offset, int length)
          Deletes specified run of text at the specified offset.
 void removeListener(Document.Listener listener)
          Clears a document listener registration.
 boolean replace(int offset, int length, String text)
          Replaces the specified run of text with the supplied new text.
 boolean setText(String text)
          Replaces the current contents of the document with the specified text.
protected  boolean validateEdit(String oldText, String newText)
          Provides an opportunity for edits to be rejected before being applied to the document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_text

protected String _text

_listeners

protected ArrayList<Document.Listener> _listeners
Constructor Detail

Document

public Document()
Method Detail

addListener

public void addListener(Document.Listener listener)
Registers a document listener.


removeListener

public void removeListener(Document.Listener listener)
Clears a document listener registration.


getText

public String getText()
Returns the entire text of the document.


getText

public String getText(int offset,
                      int length)
Returns a subset of the text of the document.


setText

public boolean setText(String text)
Replaces the current contents of the document with the specified text.

Returns:
true if the text was changed, false if it was rejected by the document validator.

getLength

public int getLength()
Returns the number of characters in the document.


insert

public boolean insert(int offset,
                      String text)
Inserts the specified text at the specified offset.

Returns:
true if the text was inserted, false if it was rejected by the document validator.

remove

public boolean remove(int offset,
                      int length)
Deletes specified run of text at the specified offset.

Returns:
true if the text was removed, false if it was rejected by the document validator.

replace

public boolean replace(int offset,
                       int length,
                       String text)
Replaces the specified run of text with the supplied new text.

Returns:
true if the text was replaced, false if it was rejected by the document validator.

validateEdit

protected boolean validateEdit(String oldText,
                               String newText)
Provides an opportunity for edits to be rejected before being applied to the document.

Returns:
true if the document should be configured with the specified new text, false if the old text should remain.

notify

protected void notify(boolean inserted,
                      int offset,
                      int length)
Notifies document listeners.



Copyright © 2008 Michael Bayne. All Rights Reserved.