Package org.luwrain.controls
Class ListArea<E>
java.lang.Object
org.luwrain.controls.ListArea<E>
- Type Parameters:
E- the type of items in the list
- All Implemented Interfaces:
ClipboardTranslator.Provider,RegionTextQueryTranslator.Provider,Area,HotPoint,Lines
- Direct Known Subclasses:
CommanderArea,EditableListArea,ListPopup2,ListPopupBase,MarkableListArea,TreeListArea
public class ListArea<E>
extends Object
implements Area, ClipboardTranslator.Provider, RegionTextQueryTranslator.Provider
A generic list area that displays a model of items and allows navigation,
selection, clipboard operations, and custom appearance. The list area
integrates with the LUWRAIN area management, handling input events,
system events, and area queries.
The class is parameterized by the type of item <E>. It uses a
ListArea.Model to provide the data, an ListArea.Appearance to control how
items are displayed and announced, a ListArea.Transition to define movement
behaviour, and a ListArea.ClipboardSaver for clipboard operations.
The list can optionally have an empty line at the top and/or bottom, and can announce the selected item when the area is introduced.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceControls the visual and audible presentation of items.static interfaceHandler for click (activation) events on list items.static interfaceResponsible for saving a range of items to the clipboard.static enumFlags that control the behaviour of the list area.protected static classInternal class used to pass information about the listening position between the begin-listening query and the listening-finished event.static interfaceProvides the data for the list.static classParameters for constructing aListArea.static interfaceDefines how the hot point moves in response to navigation commands (arrow keys, page up/down, home/end). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected static final Set<ListArea.Appearance.Flags> protected final ClipboardTranslatorprotected final ControlContextprotected intprotected intprotected final ListArea.Appearance<E> protected ListArea.ClickHandler<E> protected final ListArea.ClipboardSaver<E> protected final Set<ListArea.Flags> protected final ListArea.Model<E> protected final ListArea.Transitionprotected static final Set<ListArea.Appearance.Flags> protected final RegionPointprotected final RegionTextQueryTranslator -
Constructor Summary
ConstructorsConstructorDescriptionListArea(ListArea.Params<E> params) Constructs a new list area with the given parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidannounceChar(String line, int pos, int rightBound) Announces a character at the given position, or a line bound hint if at the end.voidAnnounces the currently selected item using the appearance.Action[]intgetExistingItemIndexOnLine(int lineIndex) Given a line index (screen coordinate), returns the corresponding item index in the model, or -1 if the line does not contain a valid item.intintintgetItemIndexOnLine(int index) Converts a screen line index to a model index, without checking whether the resulting index is within the model bounds.getItemOnLine(int lineIndex) Returns the item displayed on the given screen line.getLine(int index) intintgetLineIndexByItemIndex(int index) Converts a model item index to the corresponding screen line index.Returns the appearance controller used by this list.intReturns the total number of items in the model.Returns the data model used by this list.protected StringgetObservableSubstr(E item) Returns the observable substring of an item's screen representation, i.e., the part between its left and right bounds.booleanisEmpty()Checks whether the list model contains any items.protected booleanChecks whether the list has no content and, if so, sets an appropriate hint response.protected StringReturns the string to display when the list has no content.protected booleanonAltEnd(InputEvent event) Handles the alternative end command (jump to the end of the line).protected booleanonAltHome(InputEvent event) Handles the alternative home command (jump to the beginning of the line).protected booleanonAltLeft(InputEvent event) Handles the alternative left command (move by word backward).protected booleanonAltRight(InputEvent event) Handles the alternative right command (move by word forward).protected booleanAnnounces the list area.protected booleanAnnounces the current line (the item under the hot point).booleanonAreaQuery(AreaQuery query) protected booleanHandles aBeginListeningQueryto start continuous reading from the current hot point position.protected booleanonChar(InputEvent event) Handles character input for incremental search.booleanonClipboardCopy(int fromX, int fromY, int toX, int toY, boolean withDeleting) booleanbooleanonDeleteRegion(int fromX, int fromY, int toX, int toY) protected booleanonEnd(InputEvent event) Handles the "end" command (jump to last item).protected booleanonEnter(InputEvent event) Handles the Enter key activation.protected booleanonHome(InputEvent event) Handles the "home" command (jump to first item).booleanonInputEvent(InputEvent event) protected booleanHandles the completion of a listening session, moving the hot point to the position where listening stopped.protected booleanonMoveDown(InputEvent event, boolean briefAnnouncement) Handles the "move down" command.protected booleanonMoveHotPoint(MoveHotPointEvent event) Handles aMoveHotPointEventto reposition the hot point.protected booleanonMoveLeft(InputEvent event) Handles the "move left" command (character by character).protected booleanonMoveRight(InputEvent event) Handles the "move right" command (character by character).protected booleanonMoveUp(InputEvent event, boolean briefAnnouncement) Handles the "move up" command.protected voidonNewHotPointY(boolean briefAnnouncement) Called after the hot point Y coordinate changes.protected booleanonOk(SystemEvent event) Handles the OK system event (alternative activation).protected booleanonPageDown(InputEvent event, boolean briefAnnouncement) Handles the "page down" command.protected booleanonPageUp(InputEvent event, boolean briefAnnouncement) Handles the "page up" command.onRegionTextQuery(int fromX, int fromY, int toX, int toY) booleanonSystemEvent(SystemEvent event) protected booleanonTransition(ListArea.Transition.Type type, Hint hint, boolean briefAnnouncement) Performs a transition based on the given type, using the current state and the list's transition logic.voidredraw()Redraws the area content and adjusts the hot point similarly torefresh(), but without callingModel.refresh().voidrefresh()Refreshes the content of the list.voidreset(boolean announce) Resets the region point and the hot point to the beginning of the list.voidResets the hot point to the first item (or the top empty line if the list is empty) without any announcement.voidresetHotPoint(boolean introduce) Resets the hot point to the first item (or the top empty line if the list is empty).booleanselect(int index, boolean announce) Selects the item by its index.booleanSearches for the item in the model and sets hot point on it.final Eselected()Returns the object in the model corresponding to current hot point position.final intThe index of the item in the model which is under the hot point in this list.booleanselectEmptyLineBottom(boolean announce) Moves the hot point to the bottom empty line, if the list has one.voidsetAreaName(String areaName) Sets the area name and notifies the context of the change.voidsetListClickHandler(ListArea.ClickHandler<E> clickHandler) Sets the click handler for item activation.
-
Field Details
-
NONE_APPEARANCE_FLAGS
-
BRIEF_ANNOUNCEMENT_ONLY
-
context
-
regionPoint
-
clipboardTranslator
-
regionTextQueryTranslator
-
areaName
-
listModel
-
listAppearance
-
listTransition
-
listClipboardSaver
-
listFlags
-
listClickHandler
-
hotPointX
protected int hotPointX -
hotPointY
protected int hotPointY
-
-
Constructor Details
-
ListArea
Constructs a new list area with the given parameters.- Parameters:
params- the configuration parameters (must not benull)- Throws:
NullPointerException- ifparamsor any required field isnull
-
-
Method Details
-
setListClickHandler
Sets the click handler for item activation.- Parameters:
clickHandler- the handler to set (may benull)
-
getListModel
Returns the data model used by this list.- Returns:
- the model
-
getListAppearance
Returns the appearance controller used by this list.- Returns:
- the appearance
-
selected
Returns the object in the model corresponding to current hot point position. If the model is empty or hot point is on an empty line, this method always returnsnull.- Returns:
- The object in the model associated with the currently selected line or
nullif there is no any
-
selectedIndex
public final int selectedIndex()The index of the item in the model which is under the hot point in this list. This method returns the index in the model, not on the screen. It means that the value returned by this method may be different than the value returned bygetHotPointY()(but may be equal as well). If the list is empty or an empty line is selected, this method returns -1.- Returns:
- The index of the selected line in the model or -1 if there is no any
-
select
Searches for the item in the model and sets hot point on it. Given an arbitrary object, this method looks through all items in the model and does a couple of checks: literal pointers equality and a check withequals()method. If at least one of these checks succeeds, the item is considered equal to the given one, and hot points is set on it.- Parameters:
obj- The object to search forannounce- Must be true if it is necessary to introduce the object, once it's found- Returns:
- True if the request object is found, false otherwise
-
select
public boolean select(int index, boolean announce) Selects the item by its index. Given the non-negative integer value as an index, this method sets the hot point on the item addressed with this index, checking only that index is in appropriate bounds. Index must address the object as a number in the model, ignoring any empty lines.- Parameters:
index- The item index to selectannounce- Must be true, if it is necessary to announce the item , once it has been selected- Returns:
- True if the index is valid and the item gets hot point on it
-
selectEmptyLineBottom
public boolean selectEmptyLineBottom(boolean announce) Moves the hot point to the bottom empty line, if the list has one.- Parameters:
announce- iftrue, the empty line is announced- Returns:
trueif the operation succeeded,falseif there is no bottom empty line
-
getExistingItemIndexOnLine
public int getExistingItemIndexOnLine(int lineIndex) Given a line index (screen coordinate), returns the corresponding item index in the model, or -1 if the line does not contain a valid item.- Parameters:
lineIndex- the screen line index (non-negative)- Returns:
- the model index, or -1 if not on an item
- Throws:
IllegalArgumentException- iflineIndexis negative
-
getItemIndexOnLine
public int getItemIndexOnLine(int index) Converts a screen line index to a model index, without checking whether the resulting index is within the model bounds. This is used internally for calculations.- Parameters:
index- the screen line index- Returns:
- the model index (may be out of bounds)
-
getLineIndexByItemIndex
public int getLineIndexByItemIndex(int index) Converts a model item index to the corresponding screen line index.- Parameters:
index- the model index- Returns:
- the screen line index, or -1 if the index is invalid
-
getItemOnLine
Returns the item displayed on the given screen line.- Parameters:
lineIndex- the screen line index (non-negative)- Returns:
- the item, or
nullif the line is empty or out of range - Throws:
IllegalArgumentException- iflineIndexis negative
-
getListItemCount
public int getListItemCount()Returns the total number of items in the model.- Returns:
- the item count
-
reset
public void reset(boolean announce) Resets the region point and the hot point to the beginning of the list.- Parameters:
announce- iftrue, the newly selected item is announced
-
resetHotPoint
public void resetHotPoint()Resets the hot point to the first item (or the top empty line if the list is empty) without any announcement. -
resetHotPoint
public void resetHotPoint(boolean introduce) Resets the hot point to the first item (or the top empty line if the list is empty).- Parameters:
introduce- iftrue, the newly selected item is announced
-
announceSelected
public void announceSelected()Announces the currently selected item using the appearance. -
refresh
public void refresh()Refreshes the content of the list. This method callsrefresh()method of the model and displays new items. It does not produce any speech announcement of the change. HotPointY is preserved if it is possible (meaning, the new number of lines not less than old value of hotPointY), but hotPointX is moved to the beginning of the line. -
redraw
public void redraw()Redraws the area content and adjusts the hot point similarly torefresh(), but without callingModel.refresh(). -
isEmpty
public boolean isEmpty()Checks whether the list model contains any items.- Returns:
trueif the model is empty,falseotherwise
-
onInputEvent
- Specified by:
onInputEventin interfaceArea
-
onSystemEvent
- Specified by:
onSystemEventin interfaceArea
-
onAreaQuery
- Specified by:
onAreaQueryin interfaceArea
-
getAreaActions
- Specified by:
getAreaActionsin interfaceArea
-
getLineCount
public int getLineCount()- Specified by:
getLineCountin interfaceLines
-
getLine
-
getHotPointX
public int getHotPointX()- Specified by:
getHotPointXin interfaceArea- Specified by:
getHotPointXin interfaceHotPoint
-
getHotPointY
public int getHotPointY()- Specified by:
getHotPointYin interfaceArea- Specified by:
getHotPointYin interfaceHotPoint
-
getAreaName
- Specified by:
getAreaNamein interfaceArea
-
setAreaName
Sets the area name and notifies the context of the change.- Parameters:
areaName- the new area name (must not benull)- Throws:
NullPointerException- ifareaNameisnull
-
onAnnounce
protected boolean onAnnounce()Announces the list area. If the area is created withAREA_ANNOUNCE_SELECTEDflag, this method speaks the screen text of the currently selected item or the area name otherwise (without the flag or if there is no selected item). -
onAnnounceLine
protected boolean onAnnounceLine()Announces the current line (the item under the hot point).- Returns:
trueif the announcement was handled
-
onMoveHotPoint
Handles aMoveHotPointEventto reposition the hot point.- Parameters:
event- the event (must not benull)- Returns:
trueif the hot point was moved
-
onBeginListeningQuery
Handles aBeginListeningQueryto start continuous reading from the current hot point position.- Parameters:
query- the query (must not benull)- Returns:
trueif the query was answered
-
onListeningFinishedEvent
Handles the completion of a listening session, moving the hot point to the position where listening stopped.- Parameters:
event- the event (must not benull)- Returns:
trueif the hot point was updated
-
onChar
Handles character input for incremental search. Moves the hot point to the first item whose observable text starts with the accumulated prefix.- Parameters:
event- the input event- Returns:
trueif the character was processed
-
onMoveDown
Handles the "move down" command.- Parameters:
event- the input eventbriefAnnouncement- iftrue, use brief announcement- Returns:
trueif handled
-
onMoveUp
Handles the "move up" command.- Parameters:
event- the input eventbriefAnnouncement- iftrue, use brief announcement- Returns:
trueif handled
-
onPageDown
Handles the "page down" command.- Parameters:
event- the input eventbriefAnnouncement- iftrue, use brief announcement- Returns:
trueif handled
-
onPageUp
Handles the "page up" command.- Parameters:
event- the input eventbriefAnnouncement- iftrue, use brief announcement- Returns:
trueif handled
-
onEnd
Handles the "end" command (jump to last item).- Parameters:
event- the input event- Returns:
trueif handled
-
onHome
Handles the "home" command (jump to first item).- Parameters:
event- the input event- Returns:
trueif handled
-
onTransition
Performs a transition based on the given type, using the current state and the list's transition logic.- Parameters:
type- the type of transitionhint- the hint to provide if no transition is possiblebriefAnnouncement- iftrue, use brief announcement- Returns:
trueif the transition was processed
-
onMoveRight
Handles the "move right" command (character by character).- Parameters:
event- the input event- Returns:
trueif handled
-
onMoveLeft
Handles the "move left" command (character by character).- Parameters:
event- the input event- Returns:
trueif handled
-
onAltRight
Handles the alternative right command (move by word forward).- Parameters:
event- the input event- Returns:
trueif handled
-
onAltLeft
Handles the alternative left command (move by word backward).- Parameters:
event- the input event- Returns:
trueif handled
-
onAltEnd
Handles the alternative end command (jump to the end of the line).- Parameters:
event- the input event- Returns:
trueif handled
-
onAltHome
Handles the alternative home command (jump to the beginning of the line).- Parameters:
event- the input event- Returns:
trueif handled
-
onEnter
Handles the Enter key activation.- Parameters:
event- the input event- Returns:
trueif the click was handled
-
onOk
Handles the OK system event (alternative activation).- Parameters:
event- the system event- Returns:
trueif the click was handled
-
onRegionTextQuery
- Specified by:
onRegionTextQueryin interfaceRegionTextQueryTranslator.Provider
-
onClipboardCopyAll
public boolean onClipboardCopyAll()- Specified by:
onClipboardCopyAllin interfaceClipboardTranslator.Provider
-
onClipboardCopy
public boolean onClipboardCopy(int fromX, int fromY, int toX, int toY, boolean withDeleting) - Specified by:
onClipboardCopyin interfaceClipboardTranslator.Provider
-
onDeleteRegion
public boolean onDeleteRegion(int fromX, int fromY, int toX, int toY) - Specified by:
onDeleteRegionin interfaceClipboardTranslator.Provider
-
onNewHotPointY
protected void onNewHotPointY(boolean briefAnnouncement) Called after the hot point Y coordinate changes. Updates the hot point X to the left bound of the new item and announces it.- Parameters:
briefAnnouncement- iftrue, use brief announcement
-
getObservableSubstr
Returns the observable substring of an item's screen representation, i.e., the part between its left and right bounds.- Parameters:
item- the item (must not benull)- Returns:
- the observable substring, or an empty string if not applicable
-
noContentStr
Returns the string to display when the list has no content.- Returns:
- the "no content" string
-
announceChar
Announces a character at the given position, or a line bound hint if at the end.- Parameters:
line- the full line textpos- the current hot point columnrightBound- the right observable bound
-
noContent
protected boolean noContent()Checks whether the list has no content and, if so, sets an appropriate hint response.- Returns:
trueif the list is empty,falseotherwise
-