Class JtvFileEditor
public class JtvFileEditor
extends JtvEditor
A file-backed editor that loads and saves text files.
JtvFileEditor extends JtvEditor with file I/O, search-and-replace dialogs,
and cmSave/cmSaveAs command handling. It is normally hosted inside a
JtvEditWindow, which adds a window frame, scroll bars, and an indicator.
On construction the file named by aFileName is read into the edit buffer.
If the file does not exist the buffer starts empty (ready for a new file).
Before the editor closes, valid(int) prompts the user to save if the buffer
has been modified.
org.viktor44.jtvision.editors.JtvFileEditor
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvFileEditor(JtvRect bounds, JtvScrollBar hScrollBar, JtvScrollBar vScrollBar, JtvIndicator indicator, String fileName) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| private static final | log | org.slf4j.Logger |
| private static final | efCaseSensitive | int |
| private static final | efWholeWordsOnly | int |
| private static final | efPromptOnReplace | int |
| private static final | efReplaceAll | int |
| private static final | efDoReplace | int |
| private static | findText | String |
| private static | replaceText | String |
| private static | editorFlags | int |
| private | fileName | String |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public | loadFile() | boolean |
| public | save() | boolean |
| public | saveAs() | boolean |
| public | saveFile() | boolean |
| private static | normalizeFileName(String name) | String |
| protected | doFind() | void |
| protected | doReplace() | void |
| protected | doSearchAgain() | void |
| private | doSearchReplace() | void |
| private | search(String findStr, int opts) | boolean |
| private | isWholeWord(String text, int start, int end) | boolean |
| private | createFindDialog() | org.viktor44.jtvision.dialogs.JtvDialog |
| private | createReplaceDialog() | org.viktor44.jtvision.dialogs.JtvDialog |
| public | handleEvent(JtvEvent event) | void |
| protected | updateCommands() | void |
| public | valid(int command) | boolean |
| public | getFileName() | String |
Constructors
JtvFileEditor(JtvRect bounds, JtvScrollBar hScrollBar, JtvScrollBar vScrollBar, JtvIndicator indicator, String fileName)
Constructs a file editor. If aFileName is non-empty, the named file is
loaded into the buffer immediately via loadFile().
Parameters
bounds- the bounding rectangle for this editor viewhScrollBar- optional horizontal scroll bar, ornullvScrollBar- optional vertical scroll bar, ornullindicator- optional position indicator, ornullfileName- path of the file to edit, or empty/null for a new untitled file
Fields
org.slf4j.Logger log
No description provided
int efCaseSensitive
Search flag: match is case-sensitive.
int efWholeWordsOnly
Search flag: match only whole words.
int efPromptOnReplace
Search flag: prompt before replacing each occurrence.
int efReplaceAll
Search flag: replace all occurrences without stopping.
int efDoReplace
Internal flag: a replace (not just find) operation is in progress.
String findText
Most recently used search string; shared across all TFileEditor instances.
String replaceText
Most recently used replacement string; shared across all instances.
int editorFlags
Current combination of ef* flags; shared across all instances.
String fileName
The path of the file currently being edited. Empty if editing an untitled (unsaved) file.
Methods
loadFile()
Reads the file named by fileName into the edit buffer.
If the file does not exist, the buffer is cleared (ready to create a new file)
and true is returned. Displays an error message and returns false
on read failure.
Returns
true if the file was loaded (or does not yet exist); false on error
save()
Saves the buffer. If the file has no name yet, delegates to saveAs(); otherwise delegates to saveFile().
Returns
true if the save succeeded; false if cancelled or on error
saveAs()
Presents a file-save dialog to let the user choose a file name, then saves the buffer.
Updates fileName and broadcasts cmUpdateTitle on success.
Returns
true if the file was saved; false if the dialog was cancelled or on error
saveFile()
Writes the buffer to the file named by fileName using UTF-8 encoding.
Clears the JtvEditor.modified flag and redraws on success.
Displays an error message and returns false on write failure.
Returns
true if the file was written successfully; false on error
normalizeFileName(String name)
No method description provided
Parameters
name
doFind()
Overrides:
doFind() in org.viktor44.jtvision.editors.JtvEditor
Opens the Find dialog to let the user enter a search string and options, then performs the search.
doReplace()
Overrides:
doReplace() in org.viktor44.jtvision.editors.JtvEditor
Opens the Replace dialog to let the user enter search and replacement strings and options, then performs the search-and-replace.
doSearchAgain()
Overrides:
doSearchAgain() in org.viktor44.jtvision.editors.JtvEditor
Repeats the most recent search/replace operation using the saved findText,
replaceText, and editorFlags.
doSearchReplace()
No method description provided
search(String findStr, int opts)
No method description provided
Parameters
findStropts
isWholeWord(String text, int start, int end)
No method description provided
Parameters
textstartend
createFindDialog()
No method description provided
createReplaceDialog()
No method description provided
handleEvent(JtvEvent event)
Overrides:
handleEvent(JtvEvent event) in org.viktor44.jtvision.editors.JtvEditor
Handles events by first delegating to the inherited JtvEditor handler, then
intercepts cmSave and cmSaveAs commands to save the file.
Parameters
event- the event to handle
updateCommands()
Overrides:
updateCommands() in org.viktor44.jtvision.editors.JtvEditor
Extends the base command update to enable cmSave and cmSaveAs when
the editor is active, and disable them when it is not focused.
valid(int command)
Overrides:
valid(int command) in org.viktor44.jtvision.editors.JtvEditor
Validates the editor for the given command. For cmValid, returns
JtvEditor.isValid. For any other command (typically cmClose), if the
buffer has been modified, prompts the user to save, discard, or cancel.
Parameters
command- the validation command
Returns
true if it is safe to proceed; false if the user cancelled
getFileName()
The path of the file currently being edited. Empty if editing an untitled (unsaved) file.