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.
 
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.
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.


Copyright © 2011. All Rights Reserved.