Class JtvInputLine
public class JtvInputLine
extends JtvView
A single-line text editor control.
JtvInputLine provides a basic editable string field. It handles cursor movement,
text insertion and deletion, text selection (including Shift+arrow), overwrite
mode (Ins), and scrolling when the text is longer than the visible area.
Left and right arrow indicators (\u25c4 / \u25ba) appear at the edges
when the text can be scrolled.
The maximum number of characters the field may hold is set at construction time
(aMaxLen) and must not be changed afterwards. Double-clicking selects
all text. When the field receives or loses selection, all text is selected or deselected.
History lists can be attached via a JtvHistory view placed beside the input line.
Colour palette
The four-entry palette cpInputLine maps to:
- Unfocused field text.
- Focused field text.
- Selected text highlight.
- Scroll arrow colour.
org.viktor44.jtvision.dialogs.JtvInputLine
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvInputLine(JtvRect bounds, int maxLen) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| protected | data | String |
| protected | maxLen | int |
| protected | curPos | int |
| protected | firstPos | int |
| protected | selStart | int |
| protected | selEnd | int |
| protected | anchor | int |
| private static final | leftArrow | char |
| private static final | rightArrow | char |
| private static final | cpInputLine | org.viktor44.jtvision.core.JtvPalette |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public | draw() | void |
| public | getPalette() | org.viktor44.jtvision.core.JtvPalette |
| public | getDataTo(Object rec) | void |
| public | setDataFrom(Object rec) | void |
| public | canScroll(int delta) | boolean |
| public | handleEvent(JtvEvent event) | void |
| private | clipCopy() | void |
| private | clipCut() | void |
| private | clipPaste() | void |
| private | insertPastedText(String text) | void |
| private | deleteSelect() | void |
| private | adjustSelectBlock() | void |
| public | selectAll(boolean enable) | void |
| private | mouseDelta(JtvEvent event) | int |
| private | mousePos(JtvEvent event) | int |
| public | setState(int aState, boolean enable) | void |
| public | valid(int cmd) | boolean |
| public | getData() | String |
| public | setData(String data) | void |
| public | getMaxLen() | int |
| public | setMaxLen(int maxLen) | void |
Constructors
JtvInputLine(JtvRect bounds, int maxLen)
Creates an input line with the given bounds and maximum text length.
Parameters
bounds- the bounding rectangle (should be at least 3 characters wide to accommodate scroll arrows and at least one character of text)maxLen- the maximum number of characters the field may hold
Fields
String data
The current text content of the input field.
int maxLen
Maximum number of characters the field may hold (set at construction; do not change).
int curPos
Current cursor position (character index within data).
int firstPos
Index of the first visible character (non-zero when the text is scrolled).
int selStart
Start of the current text selection (inclusive, character index).
int selEnd
End of the current text selection (exclusive, character index).
int anchor
The anchor point used when extending a selection with Shift+arrow keys.
char leftArrow
Arrow character shown on the left when the text can be scrolled left.
char rightArrow
Arrow character shown on the right when the text can be scrolled right.
org.viktor44.jtvision.core.JtvPalette cpInputLine
Four-entry colour palette:
0x13— unfocused field text.0x13— focused field text.0x14— selected text highlight.0x15— scroll arrow colour.
Methods
draw()
Overrides:
draw() in org.viktor44.jtvision.views.JtvView
Draws the input field, rendering the visible portion of data, selection highlight, and scroll-arrow indicators.
getPalette()
Overrides:
getPalette() in org.viktor44.jtvision.views.JtvView
Returns the default color palette cpInputLine.
Returns
the input line's color palette
getDataTo(Object rec)
Reads the field's current text. Callers should read the data field directly in this implementation.
Parameters
rec- the destination record (unused)
setDataFrom(Object rec)
Overrides:
setDataFrom(Object rec) in org.viktor44.jtvision.views.JtvView
Sets the field's text from a String record, truncating to maxLen
if necessary, then selects all text.
Parameters
rec- aStringwith the new text value
canScroll(int delta)
Returns whether the text can be scrolled in the given direction.
Parameters
delta- negative to check left-scroll, positive to check right-scroll
Returns
true if scrolling in the given direction is possible
handleEvent(JtvEvent event)
Overrides:
handleEvent(JtvEvent event) in org.viktor44.jtvision.views.JtvView
Handles mouse and keyboard events for the input field.
Supported operations:
- Mouse clicks — move cursor; double-click selects all text.
- Shift+arrow keys — extend text selection.
- Arrow keys, Home, End — move cursor.
- Backspace, Delete — delete character or selection.
- Ins — toggle insert/overwrite mode.
- Printable characters — insert or overwrite text.
- Ctrl+Y — clear the entire field.
Parameters
event- the incoming event
clipCopy()
Copies the selected text to the clipboard.
clipCut()
Copies the selected text to the clipboard then deletes it.
clipPaste()
Inserts the clipboard text at the cursor position, replacing any current selection.
insertPastedText(String text)
Inserts pasted text into the input line, filtering out control
characters (below ASCII 32). Used by both clipPaste() and the
bracketed-paste (evPaste) handler.
Parameters
text- the raw pasted text
deleteSelect()
Deletes the currently selected text range and moves the cursor to selStart.
adjustSelectBlock()
Updates selStart and selEnd based on curPos and anchor.
selectAll(boolean enable)
Selects all text (positions cursor at end, sets selection to the whole string) or clears the selection (positions cursor and selection start at 0).
Parameters
enable-trueto select all,falseto deselect all
mouseDelta(JtvEvent event)
Returns the scroll direction implied by the current mouse position:
-1 if the mouse is at or left of the left edge, 1 if at or right
of the right edge, 0 otherwise.
Parameters
event
mousePos(JtvEvent event)
Converts a mouse event position into a character index within data.
Parameters
event
setState(int aState, boolean enable)
Overrides:
setState(int aState, boolean enable) in org.viktor44.jtvision.views.JtvView
Extends the inherited setState to select or deselect all text when
the field is selected or activated.
Parameters
aState- the state flag(s) being changedenable-trueto set,falseto clear
valid(int cmd)
Always returns true — input lines are always valid regardless of command.
Parameters
cmd- the command to validate
Returns
true
getData()
The current text content of the input field.
setData(String data)
The current text content of the input field.
Parameters
data
getMaxLen()
Maximum number of characters the field may hold (set at construction; do not change).
setMaxLen(int maxLen)
Maximum number of characters the field may hold (set at construction; do not change).
Parameters
maxLen