Class SList
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<SList>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<SList>, com.vaadin.flow.component.FocusNotifier<SList>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, ComponentMixin, ItemSelectable, Serializable
List — the AWT 1.0 scrolling list box, not
JList. Hosts a native <select> directly
(is-a HtmlComponent) and picks up the AWT Component API
from ComponentMixin.
SList l = new SList(4, false);
l.addItem("Mercury", -1);
l.addItem("Venus", -1);
l.select(1); // silent: no ItemEvent, exactly as in AWT
l.addItemListener(e -> log(e.getItem())); // only the browser fires
Why a native <select> and not Grid
java.awt.List and an HTML <select size=N> are the same
widget — both 1995-era scrolling selection boxes — so most of what a
Grid peer would have to simulate, the element simply is. The
size attribute is AWT's rows; the multiple
attribute is the runtime setMultipleMode(boolean) flip, with no
component swap; the <option> children are the item store,
positionally identified, so duplicate item Strings need none of
SJList's SD_sjlist index-identity machinery; and writing
option.selected fires no change, which is AWT's
documented "programmatic selection is silent" contract for free rather
than a rule to enforce. Rationale, the measured rendering table and the
rejected Grid / VirtualList / ListBox designs:
SD_slist.
The trade, taken deliberately: a native <select multiple> is
not themed by Aura. That is SScrollbar's bargain (SD_sscrollbar) — an AWT
widget rendering as the browser's own control — and here it arguably
reads as fidelity rather than as a gap.
size is floored at 2
A <select> renders as a drop-down at size=1
without multiple, and as a list box otherwise (measured in Gecko;
the HTML spec says "list box control" when multiple is present or
size > 1). AWT's rows defaults to 4 but
new List(1) is legal, so applyRows(int) emits
max(2, rows). This is a rendering floor only — the
emulator's getRows() returns the JDK value verbatim, negatives
included, because rows never round-trips through the attribute.
State
Items,multipleMode and rows are all DOM state, so none of
them is a field here. The one mirror is selected: the browser
owns the selection and the server cannot read it synchronously, so the
change bridge writes it and every programmatic
select(int)/deselect(int) writes it through alongside the DOM.
That is an R_swing_is_truth write-through, not an R_vaadin_first shadow cache — and notably it needs
no preventPeerEvents guard, because our own write fires
no change, so the feedback loop the guard exists to break cannot
form.
removeAll() is named removeAllItems() here, the
SJComboBox.removeAllItems() convention, so nothing reads as
the HasComponents container clear to a stage-3 eye; the
emulator vaadinx.awt.List carries AWT's removeAll
and clear names. AWT's generic
getListeners(Class) is absent for the SD_sbutton erasure clash
against Vaadin Component's.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C>Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidAWT'saddItem(String, int)— the one insert body, coercions included: an out-of-range index appends and a null item becomes"".voidvoiddeselect(int index) Deselects a row, reproducing AWT's guard rather than only its outcome: in SINGLE mode the call reaches the peer only whenindexis the sole selected row.getItemAt(int index) intString[]intint[]Ascending, and a fresh array each call — never the live mirror.String[]Object[]intindexOfItem(String item) The index of the first item equal toitem, or-1.booleanisIndexSelected(int index) booleanRead straight off the peer — no shadow, the round-trip is lossless.voidmakeVisible(int index) scrollIntoViewon the row; no read-back, so no getter here.protected StringAWT'sList.paramStringtail.protected voidTheActionEventtwin ofprocessItemEvent(ItemEvent).protected voidAWT's dispatch hook, and the single funnel every browser selection reaches the listeners through.voidvoidEmpties the list and the selection.voidvoidremoveItemRange(int start, int end) AWT'sdelItems(start, end), quirk and all: the loop runs downwards fromend, so a negativestartremoves the higher indices and then throws, leaving the list shorter.voidselect(int index) Selects a row.voidsetItemsAndSelection(List<String> texts, int[] selectedIndexes) Replaces the items and the selection, applying none of the insert / remove selection rules above.voidsetMultipleMode(boolean multipleMode) Flips themultipleattribute live.voidsetSelectedIndexes(int[] selectedIndexes) Shows exactly this selection, applying none of the selection rules above.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface ComponentMixin
_installSwingClass, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, dispatchEvent, doLayout, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getComponentListeners, getCursor, getFocusListeners, getFont, getForeground, getGraphics, getHierarchyBoundsListeners, getHierarchyListeners, getKeyListeners, getLocation, getMaximumSize, getMinimumSize, getMouseListeners, getName, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolTipText, getX, getY, grabFocus, hasFocus, invalidate, isDisplayable, isFocusable, isFocusOwner, isShowing, paint, paintAll, print, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, revalidate, setBackground, setBounds, setBounds, setCursor, setEnabled, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setToolTipText, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
SList
public SList() -
SList
public SList(int rows) -
SList
public SList(int rows, boolean multipleMode) - Parameters:
rows- AWT's visible-row count, already through the JDK's(rows != 0) ? rows : 4substitution by the caller; emitted assize=max(2, rows)
-
-
Method Details
-
getItemCount
public int getItemCount() -
getItemAt
- Throws:
ArrayIndexOutOfBoundsException- as AWT'sVector.elementAtdoes — explicitly, because the plainIndexOutOfBoundsExceptionsuperclass would slip past a migrator'scatch(R_match_swing_errors)
-
getItemsArray
-
addItem
AWT'saddItem(String, int)— the one insert body, coercions included: an out-of-range index appends and a null item becomes"". Never throws.- Parameters:
index--1, or anything outside[0, count), appends
-
removeItemRange
public void removeItemRange(int start, int end) AWT'sdelItems(start, end), quirk and all: the loop runs downwards fromend, so a negativestartremoves the higher indices and then throws, leaving the list shorter. Anendpast the top throws on the first removal with nothing removed.- Throws:
ArrayIndexOutOfBoundsException- exactly where AWT'sVector.removeElementAtwould (R_match_swing_errors)
-
setItemsAndSelection
Replaces the items and the selection, applying none of the insert / remove selection rules above. For a caller that keeps AWT's item vector and selection itself and flushes them here after each change — the emulatorvaadinx.awt.Listdoes. Only the rows that differ are touched (the common prefix and suffix stay), so a caller flushing after every singleaddcosts one<option>per call.- Parameters:
texts- copied; a null entry renders as"", as AWT stores itselectedIndexes- seesetSelectedIndexes(int[])
-
setSelectedIndexes
public void setSelectedIndexes(int[] selectedIndexes) Shows exactly this selection, applying none of the selection rules above. Fires noItemEvent.- Parameters:
selectedIndexes- in any order, duplicates allowed; entries outside the rows are skipped, since nothing can render them. In SINGLE mode only the first rendered entry shows, since a single-select<select>holds one — the caller may keep more (AWT's own selection array can, after a multi → single flip while peerless)
-
removeAllItems
public void removeAllItems()Empties the list and the selection. -
indexOfItem
The index of the first item equal toitem, or-1. -
select
public void select(int index) Selects a row. Fires noItemEvent— AWT's javadoc says so outright, and here it is the platform's behaviour rather than something suppressed. Out of range is a no-op: AWT documents out-of-range as "unspecified behavior" and its peer path silently does nothing. -
deselect
public void deselect(int index) Deselects a row, reproducing AWT's guard rather than only its outcome: in SINGLE mode the call reaches the peer only whenindexis the sole selected row. Fires noItemEvent. -
getSelectedIndexes
public int[] getSelectedIndexes()Ascending, and a fresh array each call — never the live mirror. -
getSelectedIndex
public int getSelectedIndex()- Returns:
- the sole selected index, or
-1when nothing or more than one thing is selected. Not "the first selected index" — AWT's body is(sel.length == 1) ? sel[0] : -1
-
getSelectedItem
- Returns:
- null when nothing, or more than one thing, is selected
-
getSelectedItemsArray
-
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- an empty array when nothing is selected — AWT's
Listconvention, and the opposite ofSChoice.getSelectedObjects(), which answers null
-
isIndexSelected
public boolean isIndexSelected(int index) -
isMultipleMode
public boolean isMultipleMode()Read straight off the peer — no shadow, the round-trip is lossless. Reads the attribute becauseapplyMultipleMode(boolean)writes one; Vaadin's property map and its attribute map are separate, sogetProperty("multiple", …)would answer false forever. -
setMultipleMode
public void setMultipleMode(boolean multipleMode) Flips themultipleattribute live. Fires noItemEvent.Going multiple → single, the browser keeps at most one option selected (measured in Gecko: the first). AWT's rule is "the item with the location cursor stays, else all are deselected" and there is no location cursor here, so the mirror is trimmed to match what the browser will have done — a third outcome inside the same R_best_effort_behaviour latitude, and closer to AWT than dropping the selection wholesale.
-
makeVisible
public void makeVisible(int index) scrollIntoViewon the row; no read-back, so no getter here. -
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
addActionListener
-
removeActionListener
-
getActionListeners
-
processItemEvent
AWT's dispatch hook, and the single funnel every browser selection reaches the listeners through. Overriding it and calling super is the documented interception idiom forjava.awt.Listsubclasses. -
processActionEvent
TheActionEventtwin ofprocessItemEvent(ItemEvent). -
paramString
AWT'sList.paramStringtail. -
getAccessibleContext
-