com.threerings.opengl.gui.text
Class Document

java.lang.Object
  extended by com.threerings.opengl.gui.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  UndoableEdit _compoundEdit
           
protected  int _lastUndoId
           
protected  ArrayList<Document.Listener> _listeners
           
protected  String _text
           
protected  UndoableEditSupport _undosup
           
 
Constructor Summary
Document()
           
 
Method Summary
 void addListener(Document.Listener listener)
          Registers a document listener.
 void addUndoableEditListener(UndoableEditListener listener)
          Adds a listener for undoable edits.
 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.
 IntTuple getWordExtents(int start)
          Given a location in the string, finds the extents (start and end offsets) of connected word or non-word characters (depending on the character at the start).
 int indexOfWordEnd(int from)
          Finds the location of the first word end boundary after the specified position.
 boolean insert(int offset, String text, int undoId)
          Inserts the specified text at the specified offset.
 int lastIndexOfWordStart(int from)
          Finds the location of the last word start boundary before the specified position.
protected  void notify(boolean inserted, int offset, int length)
          Notifies document listeners.
 boolean remove(int offset, int length, int undoId)
          Deletes specified run of text at the specified offset.
 void removeListener(Document.Listener listener)
          Clears a document listener registration.
 void removeUndoableEditListener(UndoableEditListener listener)
          Removes a listener for undoable edits.
 boolean replace(int offset, int length, String text, int undoId)
          Replaces the specified run of text with the supplied new text.
 boolean setText(String text, int undoId)
          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

_undosup

protected UndoableEditSupport _undosup

_compoundEdit

protected UndoableEdit _compoundEdit

_lastUndoId

protected int _lastUndoId
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.


addUndoableEditListener

public void addUndoableEditListener(UndoableEditListener listener)
Adds a listener for undoable edits.


removeUndoableEditListener

public void removeUndoableEditListener(UndoableEditListener listener)
Removes a listener for undoable edits.


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,
                       int undoId)
Replaces the current contents of the document with the specified text.

Parameters:
undoId - an id used to group compound edits for undo (-1 if not undoable).
Returns:
true if the text was changed, false if it was rejected by the document validator.

indexOfWordEnd

public int indexOfWordEnd(int from)
Finds the location of the first word end boundary after the specified position.


lastIndexOfWordStart

public int lastIndexOfWordStart(int from)
Finds the location of the last word start boundary before the specified position.


getWordExtents

public IntTuple getWordExtents(int start)
Given a location in the string, finds the extents (start and end offsets) of connected word or non-word characters (depending on the character at the start). Used for double-click selection.


getLength

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


insert

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

Parameters:
undoId - an id used to group compound edits for undo (-1 if not undoable).
Returns:
true if the text was inserted, false if it was rejected by the document validator.

remove

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

Parameters:
undoId - an id used to group compound edits for undo (-1 if not undoable).
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,
                       int undoId)
Replaces the specified run of text with the supplied new text.

Parameters:
undoId - an id used to group compound edits for undo (-1 if not undoable).
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.