public class TextFileEditor
extends java.lang.Object
Please note that line and column numbers start at 1 while TextBuffer lines start at 0!
Modifier and Type | Field and Description |
---|---|
static java.lang.Character |
END_OF_FILE_CHAR
Means end of file in the buffer held by the editor.
|
Constructor and Description |
---|
TextFileEditor()
Creates a new instance of TextFileEditor.
|
Modifier and Type | Method and Description |
---|---|
void |
appendBuffer(TextBuffer buffer)
Appends another buffer into this one at the end.
|
void |
clearSelection()
Clears the selection.
|
void |
deleteCurrentLine()
Removes the current line.
|
void |
deleteCurrentWord()
Deletes the current word.
|
void |
deleteCurrentWord(char delimeter)
Deletes the current word as denoted by the specified delimeter.
|
void |
deleteSelection()
Deletes the current selection and sets the current position to the position right after the deleted text.
|
void |
endSelection()
Marks the end of the selection at the current position.
|
boolean |
find(java.lang.String text)
Finds the specified text and moves the current position.
|
java.util.List<Occurence> |
findAllBlankLines()
Finds all blank lines and returns them as a list of Occurence objects.
|
java.util.List<Occurence> |
findAllLinesMatching(java.lang.String regexp)
Returns a list of Occurence objects for each match.
|
java.util.List<Occurence> |
findAllOccurences(java.lang.String text)
Returns a list of Occurence objects for each match.
|
boolean |
findBlankLine()
Finds the next blank line starting at the current line.
|
boolean |
findLast(java.lang.String text)
Finds the last occurence of the specifeid text and moves the current position.
|
Occurence |
findLastOccurence(java.lang.String text)
Finds the last occurence of the specified text and returns it as an Occurence object.
|
boolean |
findNext(java.lang.String text)
Finds the next occurence of the specified text and moves the current position.
|
boolean |
findNextBlankLine()
Finds the next blank line starting at the line after the current line.
|
char |
getChar()
Returns the character at the current position.
|
java.lang.String |
getLine()
Returns the current line.
|
java.lang.String |
getLine(int line)
Returns the specified line.
|
Position |
getPosition()
Returns the current position.
|
TextBuffer |
getSelectedText()
Returns the selection as a TextBuffer.
|
java.lang.String |
getSelectedTextAsString()
Returns the selection as a String including '\n' character at end of line for multi line selections.
|
Selection |
getSelection()
Returns the current selection.
|
java.lang.String |
getSubString(int startColumn,
int endColumn)
Returns a substring of the current line.
|
java.lang.String |
getSubString(int line,
int startColumn,
int endColumn)
Returns a substring of the specified line.
|
TextBuffer |
getTextBuffer()
Returns the currently edited buffer.
|
java.lang.String |
getWord()
Returns the current word, and positions the current position at the beginning of the word.
|
boolean |
hasValidSelection()
Returns true if there is a valid selection set.
|
void |
insertBuffer(TextBuffer buffer)
Inserts another buffer into the buffer at the line below the current line.
|
void |
insertLine(java.lang.String line)
Inserts a line after the current line.
|
void |
insertLineAbove(java.lang.String line)
Inserts a line above the current line.
|
void |
insertTextBuffer(TextBuffer insertBuffer)
Inserts a TextBuffer at the current position and moves the current position
to after the last inserted character.
|
boolean |
isOnFirstColumn()
Returns true if the current position is on the first column in the line.
|
boolean |
isOnFirstLine()
Returns true if the current position is on the first line.
|
boolean |
isOnLastColumn()
Returns true if the current position is on the last column of the line.
|
boolean |
isOnLastLine()
Returns true if the current position is on the last line.
|
boolean |
lineMatches(java.lang.String regexp)
Returns true if the current line matches the specified regular expression.
|
void |
load(java.io.File file)
Loads a file into the buffer.
|
void |
load(java.lang.String path)
Loads a file into the buffer.
|
boolean |
moveDown(int size)
Moves the current position down.
|
boolean |
moveLeft(int size)
Move the current position left.
|
boolean |
moveRight(int size)
Move the current position right.
|
char |
moveToAndReturnNextChar()
Moves to the right and returns the next character.
|
java.lang.String |
moveToAndReturnNextWord()
Moves to the next word and returns it.
|
java.lang.String |
moveToAndReturnPrevWord()
Moves to the previous word and returns it.
|
void |
moveToBeginningOfLine()
Moves the current position to the beginning of the line.
|
void |
moveToBottomOfFile()
Moves the current position to the bottom of the file at 0,last-line.
|
void |
moveToEndOfFile()
Moves the current position to the end of the file at last-column,last-line.
|
void |
moveToEndOfLine()
Moves the current position to the end of the line.
|
void |
moveToMatching(char start,
char end)
Moves to the next "end" character at the 0 level.
|
boolean |
moveToNextChar()
Moves to the next character in the buffer being edited.
|
boolean |
moveToPrevChar()
Moves to the previous character in the buffer being edited.
|
void |
moveToTopOfFile()
Moves the current position to the top of the file at 0,0.
|
boolean |
moveUp(int size)
Moves the current positon up.
|
boolean |
moveWordsLeft(int words)
Moves the current position the specified number of words left and returns true if this was possible.
|
boolean |
moveWordsRight(int words)
Moves the current position the specified number of words right and returns true if this was possible.
|
boolean |
nextLineMatches(java.lang.String regexp)
Moves down to the next line and returns true if that line matches the
specified regular expression.
|
void |
replaceAllInCurrentLine(java.lang.String text,
java.lang.String replaceWithText)
Replaces all occurances of the specified text with the new text in the current line.
|
void |
replaceAllInFile(java.lang.String text,
java.lang.String replaceWithText)
Replaces all occurances of the specified text with the new text in the whole buffer.
|
void |
replaceCurrentLine(java.lang.String text)
Replaces the current line completely wiht the specified text.
|
void |
replaceFirstInCurrentLine(java.lang.String text,
java.lang.String replaceWithText)
Replaces the first occurence of the specified text with the new text in the current line.
|
void |
replaceSelectionWithText(java.lang.String replacementText)
Replaces the current selection with the specified text.
|
void |
replaceSelectionWithTextBuffer(TextBuffer replaceBuffer)
Replaces the current selection with the contents of the specified TextBuffer.
|
void |
save()
Saves the current buffer.
|
void |
saveAs(java.io.File file)
Saves the current buffer to a new file.
|
void |
saveAs(java.lang.String path)
Saves the current buffer to a new file.
|
void |
selectToMatching(char start,
char end)
Selects to the next "end" character at the 0 level.
|
void |
setAllowLoadSave(boolean allowLoadSave)
Change the allowLoadSave state.
|
void |
setLine(int lineNo,
java.lang.String line)
Replaces a line with a new text.
|
void |
setLine(java.lang.String line)
Replaces the current line with a new text.
|
void |
setPosition(int column,
int line)
Sets the current position.
|
void |
setPosition(Position position)
Sets the current position.
|
void |
setTextBuffer(TextBuffer textBuffer)
Replaces the buffer to edit.
|
void |
show()
Displays the loaded file.
|
void |
show(int start,
int end)
Displays the loaded file.
|
void |
startSelection()
Starts a new selection at the current position.
|
public static final java.lang.Character END_OF_FILE_CHAR
public void setAllowLoadSave(boolean allowLoadSave)
allowLoadSave
- true or false.public void setTextBuffer(TextBuffer textBuffer)
public TextBuffer getTextBuffer()
public void load(java.io.File file) throws java.io.IOException
file
- The file to load.java.io.IOException
public void load(java.lang.String path) throws java.io.IOException
path
- The path to the file to load.java.io.IOException
public void save() throws java.io.IOException
java.io.IOException
public void saveAs(java.io.File file) throws java.io.IOException
file
- The file to save to.java.io.IOException
public void saveAs(java.lang.String path) throws java.io.IOException
path
- The path to the file to save to.java.io.IOException
public java.lang.String getLine(int line)
line
- The line to get.public java.lang.String getLine()
public void setLine(int lineNo, java.lang.String line)
lineNo
- The line number to replace.line
- The new line text.public void setLine(java.lang.String line)
line
- The new text to set for the line.public java.lang.String getSubString(int line, int startColumn, int endColumn)
line
- The line to get the substring from.startColumn
- The start of the substring.endColumn
- The end of the substring (inclusive! Not like java substring!!).public java.lang.String getSubString(int startColumn, int endColumn)
startColumn
- The start of the substring.endColumn
- The end of the substring.public java.lang.String getWord()
public void setPosition(Position position)
position
- The position to set.public void setPosition(int column, int line)
column
- The column of the position.line
- The line of the position.public Position getPosition()
public boolean moveDown(int size)
Returns false on failure to do so.
size
- The number of lines to move the position down.public boolean moveUp(int size)
Returns false on failure to do so.
size
- The number of lines to move the position up.public boolean moveRight(int size)
Returns false on failure to do so.
size
- The number of columns to move the position right.public boolean moveLeft(int size)
Returns false on failure to do so.
size
- The number of columns to move the position left.public boolean moveToNextChar()
Returns false on failure to do so.
public boolean moveToPrevChar()
Returns false on failure to do so.
public char getChar()
public char moveToAndReturnNextChar()
public java.lang.String moveToAndReturnNextWord()
public java.lang.String moveToAndReturnPrevWord()
public boolean moveWordsRight(int words)
Please note that this method only moves right on the current line, it will not wrap to the next line! When it returns false, do "moveDown(1);" and "moveToBeginningOfLine();" and then continue if you want to cover several lines.
words
- The number of words to move.public boolean moveWordsLeft(int words)
Please note that this method only moves left on the current line, it will not wrap to the previous line! When it returns false, do "moveUp(1);" and "moveToBeginningOfLine();" and then continue if you want to cover several lines.
words
- The number of words to move.public void moveToEndOfLine()
public void moveToBeginningOfLine()
public void moveToTopOfFile()
public void moveToBottomOfFile()
public void moveToEndOfFile()
public boolean isOnFirstLine()
public boolean isOnLastLine()
public boolean isOnFirstColumn()
public boolean isOnLastColumn()
public boolean find(java.lang.String text)
text
- The text to find. This can be a regular expression.public boolean findNext(java.lang.String text)
text
- The text to find. This can be a regular expression.public boolean findLast(java.lang.String text)
text
- The text to find. This can be a regular expression.public java.util.List<Occurence> findAllOccurences(java.lang.String text)
This search will not move the current position, and will always start at the top of the file.
text
- The text to find all occurences of. This can be a reqular expression.public Occurence findLastOccurence(java.lang.String text)
This search will not move the current position, and will always start at the top of the file.
text
- The text to look for the last occurence of. This can be a reqular expression.public boolean findBlankLine()
public boolean findNextBlankLine()
public java.util.List<Occurence> findAllBlankLines()
This search will not move the current position, and will always start at the top of the file.
public boolean lineMatches(java.lang.String regexp)
regexp
- A regular expression to match with the line.public boolean nextLineMatches(java.lang.String regexp)
regexp
- The regular expression to match with the next line.public java.util.List<Occurence> findAllLinesMatching(java.lang.String regexp)
This search will not move the current position, and will always start at the top of the file.
regexp
- The regular expression to find all occurences of.public void startSelection()
public void endSelection()
public void clearSelection()
public boolean hasValidSelection()
public void moveToMatching(char start, char end)
start
- This character increases the level.end
- This is what to look for and also decreses the level.public void selectToMatching(char start, char end)
A few notes:
- You must have done startSelection() first!
- The selection will include the matching end character, but the current position will remain at the matching end character.
start
- This character increases the level.end
- This is what to look for and also decreses the level.public Selection getSelection()
public void replaceCurrentLine(java.lang.String text)
text
- The text to replace the current line with.public void replaceFirstInCurrentLine(java.lang.String text, java.lang.String replaceWithText)
text
- The text to replace. Can be a regular expression.replaceWithText
- The new text to replace the old with.public void replaceAllInCurrentLine(java.lang.String text, java.lang.String replaceWithText)
text
- The text to replace. Can be a regular expression.replaceWithText
- The new text to replace the old with.public void replaceAllInFile(java.lang.String text, java.lang.String replaceWithText)
text
- The text to replace. Can be a regular expression.replaceWithText
- The new text to replace the old with.public void replaceSelectionWithText(java.lang.String replacementText)
replacementText
- The text to replace with.public void replaceSelectionWithTextBuffer(TextBuffer replaceBuffer)
replaceBuffer
- The buffer whose content should replace current selection.public void insertTextBuffer(TextBuffer insertBuffer)
insertBuffer
- The buffer to insert.public void deleteSelection()
public TextBuffer getSelectedText()
public java.lang.String getSelectedTextAsString()
public void insertBuffer(TextBuffer buffer)
buffer
- The buffer to insert.public void appendBuffer(TextBuffer buffer)
public void insertLine(java.lang.String line)
public void insertLineAbove(java.lang.String line)
public void deleteCurrentLine()
public void deleteCurrentWord(char delimeter)
delimeter
- The delimeter that separates words.public void deleteCurrentWord()
public void show()
public void show(int start, int end)
Copyright © 2009-2012. All Rights Reserved.