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 intbackgroundCharBackground character for unfilled-in text.protected TActionenterActionThe action to perform when the user presses enter.protected booleanfixedIf true, only allow enough characters that will fit in the width.protected booleaninsertModeIf true, new characters are inserted at position.protected TMouseEventmouseRemember mouse state.protected intpositionCurrent editing position within text.protected intscreenPositionCurrent editing position screen column number.protected java.lang.StringtextField text.protected TActionupdateActionThe action to perform when the text is updated.protected intwindowStartBeginning 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 voidappendChar(int ch)Append char to the end of the field.protected voiddispatch(boolean enter)Dispatch to the action function.voiddraw()Draw the text field.voidend()Set the editing position to the last filled character.intgetBackgroundChar()Get field background character.java.lang.StringgetText()Get field text.voidhome()Position the cursor at the first column.protected voidinsertChar(int ch)Insert char somewhere in the middle of the field.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.protected booleanmouseOnField()Returns true if the mouse is currently on the field.protected voidnormalizeWindowStart()Normalize windowStart such that most of the field data if visible.voidonCommand(TCommandEvent command)Handle posted command events.voidonKeypress(TKeypressEvent keypress)Handle keystrokes.voidonMouseDown(TMouseEvent mouse)Handle mouse button presses.protected intscreenToTextPosition(int screenPosition)Determine string position from screen position.voidsetActiveColorKey(java.lang.String activeColorKey)Set the active color key.voidsetBackgroundChar(int backgroundChar)Set field background character.voidsetEnterAction(TAction action)Set the action to perform when the user presses enter.voidsetHeight(int height)Override TWidget's height: we can only set height at construction time.voidsetInactiveColorKey(java.lang.String inactiveColorKey)Set the inactive color key.voidsetPosition(int position)Set the editing position.voidsetText(java.lang.String text)Set field text.voidsetUpdateAction(TAction action)Set the action to perform when the field is updated.protected voidupdateCursor()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, 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, 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, setLocale, setMouseStyle, setParent, setupForTWindow, setVisible, setWidth, setWindow, setX, setY, splitHorizontal, splitVertical, switchWidget, toPrettyString, toPrettyString, toString, vLineXY, 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:
onMouseDownin classTWidget- Parameters:
mouse- mouse button event
-
onKeypress
public void onKeypress(TKeypressEvent keypress)
Handle keystrokes.- Overrides:
onKeypressin 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:
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
-
-