|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.gjt.sp.jedit.Buffer
A Buffer
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).
In a BeanShell script, you can obtain the current buffer instance from the
buffer
variable.
This class does not have a public constructor.
Buffers can be opened and closed using methods in the jEdit
class.
This class is partially thread-safe, however you must pay attention to two very important guidelines:
Nested Class Summary | |
static class |
Buffer.TokenList
Deprecated. Use org.gjt.sp.jedit.syntax.DefaultTokenHandler instead |
Field Summary | |
static java.lang.String |
BACKED_UP
Backed up property. |
static java.lang.String |
CARET
Caret info properties. |
static java.lang.String |
ENCODING
Character encoding used when loading and saving. |
static int |
FILE_CHANGED
|
static int |
FILE_DELETED
|
static int |
FILE_NOT_CHANGED
|
static java.lang.String |
GZIPPED
This property is set to 'true' if the file should be GZipped. |
static java.lang.String |
LINESEP
Line separator property. |
static java.lang.String |
SCROLL_HORIZ
|
static java.lang.String |
SCROLL_VERT
This should be a physical line number, so that the scroll position is preserved correctly across reloads (which will affect virtual line numbers, due to fold being reset) |
static java.lang.String |
SELECTION
|
static java.lang.String |
TRAILING_EOL
This property is set to 'true' if the file has a trailing newline. |
Method Summary | |
FoldVisibilityManager |
_getFoldVisibilityManager(JEditTextArea textArea)
Plugins and macros should not call this method. |
void |
_releaseFoldVisibilityManager(FoldVisibilityManager mgr)
Plugins and macros should not call this method. |
void |
addBufferChangeListener(BufferChangeListener listener)
Adds a buffer change listener. |
void |
addMarker(char shortcut,
int pos)
Adds a marker to this buffer. |
void |
addOrRemoveMarker(char shortcut,
int pos)
If a marker is set on the line of the position, it is removed. |
void |
autosave()
Autosaves this buffer. |
void |
beginCompoundEdit()
Starts a compound edit. |
int |
checkFileStatus()
Check if the buffer has changed on disk. |
void |
checkModTime(EditPane editPane)
Check if the buffer has changed on disk. |
javax.swing.text.Position |
createPosition(int offset)
Creates a floating position. |
void |
endCompoundEdit()
Ends a compound edit. |
java.io.File |
getAutosaveFile()
Returns the autosave file for this buffer. |
boolean |
getBooleanProperty(java.lang.String name)
Returns the value of a boolean property. |
BufferChangeListener[] |
getBufferChangeListeners()
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). |
javax.swing.text.Element |
getDefaultRootElement()
Deprecated. Use getLineOfOffset() ,
getLineStartOffset() , and
getLineEndOffset() instead. |
java.lang.String |
getDirectory()
Returns the directory containing this buffer. |
java.io.File |
getFile()
Deprecated. Do not call this method, use getPath()
instead. |
int[] |
getFoldAtLine(int line)
Returns an array. |
int |
getFoldLevel(int line)
Returns the fold level of the specified line. |
javax.swing.Icon |
getIcon()
Returns this buffer's icon. |
int |
getIndentForLine(int lineIndex)
Returns the ideal leading indent for the specified line. |
int |
getIndentSize()
Returns the indent size used in this buffer. |
int |
getIndex()
Returns the position of this buffer in the buffer list. |
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. |
long |
getLastModified()
Returns the last time jEdit modified the file on disk. |
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 lineIndex)
Returns the text on the specified line. |
void |
getLineText(int lineIndex,
javax.swing.text.Segment segment)
Returns the specified line in a Segment . |
Marker |
getMarker(char shortcut)
Returns the marker with the specified shortcut. |
Marker |
getMarkerAtLine(int line)
Returns the first marker at the specified line, or null
if there is none. |
Marker |
getMarkerInRange(int start,
int end)
Returns the first marker within the specified range. |
java.util.Vector |
getMarkers()
Returns a vector of markers. |
Mode |
getMode()
Returns this buffer's edit mode. |
java.lang.String |
getName()
Returns the name of this buffer. |
Buffer |
getNext()
Returns the next buffer in the list. |
int |
getOffsetOfVirtualColumn(int line,
int column,
int[] totalVirtualWidth)
Returns the array offset of a virtual column number (taking tabs into account) in the segment. |
javax.swing.text.Element |
getParagraphElement(int offset)
Deprecated. |
java.lang.String |
getPath()
Returns the path name of this buffer. |
Buffer |
getPrev()
Returns the previous buffer in the list. |
java.lang.Object |
getProperty(java.lang.Object name)
Returns the value of a buffer-local property. |
RE |
getRegexpProperty(java.lang.String name,
int cflags,
RESyntax syntax)
Returns the value of a property as a regular expression. |
javax.swing.text.Element[] |
getRootElements()
Deprecated. |
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()
This method is only public so that the OffsetManager
class can use it. |
VFS |
getVFS()
Returns the virtual filesystem responsible for loading and saving this buffer. |
int |
getVirtualWidth(int line,
int column)
Returns the virtual column number (taking tabs into account) of the specified position. |
void |
handleMessage(EBMessage msg)
Handles a message sent on the EditBus. |
boolean |
indentLine(int lineIndex,
boolean canIncreaseIndent,
boolean canDecreaseIndent)
If auto indent is enabled, this method is called when the `Tab' or `Enter' key is pressed to perform mode-specific indentation and return true, or return false if a normal tab is to be inserted. |
void |
indentLines(int[] lines)
Indents all specified lines. |
void |
indentLines(int start,
int end)
Indents all specified lines. |
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. |
boolean |
insertFile(View view,
java.lang.String path)
Loads a file from disk, and inserts it into this buffer. |
void |
insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet attr)
Deprecated. Call insert() instead. |
boolean |
insideCompoundEdit()
Returns if a compound edit is currently active. |
void |
invalidateCachedFoldLevels()
Invalidates all cached fold level information. |
boolean |
isClosed()
Returns true if this buffer has been closed with jEdit.closeBuffer(View,Buffer) . |
boolean |
isDirty()
Returns whether there have been unsaved changes to this buffer. |
boolean |
isEditable()
Returns true if this file is editable, false otherwise. |
boolean |
isFoldStart(int line)
Returns if the specified line begins a fold. |
boolean |
isLoaded()
Returns true if the buffer is loaded. |
boolean |
isNewFile()
Returns whether this buffer lacks a corresponding version on disk. |
boolean |
isNextLineRequested()
Returns true if the next line should be repainted. |
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 |
isTemporary()
Returns if this is a temporary buffer. |
boolean |
isTransactionInProgress()
Returns if an undo or compound edit is currently in progress. |
boolean |
isUntitled()
Returns true if this file is 'untitled'. |
boolean |
load(View view,
boolean reload)
Loads the buffer from disk, even if it is loaded already. |
Buffer.TokenList |
markTokens(int lineIndex)
Deprecated. Use the other form of markTokens() instead |
void |
markTokens(int lineIndex,
TokenHandler tokenHandler)
Returns the syntax tokens for the specified line. |
void |
propertiesChanged()
Reloads settings from the properties. |
void |
putBooleanProperty(java.lang.String name,
boolean value)
Deprecated. Call setBooleanProperty() instead |
void |
putProperty(java.lang.Object name,
java.lang.Object value)
Deprecated. Call setProperty() instead. |
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 |
reload(View view)
Reloads the buffer from disk, asking for confirmation if the buffer has unsaved changes. |
void |
remove(int offset,
int length)
Removes the specified rang efrom the buffer. |
void |
removeAllMarkers()
Removes all defined markers. |
void |
removeBufferChangeListener(BufferChangeListener listener)
Removes a buffer change listener. |
void |
removeMarker(int line)
Removes all markers at the specified line. |
void |
removeTrailingWhiteSpace(int[] lines)
Removes trailing whitespace from all lines in the specified list. |
boolean |
save(View view,
java.lang.String path)
Saves this buffer to the specified path name, or the current path name if it's null. |
boolean |
save(View view,
java.lang.String path,
boolean rename)
Saves this buffer to the specified path name, or the current path name if it's null. |
boolean |
saveAs(View view,
boolean rename)
Prompts the user for a file to save this buffer to. |
void |
setBooleanProperty(java.lang.String name,
boolean value)
Sets a boolean property. |
void |
setDirty(boolean d)
Sets the 'dirty' (changed since last save) flag of this buffer. |
void |
setIntegerProperty(java.lang.String name,
int value)
Sets an integer property. |
void |
setLastModified(long modTime)
Sets the last time jEdit modified the file on disk. |
void |
setMode()
Sets this buffer's edit mode by calling the accept() method of each registered edit mode. |
void |
setMode(Mode mode)
Sets this buffer's edit mode. |
void |
setNewFile(boolean newFile)
Sets the new file flag. |
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 |
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 |
showInsertFileDialog(View view)
Displays the 'insert file' dialog box and inserts the selected file into the buffer. |
void |
toggleLineSeparator(View view)
Toggles the line separator between the three available settings. |
void |
toggleWordWrap(View view)
Toggles word wrap between the three available modes. |
java.lang.String |
toString()
Returns a string representation of this buffer. |
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, wait, wait, wait |
Field Detail |
public static final java.lang.String LINESEP
public static final java.lang.String BACKED_UP
public static final java.lang.String CARET
public static final java.lang.String SELECTION
public static final java.lang.String SCROLL_VERT
public static final java.lang.String SCROLL_HORIZ
public static final java.lang.String ENCODING
public static final java.lang.String TRAILING_EOL
public static final java.lang.String GZIPPED
public static final int FILE_NOT_CHANGED
public static final int FILE_CHANGED
public static final int FILE_DELETED
Method Detail |
public void showInsertFileDialog(View view)
view
- The viewpublic void reload(View view)
view
- The viewpublic boolean load(View view, boolean reload)
view
- The viewreload
- If true, user will not be asked to recover autosave
file, if anypublic boolean insertFile(View view, java.lang.String path)
view
- The viewpublic void autosave()
public boolean saveAs(View view, boolean rename)
view
- The viewrename
- True if the buffer's path should be changed, false
if only a copy should be saved to the specified filenamepublic boolean save(View view, java.lang.String path)
view
- The viewpath
- The path name to save the buffer to, or null to use
the existing pathpublic boolean save(View view, java.lang.String path, boolean rename)
view
- The viewpath
- The path name to save the buffer to, or null to use
the existing pathrename
- True if the buffer's path should be changed, false
if only a copy should be saved to the specified filenamepublic int checkFileStatus()
NOT_CHANGED
, CHANGED
, or
DELETED
.public void checkModTime(EditPane editPane)
public long getLastModified()
public void setLastModified(long modTime)
modTime
- The new modification timepublic VFS getVFS()
public final java.io.File getAutosaveFile()
public final java.lang.String getName()
public final java.lang.String getPath()
public java.lang.String getDirectory()
public final boolean isClosed()
jEdit.closeBuffer(View,Buffer)
.
This method is thread-safe.
public final boolean isLoaded()
public final boolean isPerformingIO()
public final boolean isNewFile()
public final void setNewFile(boolean newFile)
newFile
- The new file flagpublic final boolean isUntitled()
public final boolean isDirty()
public final boolean isReadOnly()
public final boolean isEditable()
public final void setReadOnly(boolean readOnly)
readOnly
- The read only flagpublic void setDirty(boolean d)
public boolean isTemporary()
jEdit.openTemporary(View,String,String,boolean)
,
jEdit.commitTemporary(Buffer)
public javax.swing.Icon getIcon()
public final void readLock()
readLock()
and readUnlock()
.
public final void readUnlock()
readLock()
and readUnlock()
.
public final void writeLock()
writeLock()
and writeUnlock()
.
public final void writeUnlock()
writeLock()
and writeUnlock()
.
public int getLength()
public int getLineCount()
public final 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 java.lang.String getLineText(int lineIndex)
lineIndex
- The line
public void getLineText(int lineIndex, javax.swing.text.Segment segment)
Segment
.
Using a
This method is thread-safe.
lineIndex
- 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 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 void addBufferChangeListener(BufferChangeListener listener)
listener
- The listenerpublic void removeBufferChangeListener(BufferChangeListener listener)
listener
- The listenerpublic BufferChangeListener[] getBufferChangeListeners()
public void propertiesChanged()
syntax
or folding
buffer-local properties are changed.
public int getTabSize()
getProperty("tabSize")
.
This method is thread-safe.
public final 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 void setProperty(java.lang.String name, java.lang.Object value)
name
- The property namevalue
- The property valuepublic void unsetProperty(java.lang.String name)
name
- The property namepublic 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 RE getRegexpProperty(java.lang.String name, int cflags, RESyntax syntax) throws REException
name
- The property namecflags
- Regular expression compilation flagssyntax
- Regular expression syntax
REException
public 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 void toggleWordWrap(View view)
view
- We show a message in the view's status barpublic void toggleLineSeparator(View view)
view
- We show a message in the view's status barpublic final Mode getMode()
public void setMode(Mode mode)
mode
- The modepublic void setMode()
public void markTokens(int lineIndex, TokenHandler tokenHandler)
lineIndex
- The line numbertokenHandler
- The token handler that will receive the syntax
tokenspublic boolean isNextLineRequested()
public TokenMarker getTokenMarker()
OffsetManager
class can use it.
public void removeTrailingWhiteSpace(int[] lines)
lines
- The line numberspublic void shiftIndentLeft(int[] lines)
lines
- The line numberspublic void shiftIndentRight(int[] lines)
lines
- The line numberspublic boolean indentLine(int lineIndex, boolean canIncreaseIndent, boolean canDecreaseIndent)
canIncreaseIndent
- If false, nothing will be done if the
calculated indent is greater than the currentcanDecreaseIndent
- If false, nothing will be done if the
calculated indent is less than the current
public 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 int getIndentForLine(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 void putProperty(java.lang.Object name, java.lang.Object value)
setProperty()
instead.
public void putBooleanProperty(java.lang.String name, boolean value)
setBooleanProperty()
instead
public Buffer.TokenList markTokens(int lineIndex)
markTokens()
instead
public javax.swing.text.Element[] getRootElements()
public javax.swing.text.Element getParagraphElement(int offset)
public javax.swing.text.Element getDefaultRootElement()
getLineOfOffset()
,
getLineStartOffset()
, and
getLineEndOffset()
instead.
public void insertString(int offset, java.lang.String str, javax.swing.text.AttributeSet attr)
insert()
instead.
public final java.io.File getFile()
getPath()
instead.
public boolean isFoldStart(int line)
public void invalidateCachedFoldLevels()
public int getFoldLevel(int line)
line
- A physical line indexpublic int[] getFoldAtLine(int line)
line
- The line numberpublic javax.swing.text.Position createPosition(int offset)
offset
- The offsetpublic final java.util.Vector getMarkers()
public void addOrRemoveMarker(char shortcut, int pos)
pos
- The position of the markershortcut
- The shortcut ('\0' if none)public void addMarker(char shortcut, int pos)
pos
- The position of the markershortcut
- The shortcut ('\0' if none)public Marker getMarkerInRange(int start, int end)
start
- The start offsetend
- The end offsetpublic Marker getMarkerAtLine(int line)
null
if there is none.
line
- The line numberpublic void removeMarker(int line)
line
- The line numberpublic void removeAllMarkers()
public Marker getMarker(char shortcut)
shortcut
- The shortcutpublic final Buffer getNext()
public final Buffer getPrev()
public final int getIndex()
public java.lang.String toString()
toString
in class java.lang.Object
public void handleMessage(EBMessage msg)
EBComponent
EBMessage
class. Typically
this is done with one or more if
blocks that test
whether the message is an instance of a derived message class in
which the component has an interest. For example:
if(msg instanceof BufferUpdate) { // a buffer's state has changed! } else if(msg instanceof ViewUpdate) { // a view's state has changed! } // ... and so on
handleMessage
in interface EBComponent
msg
- The messagepublic FoldVisibilityManager _getFoldVisibilityManager(JEditTextArea textArea)
JEditTextArea.getFoldVisibilityManager()
instead.
textArea
- The text areapublic void _releaseFoldVisibilityManager(FoldVisibilityManager mgr)
mgr
- The fold visibility manager
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |