Package jexer
Class TEditorWidget
- java.lang.Object
-
- jexer.TWidget
-
- jexer.TEditorWidget
-
- All Implemented Interfaces:
java.lang.Comparable<TWidget>,EditMenuUser
public class TEditorWidget extends TWidget implements EditMenuUser
TEditorWidget displays an editable text document. It is unaware of scrolling behavior, but can respond to mouse and keyboard events.
-
-
Constructor Summary
Constructors Constructor Description TEditorWidget(TWidget parent, java.lang.String text, int x, int y, int width, int height)Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanWhitespace()Trim trailing whitespace from lines and trailing empty lines from the document.voiddraw()Draw the text box.intgetEditingColumnNumber()Get the current editing column number.java.lang.StringgetEditingRawLine(int row)Get the current editing row plain text.intgetEditingRowNumber()Get the current editing row number.intgetLineCount()Get the number of lines in the underlying Document.intgetMaximumColumnNumber()Get the maximum possible column number.intgetMaximumRowNumber()Get the maximum possible row number.java.lang.StringgetSelection()Copy text within the selection bounds to a string.intgetSelectionEndColumn()Get the selection ending column number.intgetSelectionEndRow()Get the selection ending row number.intgetSelectionStartColumn()Get the selection starting column number.intgetSelectionStartRow()Get the selection starting row number.java.lang.StringgetText()Get the entire contents of the editor as one string.intgetVisibleColumnNumber()Set the current visible column number.intgetVisibleRowNumber()Get the current visible top row number.booleanhasSelection()Check if selection is available.booleanisAutoWrap()Get the wrapping behavior.booleanisDirty()Get the dirty value.booleanisEditMenuClear()Check if the clear menu item should be enabled.booleanisEditMenuCopy()Check if the copy menu item should be enabled.booleanisEditMenuCut()Check if the cut menu item should be enabled.booleanisEditMenuPaste()Check if the paste menu item should be enabled.booleanisOverwrite()Get the overwrite value.voidonCommand(TCommandEvent command)Handle posted command events.voidonKeypress(TKeypressEvent keypress)Handle keystrokes.voidonMouseDown(TMouseEvent mouse)Handle mouse press events.voidonMouseMotion(TMouseEvent mouse)Handle mouse motion events.voidonMouseUp(TMouseEvent mouse)Handle mouse release events.voidonResize(TResizeEvent resize)Method that subclasses can override to handle window/screen resize events.voidredo()Redo an edit.voidreplaceSelection(java.lang.String text)Replace whatever is being selected with new text.voidsaveToFilename(java.lang.String filename)Save contents to file.voidsetAutoWrap(boolean autoWrap)Set the wrapping behavior.voidsetEditingColumnNumber(int column)Set the current editing column number.voidsetEditingRowNumber(int row)Set the current editing row number.voidsetHighlighting(boolean enabled)Set keyword highlighting.voidsetMargin(int margin)Set the right margin.voidsetNotDirty()Unset the dirty flag.voidsetSelection(int startRow, int startColumn, int endRow, int endColumn)Set the selection.voidsetText(java.lang.String text)Set the entire contents of the editor from one string.voidsetUndoLevel(int undoLevel)Set the undo level.voidsetVisibleColumnNumber(int column)Set the current visible column number.voidsetVisibleRowNumber(int row)Set the current visible row number.voidundo()Undo an edit.voidunsetSelection()Unset the selection.voidwrapText()Reflow the text to fit inside the margin.-
Methods inherited from class jexer.TWidget
activate, activate, activate, activateAll, addButton, addCalendar, addCheckBox, addCheckBox, addComboBox, addDirectoryList, addDirectoryList, addDirectoryList, addDirectoryList, addEditor, addField, addField, addField, addField, addImage, addImage, addImage, addImage, addLabel, addLabel, addLabel, addLabel, addLabel, addLabel, addList, addList, addList, addList, addPanel, addPasswordField, addPasswordField, addPasswordField, addProgressBar, addRadioGroup, addRadioGroup, addSpinner, addSplitPane, addTable, addTable, addText, addText, addTreeViewWidget, addTreeViewWidget, close, compareTo, doRepaint, drawBox, drawBox, drawBoxShadow, drawChildren, fileOpenBox, fileOpenBox, fileOpenBox, fileOpenBox, fileSaveBox, getAbsoluteX, getAbsoluteY, getActiveChild, getApplication, getAttrXY, getChildren, getClipboard, getCursorAbsoluteX, getCursorAbsoluteY, getCursorX, getCursorY, getCustomMousePointer, getHeight, getLayoutManager, getLocale, getMouseStyle, getParent, getScreen, getTheme, getWidgetUnderMouse, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, hLineXY, inputBox, inputBox, inputBox, isAbsoluteActive, isActive, isCursorVisible, isDrawable, isEchoKeystrokes, isEnabled, isPixelMouse, isVisible, messageBox, messageBox, mouseWouldHit, onIdle, onMenu, onMouseDoubleClick, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putStringXY, putStringXY, remove, remove, remove, remove, removeAll, resetTabOrder, setActive, setCursorVisible, setCursorX, setCursorY, setCustomMousePointer, setDimensions, setEchoKeystrokes, setEchoKeystrokes, setEnabled, setHeight, setLayoutManager, setLocale, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY, vLineXY
-
-
-
-
Field Detail
-
document
protected Document document
The document being edited.
-
-
Constructor Detail
-
TEditorWidget
public TEditorWidget(TWidget parent, java.lang.String text, int x, int y, int width, int height)
Public constructor.- Parameters:
parent- parent widgettext- text on the screenx- column relative to parenty- row relative to parentwidth- width of text areaheight- height of text area
-
-
Method Detail
-
onMouseDown
public void onMouseDown(TMouseEvent mouse)
Handle mouse press events.- Overrides:
onMouseDownin classTWidget- Parameters:
mouse- mouse button press event
-
onMouseUp
public void onMouseUp(TMouseEvent mouse)
Handle mouse release events.
-
onMouseMotion
public void onMouseMotion(TMouseEvent mouse)
Handle mouse motion events.- Overrides:
onMouseMotionin classTWidget- Parameters:
mouse- mouse motion event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypressin classTWidget- Parameters:
keypress- keystroke event
-
onResize
public void onResize(TResizeEvent resize)
Method that subclasses can override to handle window/screen resize events.
-
onCommand
public void onCommand(TCommandEvent command)
Handle posted command events.
-
isAutoWrap
public boolean isAutoWrap()
Get the wrapping behavior.- Returns:
- true if the editor automatically wraps text to fit in the margin
-
setAutoWrap
public void setAutoWrap(boolean autoWrap)
Set the wrapping behavior.- Parameters:
autoWrap- if true, automatically wrap text to fit in the margin
-
setUndoLevel
public void setUndoLevel(int undoLevel)
Set the undo level.- Parameters:
undoLevel- the maximum number of undo operations
-
setMargin
public void setMargin(int margin)
Set the right margin.- Parameters:
margin- column number, or 0 to disable
-
getLineCount
public int getLineCount()
Get the number of lines in the underlying Document.- Returns:
- the number of lines
-
getVisibleRowNumber
public int getVisibleRowNumber()
Get the current visible top row number. 1-based.- Returns:
- the visible top row number. Row 1 is the first row.
-
setVisibleRowNumber
public void setVisibleRowNumber(int row)
Set the current visible row number. 1-based.- Parameters:
row- the new visible row number. Row 1 is the first row.
-
getEditingRowNumber
public int getEditingRowNumber()
Get the current editing row number. 1-based.- Returns:
- the editing row number. Row 1 is the first row.
-
setEditingRowNumber
public void setEditingRowNumber(int row)
Set the current editing row number. 1-based.- Parameters:
row- the new editing row number. Row 1 is the first row.
-
getVisibleColumnNumber
public int getVisibleColumnNumber()
Set the current visible column number. 1-based.- Returns:
- the visible column number. Column 1 is the first column.
-
setVisibleColumnNumber
public void setVisibleColumnNumber(int column)
Set the current visible column number. 1-based.- Parameters:
column- the new visible column number. Column 1 is the first column.
-
getEditingColumnNumber
public int getEditingColumnNumber()
Get the current editing column number. 1-based.- Returns:
- the editing column number. Column 1 is the first column.
-
setEditingColumnNumber
public void setEditingColumnNumber(int column)
Set the current editing column number. 1-based.- Parameters:
column- the new editing column number. Column 1 is the first column.
-
getMaximumRowNumber
public int getMaximumRowNumber()
Get the maximum possible row number. 1-based.- Returns:
- the maximum row number. Row 1 is the first row.
-
getMaximumColumnNumber
public int getMaximumColumnNumber()
Get the maximum possible column number. 1-based.- Returns:
- the maximum column number. Column 1 is the first column.
-
getEditingRawLine
public java.lang.String getEditingRawLine(int row)
Get the current editing row plain text. 1-based.- Parameters:
row- the editing row number. Row 1 is the first row.- Returns:
- the plain text of the row
-
isDirty
public boolean isDirty()
Get the dirty value.- Returns:
- true if the buffer is dirty
-
setNotDirty
public void setNotDirty()
Unset the dirty flag.
-
isOverwrite
public boolean isOverwrite()
Get the overwrite value.- Returns:
- true if new text will overwrite old text
-
saveToFilename
public void saveToFilename(java.lang.String filename) throws java.io.IOExceptionSave contents to file.- Parameters:
filename- file to save to- Throws:
java.io.IOException- if a java.io operation throws
-
wrapText
public void wrapText()
Reflow the text to fit inside the margin.
-
setSelection
public void setSelection(int startRow, int startColumn, int endRow, int endColumn)Set the selection.- Parameters:
startRow- the starting row number. 0-based: row 0 is the first row.startColumn- the starting column number. 0-based: column 0 is the first column.endRow- the ending row number. 0-based: row 0 is the first row.endColumn- the ending column number. 0-based: column 0 is the first column.
-
getSelection
public java.lang.String getSelection()
Copy text within the selection bounds to a string.- Returns:
- the selection as a string, or null if there is no selection
-
getSelectionStartRow
public int getSelectionStartRow()
Get the selection starting row number.- Returns:
- the starting row number, or -1 if there is no selection. 0-based: row 0 is the first row.
-
getSelectionStartColumn
public int getSelectionStartColumn()
Get the selection starting column number.- Returns:
- the starting column number, or -1 if there is no selection. 0-based: column 0 is the first column.
-
getSelectionEndRow
public int getSelectionEndRow()
Get the selection ending row number.- Returns:
- the ending row number, or -1 if there is no selection. 0-based: row 0 is the first row.
-
getSelectionEndColumn
public int getSelectionEndColumn()
Get the selection ending column number.- Returns:
- the ending column number, or -1 if there is no selection. 0-based: column 0 is the first column.
-
unsetSelection
public void unsetSelection()
Unset the selection.
-
replaceSelection
public void replaceSelection(java.lang.String text)
Replace whatever is being selected with new text. If not in selection, nothing is replaced.- Parameters:
text- the new replacement text
-
hasSelection
public boolean hasSelection()
Check if selection is available.- Returns:
- true if a selection has been made
-
getText
public java.lang.String getText()
Get the entire contents of the editor as one string.- Returns:
- the editor contents
-
setText
public void setText(java.lang.String text)
Set the entire contents of the editor from one string.- Parameters:
text- the new contents
-
isEditMenuCut
public boolean isEditMenuCut()
Check if the cut menu item should be enabled.- Specified by:
isEditMenuCutin interfaceEditMenuUser- Returns:
- true if the cut menu item should be enabled
-
isEditMenuCopy
public boolean isEditMenuCopy()
Check if the copy menu item should be enabled.- Specified by:
isEditMenuCopyin interfaceEditMenuUser- Returns:
- true if the copy menu item should be enabled
-
isEditMenuPaste
public boolean isEditMenuPaste()
Check if the paste menu item should be enabled.- Specified by:
isEditMenuPastein interfaceEditMenuUser- Returns:
- true if the paste menu item should be enabled
-
isEditMenuClear
public boolean isEditMenuClear()
Check if the clear menu item should be enabled.- Specified by:
isEditMenuClearin interfaceEditMenuUser- Returns:
- true if the clear menu item should be enabled
-
undo
public void undo()
Undo an edit.
-
redo
public void redo()
Redo an edit.
-
cleanWhitespace
public void cleanWhitespace()
Trim trailing whitespace from lines and trailing empty lines from the document.
-
setHighlighting
public void setHighlighting(boolean enabled)
Set keyword highlighting.- Parameters:
enabled- if true, enable keyword highlighting
-
-