danger.util
Class TextBuffer
java.lang.Object
|
+--danger.util.TextBuffer
- public class TextBuffer
- extends java.lang.Object
This class implements the 'buffer-gap' method of storage management
for a buffer that is frequently edited.
This method assumes that there is a narrow locality to the editing
taking place in a buffer, which is the common case for a text editor.
0 1 2 3 4 5 6 7 8 9 10 11 T
| D | a | n | g | e | r | o | u | s | | | | | B | u | f |
-----------------------------------------------------------------
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 B
P GS GE
This diagram illustrates how the buffer gap system works.
P is the insertion/deletion (cursor) location in the current buffer
GS is the start of the buffer gap
GE is the end of the buffer gap
When an editor action needs to be taken the gap is moved within the
buffer so that GS is at the same location as P.
For an insertion, the new character is added after GS and GS is moved
to the right by one character, thus shrinking the gap.
For a deletion, GS is simply moved one character to the left, growing
the gap and causing future references to the text to skip over the
deleted character.
There are two index systems at work within the buffer. The
first, labeled 'T' is the Text index. This indexes into the
actual displayable text and skips over the characters that are
the gap.
The second, labeled 'B', is the Buffer index system. These are
the positions used by the buffer routines. Note that they reference
the spaces between characters rather than the characters themselves.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TextBuffer
public TextBuffer()
TextBuffer
public TextBuffer(int inInitialSize)
drawText
public final void drawText(Pen p,
int x,
int y,
int offset,
int length)
moveGapToPoint
public void moveGapToPoint()
insert
public void insert(java.lang.String inString)
insert
public void insert(char inChar)
setChar
public void setChar(int position,
char inChar)
clear
public void clear()
deleteChar
public void deleteChar()
forwardDeleteChar
public void forwardDeleteChar()
delete
public void delete(int numChar)
deleteLastWord
public void deleteLastWord()
getLastWord
public java.lang.String getLastWord(char[] nonAlphaExceptionList)
getLastWordDelimPosition
public int getLastWordDelimPosition(char[] nonAlphaExceptionList)
getLastNonWhiteSpaceCharPosition
public int getLastNonWhiteSpaceCharPosition()
growBuffer
public void growBuffer()
growBuffer
public void growBuffer(int inExtraSize)
getPoint
public int getPoint()
setPoint
public void setPoint(int inPosition)
length
public int length()
charAt
public char charAt(int index)
getString
public java.lang.String getString()
getString
public java.lang.String getString(int inFirstChar,
int inNumChars)
getChars
public char[] getChars()
getChars
public char[] getChars(int inFirstChar,
int inNumChars)
setInputFilter
public void setInputFilter(TextInputFilter inFilter)
dumpBuffer
public void dumpBuffer(Pen p,
View v)
dumpBuffer
public void dumpBuffer()
setSelectionLength
public void setSelectionLength(int selectionLength)
getSelectionLength
public int getSelectionLength()
Danger Confidential. Copyright © 2000-2003, Danger Inc.