Package jexer
Class TEditorWidget
- java.lang.Object
-
- jexer.TWidget
-
- jexer.TEditorWidget
-
- All Implemented Interfaces:
java.lang.Comparable<TWidget>
,EditMenuUser
- Direct Known Subclasses:
InternalEditorWindow.InternalEditorWidget
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 void
cleanWhitespace()
Trim trailing whitespace from lines and trailing empty lines from the document.void
draw()
Draw the text box.int
getEditingColumnNumber()
Get the current editing column number.java.lang.String
getEditingRawLine(int row)
Get the current editing row plain text.int
getEditingRowNumber()
Get the current editing row number.int
getLineCount()
Get the number of lines in the underlying Document.int
getMaximumColumnNumber()
Get the maximum possible column number.int
getMaximumRowNumber()
Get the maximum possible row number.java.lang.String
getSelection()
Copy text within the selection bounds to a string.int
getSelectionEndColumn()
Get the selection ending column number.int
getSelectionEndRow()
Get the selection ending row number.int
getSelectionStartColumn()
Get the selection starting column number.int
getSelectionStartRow()
Get the selection starting row number.java.lang.String
getText()
Get the entire contents of the editor as one string.int
getVisibleColumnNumber()
Set the current visible column number.int
getVisibleRowNumber()
Get the current visible top row number.boolean
hasSelection()
Check if selection is available.boolean
isAutoWrap()
Get the wrapping behavior.boolean
isDirty()
Get the dirty value.boolean
isEditMenuClear()
Check if the clear menu item should be enabled.boolean
isEditMenuCopy()
Check if the copy menu item should be enabled.boolean
isEditMenuCut()
Check if the cut menu item should be enabled.boolean
isEditMenuPaste()
Check if the paste menu item should be enabled.boolean
isOverwrite()
Get the overwrite value.void
onCommand(TCommandEvent command)
Handle posted command events.void
onKeypress(TKeypressEvent keypress)
Handle keystrokes.void
onMouseDown(TMouseEvent mouse)
Handle mouse press events.void
onMouseMotion(TMouseEvent mouse)
Handle mouse motion events.void
onMouseUp(TMouseEvent mouse)
Handle mouse release events.void
onResize(TResizeEvent resize)
Method that subclasses can override to handle window/screen resize events.void
redo()
Redo an edit.void
replaceSelection(java.lang.String text)
Replace whatever is being selected with new text.void
saveToFilename(java.lang.String filename)
Save contents to file.void
setAutoWrap(boolean autoWrap)
Set the wrapping behavior.void
setEditingColumnNumber(int column)
Set the current editing column number.void
setEditingRowNumber(int row)
Set the current editing row number.void
setHighlighting(boolean enabled)
Set keyword highlighting.void
setMargin(int margin)
Set the right margin.void
setNotDirty()
Unset the dirty flag.void
setSelection(int startRow, int startColumn, int endRow, int endColumn)
Set the selection.void
setText(java.lang.String text)
Set the entire contents of the editor from one string.void
setUndoLevel(int undoLevel)
Set the undo level.void
setVisibleColumnNumber(int column)
Set the current visible column number.void
setVisibleRowNumber(int row)
Set the current visible row number.void
undo()
Undo an edit.void
unsetSelection()
Unset the selection.void
wrapText()
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, 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, getHeight, getLayoutManager, getParent, getScreen, getTheme, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, inputBox, inputBox, inputBox, isAbsoluteActive, isActive, isCursorVisible, isDrawable, isEchoKeystrokes, isEnabled, 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, setDimensions, setEchoKeystrokes, setEchoKeystrokes, setEnabled, setHeight, setLayoutManager, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, 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:
onMouseDown
in 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:
onMouseMotion
in classTWidget
- Parameters:
mouse
- mouse motion event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypress
in 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.IOException
Save 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:
isEditMenuCut
in 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:
isEditMenuCopy
in 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:
isEditMenuPaste
in 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:
isEditMenuClear
in 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
-
-