Package jexer
Class TField
- java.lang.Object
-
- jexer.TWidget
-
- jexer.TField
-
- All Implemented Interfaces:
java.lang.Comparable<TWidget>
,EditMenuUser
- Direct Known Subclasses:
TPasswordField
public class TField extends TWidget implements EditMenuUser
TField implements an editable text field.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
backgroundChar
Background character for unfilled-in text.protected TAction
enterAction
The action to perform when the user presses enter.protected boolean
fixed
If true, only allow enough characters that will fit in the width.protected boolean
insertMode
If true, new characters are inserted at position.protected TMouseEvent
mouse
Remember mouse state.protected int
position
Current editing position within text.protected int
screenPosition
Current editing position screen column number.protected java.lang.String
text
Field text.protected TAction
updateAction
The action to perform when the text is updated.protected int
windowStart
Beginning of visible portion.
-
Constructor Summary
Constructors Constructor Description TField(TWidget parent, int x, int y, int width, boolean fixed)
Public constructor.TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text)
Public constructor.TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text, TAction enterAction)
Public constructor.TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text, TAction enterAction, TAction updateAction)
Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
appendChar(int ch)
Append char to the end of the field.protected void
dispatch(boolean enter)
Dispatch to the action function.void
draw()
Draw the text field.void
end()
Set the editing position to the last filled character.int
getBackgroundChar()
Get field background character.java.lang.String
getText()
Get field text.void
home()
Position the cursor at the first column.protected void
insertChar(int ch)
Insert char somewhere in the middle of the field.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.protected boolean
mouseOnField()
Returns true if the mouse is currently on the field.protected void
normalizeWindowStart()
Normalize windowStart such that most of the field data if visible.void
onCommand(TCommandEvent command)
Handle posted command events.void
onKeypress(TKeypressEvent keypress)
Handle keystrokes.void
onMouseDown(TMouseEvent mouse)
Handle mouse button presses.protected int
screenToTextPosition(int screenPosition)
Determine string position from screen position.void
setActiveColorKey(java.lang.String activeColorKey)
Set the active color key.void
setBackgroundChar(int backgroundChar)
Set field background character.void
setEnterAction(TAction action)
Set the action to perform when the user presses enter.void
setHeight(int height)
Override TWidget's height: we can only set height at construction time.void
setInactiveColorKey(java.lang.String inactiveColorKey)
Set the inactive color key.void
setPosition(int position)
Set the editing position.void
setText(java.lang.String text)
Set field text.void
setUpdateAction(TAction action)
Set the action to perform when the field is updated.protected void
updateCursor()
Update the visible cursor position to match the location of position and windowStart.-
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, getCustomMousePointer, getHeight, getLayoutManager, getMouseStyle, getParent, getScreen, getTheme, getWidgetUnderMouse, getWidth, getWindow, getX, getY, handleEvent, hasChild, hLineXY, inputBox, inputBox, inputBox, isAbsoluteActive, isActive, isCursorVisible, isDrawable, isEchoKeystrokes, isEnabled, isPixelMouse, isVisible, messageBox, messageBox, mouseWouldHit, onIdle, onMenu, onMouseDoubleClick, onMouseMotion, onMouseUp, onResize, putAll, putAttrXY, putAttrXY, putCharXY, putCharXY, putCharXY, putStringXY, putStringXY, remove, remove, remove, remove, removeAll, resetTabOrder, setActive, setCursorVisible, setCursorX, setCursorY, setCustomMousePointer, setDimensions, setEchoKeystrokes, setEchoKeystrokes, setEnabled, setLayoutManager, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY
-
-
-
-
Field Detail
-
backgroundChar
protected int backgroundChar
Background character for unfilled-in text.
-
text
protected java.lang.String text
Field text.
-
fixed
protected boolean fixed
If true, only allow enough characters that will fit in the width. If false, allow the field to scroll to the right.
-
position
protected int position
Current editing position within text.
-
screenPosition
protected int screenPosition
Current editing position screen column number.
-
windowStart
protected int windowStart
Beginning of visible portion.
-
insertMode
protected boolean insertMode
If true, new characters are inserted at position.
-
mouse
protected TMouseEvent mouse
Remember mouse state.
-
enterAction
protected TAction enterAction
The action to perform when the user presses enter.
-
updateAction
protected TAction updateAction
The action to perform when the text is updated.
-
-
Constructor Detail
-
TField
public TField(TWidget parent, int x, int y, int width, boolean fixed)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- visible text widthfixed
- if true, the text cannot exceed the display width
-
TField
public TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- visible text widthfixed
- if true, the text cannot exceed the display widthtext
- initial text, default is empty string
-
TField
public TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text, TAction enterAction)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- visible text widthfixed
- if true, the text cannot exceed the display widthtext
- initial text, default is empty stringenterAction
- function to call when enter key is pressed
-
TField
public TField(TWidget parent, int x, int y, int width, boolean fixed, java.lang.String text, TAction enterAction, TAction updateAction)
Public constructor.- Parameters:
parent
- parent widgetx
- column relative to parenty
- row relative to parentwidth
- visible text widthfixed
- if true, the text cannot exceed the display widthtext
- initial text, default is empty stringenterAction
- function to call when enter key is pressedupdateAction
- function to call when the text is updated
-
-
Method Detail
-
mouseOnField
protected boolean mouseOnField()
Returns true if the mouse is currently on the field.- Returns:
- if true the mouse is currently on the field
-
onMouseDown
public void onMouseDown(TMouseEvent mouse)
Handle mouse button presses.- Overrides:
onMouseDown
in classTWidget
- Parameters:
mouse
- mouse button event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypress
in classTWidget
- Parameters:
keypress
- keystroke event
-
onCommand
public void onCommand(TCommandEvent command)
Handle posted command events.
-
setHeight
public void setHeight(int height)
Override TWidget's height: we can only set height at construction time.
-
getBackgroundChar
public final int getBackgroundChar()
Get field background character.- Returns:
- background character
-
setBackgroundChar
public void setBackgroundChar(int backgroundChar)
Set field background character.- Parameters:
backgroundChar
- the background character
-
getText
public final java.lang.String getText()
Get field text.- Returns:
- field text
-
setText
public void setText(java.lang.String text)
Set field text.- Parameters:
text
- the new field text
-
dispatch
protected void dispatch(boolean enter)
Dispatch to the action function.- Parameters:
enter
- if true, the user pressed Enter, else this was an update to the text.
-
screenToTextPosition
protected int screenToTextPosition(int screenPosition)
Determine string position from screen position.- Parameters:
screenPosition
- the position on screen- Returns:
- the equivalent position in text
-
updateCursor
protected void updateCursor()
Update the visible cursor position to match the location of position and windowStart.
-
normalizeWindowStart
protected void normalizeWindowStart()
Normalize windowStart such that most of the field data if visible.
-
appendChar
protected void appendChar(int ch)
Append char to the end of the field.- Parameters:
ch
- char to append
-
insertChar
protected void insertChar(int ch)
Insert char somewhere in the middle of the field.- Parameters:
ch
- char to append
-
home
public void home()
Position the cursor at the first column. The field may adjust the window start to show as much of the field as possible.
-
end
public void end()
Set the editing position to the last filled character. The field may adjust the window start to show as much of the field as possible.
-
setPosition
public void setPosition(int position)
Set the editing position. The field may adjust the window start to show as much of the field as possible.- Parameters:
position
- the new position- Throws:
java.lang.IndexOutOfBoundsException
- if position is outside the range of the available text
-
setActiveColorKey
public void setActiveColorKey(java.lang.String activeColorKey)
Set the active color key.- Parameters:
activeColorKey
- ColorTheme key color to use when this field is active
-
setInactiveColorKey
public void setInactiveColorKey(java.lang.String inactiveColorKey)
Set the inactive color key.- Parameters:
inactiveColorKey
- ColorTheme key color to use when this field is inactive
-
setEnterAction
public void setEnterAction(TAction action)
Set the action to perform when the user presses enter.- Parameters:
action
- the action to perform when the user presses enter
-
setUpdateAction
public void setUpdateAction(TAction action)
Set the action to perform when the field is updated.- Parameters:
action
- the action to perform when the field is updated
-
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
-
-