|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gjt.sp.jedit.buffer.JEditBuffer
public class JEditBuffer
A JEditBuffer
represents the contents of an open text
file as it is maintained in the computer's memory (as opposed to
how it may be stored on a disk).
This class is partially thread-safe, however you must pay attention to two very important guidelines:
Nested Class Summary | |
---|---|
protected static class |
JEditBuffer.PropValue
|
Field Summary | |
---|---|
static java.lang.String |
ENCODING
Character encoding used when loading and saving. |
static int |
HIGH_PRIORITY
|
static java.lang.String |
LINESEP
Line separator property. |
static int |
NORMAL_PRIORITY
|
protected javax.swing.text.Segment |
seg
|
protected boolean |
textMode
|
protected UndoManager |
undoMgr
|
Constructor Summary | |
---|---|
JEditBuffer(java.util.Hashtable props)
|
Method Summary | |
---|---|
void |
addBufferListener(BufferListener listener)
Adds a buffer change listener. |
void |
addBufferListener(BufferListener listener,
int priority)
Adds a buffer change listener. |
void |
beginCompoundEdit()
Starts a compound edit. |
javax.swing.text.Position |
createPosition(int offset)
Creates a floating position. |
void |
endCompoundEdit()
Ends a compound edit. |
protected void |
fireBufferLoaded()
|
protected void |
fireContentInserted(int startLine,
int offset,
int numLines,
int length)
|
protected void |
fireContentRemoved(int startLine,
int offset,
int numLines,
int length)
|
protected void |
fireFoldHandlerChanged()
|
protected void |
fireFoldLevelChanged(int start,
int end)
|
protected void |
firePreContentRemoved(int startLine,
int offset,
int numLines,
int length)
|
protected void |
fireTransactionComplete()
|
boolean |
getBooleanProperty(java.lang.String name)
Returns the value of a boolean property. |
BufferListener[] |
getBufferListeners()
Returns an array of registered buffer change listeners. |
java.lang.String |
getContextSensitiveProperty(int offset,
java.lang.String name)
Some settings, like comment start and end strings, can vary between different parts of a buffer (HTML text and inline JavaScript, for example). |
int |
getCurrentIndentForLine(int lineIndex,
int[] whitespaceChars)
Returns the line's current leading indent. |
java.lang.Object |
getDefaultProperty(java.lang.String key)
|
int[] |
getFoldAtLine(int line)
Returns an array. |
FoldHandler |
getFoldHandler()
Returns the current buffer's fold handler. |
int |
getFoldLevel(int line)
Returns the fold level of the specified line. |
int |
getIdealIndentForLine(int lineIndex)
Returns the ideal leading indent for the specified line. |
int |
getIndentSize()
Returns the indent size used in this buffer. |
int |
getIntegerProperty(java.lang.String name,
int defaultValue)
Returns the value of an integer property. |
KeywordMap |
getKeywordMapAtOffset(int offset)
Returns the syntax highlighting keyword map in effect at the specified offset. |
int |
getLength()
Returns the number of characters in the buffer. |
int |
getLineCount()
Returns the number of physical lines in the buffer. |
int |
getLineEndOffset(int line)
Returns the end offset of the specified line. |
int |
getLineLength(int line)
Returns the length of the specified line. |
int |
getLineOfOffset(int offset)
Returns the line containing the specified offset. |
int |
getLineStartOffset(int line)
Returns the start offset of the specified line. |
java.lang.String |
getLineText(int line)
Returns the text on the specified line. |
void |
getLineText(int line,
javax.swing.text.Segment segment)
Returns the specified line in a Segment . |
int |
getOffsetOfVirtualColumn(int line,
int column,
int[] totalVirtualWidth)
Returns the offset of a virtual column number (taking tabs into account) relative to the start of the line in question. |
java.util.regex.Pattern |
getPatternProperty(java.lang.String name,
int flags)
Returns the value of a property as a regular expression. |
int |
getPriorNonEmptyLine(int lineIndex)
Auto indent needs this. |
java.lang.Object |
getProperty(java.lang.Object name)
Returns the value of a buffer-local property. |
ParserRuleSet |
getRuleSetAtOffset(int offset)
Returns the syntax highlighting ruleset at the specified offset. |
java.lang.String |
getStringProperty(java.lang.String name)
Returns the value of a string property. |
int |
getTabSize()
Returns the tab size used in this buffer. |
java.lang.String |
getText(int start,
int length)
Returns the specified text range. |
void |
getText(int start,
int length,
javax.swing.text.Segment seg)
Returns the specified text range in a Segment . |
TokenMarker |
getTokenMarker()
|
int |
getVirtualWidth(int line,
int column)
Returns the virtual column number (taking tabs into account) of the specified position. |
boolean |
indentLine(int lineIndex,
boolean canDecreaseIndent)
Indents the specified line. |
boolean |
indentLine(int lineIndex,
boolean canIncreaseIndent,
boolean canDecreaseIndent)
Deprecated. Use indentLine(int,boolean) instead. |
void |
indentLines(int[] lines)
Indents all specified lines. |
void |
indentLines(int start,
int end)
Indents all specified lines. |
protected void |
initIndentRules()
|
void |
insert(int offset,
javax.swing.text.Segment seg)
Inserts a string into the buffer. |
void |
insert(int offset,
java.lang.String str)
Inserts a string into the buffer. |
void |
insertAtColumn(int line,
int col,
java.lang.String str)
Like the insert(int,String) method, but inserts the string at
the specified virtual column. |
int |
insertIndented(int offset,
java.lang.String text)
Inserts a string into the buffer, indenting each line of the string to match the indent of the first line. |
boolean |
insideCompoundEdit()
Returns if a compound edit is currently active. |
void |
invalidateCachedFoldLevels()
Invalidates all cached fold level information. |
protected void |
invalidateFoldLevels()
|
boolean |
isDirty()
Returns whether there have been unsaved changes to this buffer. |
boolean |
isEditable()
Returns true if this file is editable, false otherwise. |
boolean |
isElectricKey(char ch)
Should inserting this character trigger a re-indent of the current line? |
protected boolean |
isFileReadOnly()
|
boolean |
isFoldEnd(int line)
Returns if the specified line ends a fold. |
boolean |
isFoldStart(int line)
Returns if the specified line begins a fold. |
boolean |
isLoading()
|
boolean |
isPerformingIO()
Returns true if the buffer is currently performing I/O. |
boolean |
isReadOnly()
Returns true if this file is read only, false otherwise. |
boolean |
isTransactionInProgress()
Returns if an undo or compound edit is currently in progress. |
boolean |
isUndoInProgress()
Returns if an undo or redo is currently being performed. |
protected void |
loadText(javax.swing.text.Segment seg,
IntegerArray endOffsets)
|
void |
markTokens(int lineIndex,
TokenHandler tokenHandler)
Returns the syntax tokens for the specified line. |
protected void |
parseBufferLocalProperties()
|
void |
readLock()
The buffer is guaranteed not to change between calls to readLock() and readUnlock() . |
void |
readUnlock()
The buffer is guaranteed not to change between calls to readLock() and readUnlock() . |
void |
redo(JEditTextArea textArea)
Redoes the most recently undone edit. |
void |
remove(int offset,
int length)
Removes the specified rang efrom the buffer. |
void |
removeBufferListener(BufferListener listener)
Removes a buffer change listener. |
void |
removeTrailingWhiteSpace(int[] lines)
Removes trailing whitespace from all lines in the specified list. |
void |
resetCachedProperties()
|
void |
setBooleanProperty(java.lang.String name,
boolean value)
Sets a boolean property. |
void |
setDefaultProperty(java.lang.String name,
java.lang.Object value)
|
void |
setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer. |
protected void |
setFileReadOnly(boolean readOnly)
|
void |
setFoldHandler(FoldHandler foldHandler)
Sets the buffer's fold handler. |
void |
setIntegerProperty(java.lang.String name,
int value)
Sets an integer property. |
void |
setLoading(boolean loading)
|
void |
setPerformingIO(boolean io)
Returns true if the buffer is currently performing I/O. |
void |
setProperty(java.lang.String name,
java.lang.Object value)
Sets the value of a buffer-local property. |
void |
setReadOnly(boolean readOnly)
Sets the read only flag. |
void |
setStringProperty(java.lang.String name,
java.lang.String value)
Sets a string property. |
void |
setTokenMarker(TokenMarker tokenMarker)
|
void |
shiftIndentLeft(int[] lines)
Shifts the indent of each line in the specified list to the left. |
void |
shiftIndentRight(int[] lines)
Shifts the indent of each line in the specified list to the right. |
void |
undo(JEditTextArea textArea)
Undoes the most recent edit. |
void |
unsetProperty(java.lang.String name)
Clears the value of a buffer-local property. |
void |
writeLock()
Attempting to obtain read lock will block between calls to writeLock() and writeUnlock() . |
void |
writeUnlock()
Attempting to obtain read lock will block between calls to writeLock() and writeUnlock() . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String LINESEP
public static final java.lang.String ENCODING
public static final int NORMAL_PRIORITY
public static final int HIGH_PRIORITY
protected javax.swing.text.Segment seg
protected boolean textMode
protected UndoManager undoMgr
Constructor Detail |
---|
public JEditBuffer(java.util.Hashtable props)
Method Detail |
---|
public boolean isDirty()
public boolean isLoading()
public void setLoading(boolean loading)
public boolean isPerformingIO()
public void setPerformingIO(boolean io)
public boolean isEditable()
public boolean isReadOnly()
public void setReadOnly(boolean readOnly)
readOnly
- The read only flagpublic void setDirty(boolean d)
public void readLock()
readLock()
and readUnlock()
.
public void readUnlock()
readLock()
and readUnlock()
.
public void writeLock()
writeLock()
and writeUnlock()
.
public void writeUnlock()
writeLock()
and writeUnlock()
.
public int getLength()
public int getLineCount()
public int getLineOfOffset(int offset)
offset
- The offsetpublic int getLineStartOffset(int line)
line
- The line
public int getLineEndOffset(int line)
line
- The line
public int getLineLength(int line)
line
- The linepublic int getPriorNonEmptyLine(int lineIndex)
public java.lang.String getLineText(int line)
line
- The line
public void getLineText(int line, javax.swing.text.Segment segment)
Segment
.
Using a
This method is thread-safe.
line
- The linepublic java.lang.String getText(int start, int length)
start
- The start offsetlength
- The number of characters to getpublic void getText(int start, int length, javax.swing.text.Segment seg)
Segment
.
Using a
This method is thread-safe.
start
- The start offsetlength
- The number of characters to getseg
- The segment to copy the text topublic void insert(int offset, java.lang.String str)
offset
- The offsetstr
- The stringpublic void insert(int offset, javax.swing.text.Segment seg)
offset
- The offsetseg
- The segmentpublic void remove(int offset, int length)
offset
- The start offsetlength
- The number of characters to removepublic void removeTrailingWhiteSpace(int[] lines)
lines
- The line numberspublic void shiftIndentLeft(int[] lines)
lines
- The line numberspublic void shiftIndentRight(int[] lines)
lines
- The line numberspublic void indentLines(int start, int end)
start
- The first line to indentend
- The last line to indentpublic void indentLines(int[] lines)
lines
- The line numberspublic boolean indentLine(int lineIndex, boolean canIncreaseIndent, boolean canDecreaseIndent)
indentLine(int,boolean)
instead.
public boolean indentLine(int lineIndex, boolean canDecreaseIndent)
lineIndex
- The line number to indentcanDecreaseIndent
- If true, the indent can be decreased as a
result of this. Set this to false for Tab key.
public int getCurrentIndentForLine(int lineIndex, int[] whitespaceChars)
lineIndex
- The line numberwhitespaceChars
- If this is non-null, the number of whitespace
characters is stored at the 0 indexpublic int getIdealIndentForLine(int lineIndex)
lineIndex
- The line numberpublic int getVirtualWidth(int line, int column)
line
- The line numbercolumn
- The column numberpublic int getOffsetOfVirtualColumn(int line, int column, int[] totalVirtualWidth)
line
- The line numbercolumn
- The virtual column numbertotalVirtualWidth
- If this array is non-null, the total
virtual width will be stored in its first location if this method
returns -1.
public void insertAtColumn(int line, int col, java.lang.String str)
insert(int,String)
method, but inserts the string at
the specified virtual column. Inserts spaces as appropriate if
the line is shorter than the column.
line
- The line numbercol
- The virtual column numberstr
- The stringpublic int insertIndented(int offset, java.lang.String text)
offset
- The offsettext
- The text
public boolean isElectricKey(char ch)
public void markTokens(int lineIndex, TokenHandler tokenHandler)
lineIndex
- The line numbertokenHandler
- The token handler that will receive the syntax
tokenspublic TokenMarker getTokenMarker()
public void setTokenMarker(TokenMarker tokenMarker)
public javax.swing.text.Position createPosition(int offset)
offset
- The offsetpublic int getTabSize()
getProperty("tabSize")
.
This method is thread-safe.
public int getIndentSize()
getProperty("indentSize")
.
This method is thread-safe.
public java.lang.Object getProperty(java.lang.Object name)
Using this method is generally discouraged, because it returns an
Object
which must be cast to another type
in order to be useful, and this can cause problems if the object
is of a different type than what the caller expects.
The following methods should be used instead:
getStringProperty(String)
getBooleanProperty(String)
getIntegerProperty(String,int)
#getRegexpProperty(String,int,gnu.regexp.RESyntax)
name
- The property name. For backwards compatibility, this
is an Object
, not a String
.public java.lang.Object getDefaultProperty(java.lang.String key)
public void setProperty(java.lang.String name, java.lang.Object value)
name
- The property namevalue
- The property valuepublic void setDefaultProperty(java.lang.String name, java.lang.Object value)
public void unsetProperty(java.lang.String name)
name
- The property namepublic void resetCachedProperties()
public java.lang.String getStringProperty(java.lang.String name)
name
- The property namepublic void setStringProperty(java.lang.String name, java.lang.String value)
name
- The property namevalue
- The valuepublic boolean getBooleanProperty(java.lang.String name)
name
- The property namepublic void setBooleanProperty(java.lang.String name, boolean value)
name
- The property namevalue
- The valuepublic int getIntegerProperty(java.lang.String name, int defaultValue)
name
- The property namepublic void setIntegerProperty(java.lang.String name, int value)
name
- The property namevalue
- The valuepublic java.util.regex.Pattern getPatternProperty(java.lang.String name, int flags)
name
- The property namecflags
- Regular expression compilation flagspublic ParserRuleSet getRuleSetAtOffset(int offset)
public KeywordMap getKeywordMapAtOffset(int offset)
offset
- The offsetpublic java.lang.String getContextSensitiveProperty(int offset, java.lang.String name)
offset
- The offsetname
- The property namepublic boolean isFoldStart(int line)
public boolean isFoldEnd(int line)
public void invalidateCachedFoldLevels()
public int getFoldLevel(int line)
line
- A physical line indexpublic int[] getFoldAtLine(int line)
line
- The line numberpublic FoldHandler getFoldHandler()
public void setFoldHandler(FoldHandler foldHandler)
public void undo(JEditTextArea textArea)
public void redo(JEditTextArea textArea)
public boolean isTransactionInProgress()
BufferChangeListener.transactionComplete(Buffer)
buffer event will get fired.
public void beginCompoundEdit()
endCompoundEdit()
are called will be merged
into one. This can be used to make a complex operation
undoable in one step. Nested calls to
beginCompoundEdit()
behave as expected,
requiring the same number of endCompoundEdit()
calls to end the edit.
endCompoundEdit()
public void endCompoundEdit()
beginCompoundEdit()
was called can now
be undone in one step by calling undo(JEditTextArea)
.
beginCompoundEdit()
public boolean insideCompoundEdit()
public boolean isUndoInProgress()
public void addBufferListener(BufferListener listener, int priority)
listener
- The listenerpriority
- Listeners with HIGH_PRIORITY get the event before
listeners with NORMAL_PRIORITYpublic void addBufferListener(BufferListener listener)
listener
- The listenerpublic void removeBufferListener(BufferListener listener)
listener
- The listenerpublic BufferListener[] getBufferListeners()
protected void fireFoldLevelChanged(int start, int end)
protected void fireContentInserted(int startLine, int offset, int numLines, int length)
protected void fireContentRemoved(int startLine, int offset, int numLines, int length)
protected void firePreContentRemoved(int startLine, int offset, int numLines, int length)
protected void fireTransactionComplete()
protected void fireFoldHandlerChanged()
protected void fireBufferLoaded()
protected boolean isFileReadOnly()
protected void setFileReadOnly(boolean readOnly)
protected void loadText(javax.swing.text.Segment seg, IntegerArray endOffsets)
protected void invalidateFoldLevels()
protected void parseBufferLocalProperties()
protected void initIndentRules()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |