Class SChoice
java.lang.Object
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.select.Select<Integer>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.select.Select<Integer>>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.select.Select<Integer>>, com.vaadin.flow.component.HasAriaDescription, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasComponentsOfType<com.vaadin.flow.component.Component>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasPlaceholder, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.select.Select<Integer>, Integer>, Integer>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.select.Select<Integer>, Integer>, Integer>, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.select.SelectVariant>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.select.Select<Integer>, Integer>, Integer>, com.vaadin.flow.data.binder.HasItemComponents<Integer>, com.vaadin.flow.data.binder.HasValidator<Integer>, com.vaadin.flow.data.provider.HasDataView<Integer, Void, com.vaadin.flow.component.select.data.SelectDataView<Integer>>, com.vaadin.flow.data.provider.HasListDataView<Integer, com.vaadin.flow.component.select.data.SelectListDataView<Integer>>, com.vaadin.flow.data.selection.SingleSelect<com.vaadin.flow.component.select.Select<Integer>, Integer>, ComponentMixin, ItemSelectable, Serializable
public class SChoice
extends com.vaadin.flow.component.select.Select<Integer>
implements ComponentMixin, ItemSelectable
Surrogate for Why not a re-skin of
Choice — the AWT 1.0 dropdown, not
JComboBox. Extends Vaadin Select directly
(is-a) and picks up the AWT Component API from
ComponentMixin.
SChoice c = new SChoice();
c.addItem("Red");
c.addItem("Green"); // "Red" is already selected — the first add selects it
c.select("Green"); // silent: no ItemEvent, exactly as in AWT
Why not a re-skin of SJComboBox
java.awt.Choice is a Vector<String> plus an int.
It has no ComboBoxModel, no ListDataListener, no editable
mode, no ComboBoxEditor, no PopupMenuListener, no
maximumRowCount, no ListCellRenderer and no
ActionListener — reusing SJComboBox would graft an entire
MVC layer onto a class that has none of it. The host differs for the same
reason: SJComboBox needs Vaadin ComboBox for
allowCustomValue / filtering / pageSize, and giving
Choice that host would hand the migrator a text input the JDK
class does not have. See SD_schoice.
Index identity (SD_sjlist's rule, second application)
The type parameter isInteger: the peer's items are the
indices 0..n-1, with Select.setItemLabelGenerator(ItemLabelGenerator)
supplying the rendered text from items. Choice permits
duplicate item Strings, and Vaadin's KeyMapper keys items in a
HashMap — equal Strings (usually the same interned instance)
would collapse to one key, which no IdentifierProvider could
separate. Indices make that unreachable rather than merely tolerated,
and they carry a bonus: the Vaadin value is the AWT concept, so
selectedIndex needs no storage at all.
State
Three plain fields, noStore class: the List<String> item
texts (R_vaadin_first-legitimate — with index identity the data provider holds
indices, so it cannot also hold the labels), the preventPeerEvents
guard, and an EventListenerList driving the ItemListener
fan-out. The Store classes exist for mixin-shared state and for
hosts whose Vaadin super-ctor invokes a subclass override before its
fields exist; Select's ctor calls setPresentationValue,
not setValue, so neither applies here.
The item-mutation family is named after SJComboBox
(addItem / insertItemAt / removeItem /
removeItemAt / removeAllItems /
getItemAt), not after AWT. Choice.removeAll()
and Select.removeAll() are an exact signature collision
with opposite meanings — Vaadin's removes the non-item
slotted children — so the AWT names live on the emulator
vaadinx.awt.Choice, which does not extend Select.
Note also that Select.setLabel(String) here is Vaadin's floating field
caption, unlike SButton.setLabel(String) which is AWT's button
caption.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.select.Select
com.vaadin.flow.component.select.Select.InvalidChangeEvent, com.vaadin.flow.component.select.Select.OpenedChangeEvent, com.vaadin.flow.component.select.Select.SelectI18nNested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C,V> 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>Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents
com.vaadin.flow.data.binder.HasItemComponents.ItemComponent<T>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E> -
Field Summary
Fields inherited from class com.vaadin.flow.component.select.Select
LABEL_ATTRIBUTE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends an item.voidgetItemAt(int index) intintObject[]voidinsertItemAt(String item, int index) protected StringAWT'sChoice.paramStringtail: the selected item.protected voidAWT's dispatch hook.voidEmpties the list; the selection becomes "none" (-1).voidremoveItem(String item) Removes the first occurrence.voidremoveItemAt(int position) voidvoidselect(int pos) Selects by position.voidSelects the first item equal tostr, or does nothing when there is no match — AWT is silent here, unlikeremoveItem(String).voidsetEnabled(boolean enabled) VaadinHasEnabled's concrete default shadows the mixin'ssetEnabled(which carries SD_auto_pce's auto-PCE).voidsetItemsAndSelection(List<String> texts, int selectedIndex) Replaces the items and the selection in one rebuild, applying none of the insert / remove selection rules above.voidConverges withselect(int)so the fan-out doesn't depend on which API the caller reached for.voidvalidate()WidensSelect.validate()to public so the mixin'svalidate()contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile.Methods inherited from class com.vaadin.flow.component.select.Select
add, addComponentAsFirst, addComponentAtIndex, addComponents, addInvalidChangeListener, addOpenedChangeListener, getAriaDescribedBy, getAriaLabel, getAriaLabelledBy, getChildren, getDataProvider, getDefaultValidator, getEmptySelectionCaption, getGenericDataView, getI18n, getItemEnabledProvider, getItemLabelGenerator, getItemPosition, getItemRenderer, getLabel, getListDataView, hasValidValue, isAutofocus, isEmptySelectionAllowed, isNoVerticalOverlap, isOpened, isRequiredIndicatorVisible, onEnabledStateChanged, prependComponents, remove, removeAll, setAriaDescribedBy, setAriaLabel, setAriaLabelledBy, setAutofocus, setDataProvider, setEmptySelectionAllowed, setEmptySelectionCaption, setI18n, setItemEnabledProvider, setItemLabelGenerator, setItems, setItems, setItems, setLabel, setManualValidation, setNoVerticalOverlap, setOpened, setOverlayWidth, setOverlayWidth, setPlaceholder, setRenderer, setRequiredIndicatorVisible, setTextRenderer, valueEqualsMethods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValueMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, 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, setFocusable, setFont, setForeground, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setToolTipText, transferFocus, transferFocusBackward, transferFocusUpCycle, updateMethods 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.HasAriaDescription
setAriaDescribedByMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasComponents
addMethods inherited from interface com.vaadin.flow.component.HasComponentsOfType
add, bindChildren, getComponentAt, getComponentCount, indexOf, remove, replaceMethods 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.HasHelper
bindHelperText, getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, setItemsMethods inherited from interface com.vaadin.flow.component.HasPlaceholder
bindPlaceholder, getPlaceholderMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods 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, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.data.binder.HasValidator
addValidationStatusChangeListenerMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, bindValue, clear, getEmptyValue, getOptionalValue, getValue, isEmptyMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, setReadOnly
-
Constructor Details
-
SChoice
public SChoice()
-
-
Method Details
-
getItemCount
public int getItemCount() -
getItemAt
- Throws:
ArrayIndexOutOfBoundsException- as AWT'sVector.elementAtdoes — explicitly, becauseArrayList.getraises the plainIndexOutOfBoundsExceptionsuperclass and a migrator'scatchwould miss it (R_match_swing_errors)
-
addItem
Appends an item. If it is the first, it becomes selected — AWT's "a non-empty Choice always has a selection" invariant falls out of the insert rule below.- Throws:
NullPointerException- on a null item, as in AWT (R_match_swing_errors)
-
insertItemAt
- Parameters:
index- clamped to the item count when too large, as in AWT- Throws:
IllegalArgumentException- on a negative index, as in AWT (R_match_swing_errors)NullPointerException- on a null item, as in AWT (R_match_swing_errors)
-
removeItem
Removes the first occurrence.- Throws:
IllegalArgumentException- when the item is not present, as in AWT (R_match_swing_errors) — note AWT throws rather than no-opping here, unlikeselect(String)
-
removeItemAt
public void removeItemAt(int position) - Throws:
ArrayIndexOutOfBoundsException- as AWT'sVector.removeElementAtdoes (R_match_swing_errors)
-
removeAllItems
public void removeAllItems()Empties the list; the selection becomes "none" (-1). -
setItemsAndSelection
Replaces the items and the selection in one rebuild, applying none of the insert / remove selection rules above. For a caller that keeps AWT's item vector itself and flushes it here after each change — the emulatorvaadinx.awt.Choicedoes.- Parameters:
texts- copied; the caller keeps ownershipselectedIndex--1for none. AWT keeps a non-empty list selected, but aselect(int)override that skips super can leave it unselected, so-1is accepted with items too- Throws:
IllegalArgumentException- whenselectedIndexis out of rangeNullPointerException- on a null item
-
getSelectedIndex
public int getSelectedIndex()- Returns:
- -1 when there is no selection, which for AWT means "no items"
-
getSelectedItem
- Returns:
- null when there is no selection
-
getSelectedObjects
- Specified by:
getSelectedObjectsin interfaceItemSelectable- Returns:
- a length-1 array, or null — not an empty array — when
nothing is selected.
SJComboBox.getSelectedObjects()returnsnew Object[0]for the same method: AWT and Swing take opposite conventions and each is reproduced.
-
select
public void select(int pos) Selects by position. Fires noItemEvent— in AWT only user interaction does, which is the sharpest divergence fromSJComboBox(JComboBox fires on both paths).- Throws:
IllegalArgumentException- when out of range, as in AWT (R_match_swing_errors)
-
select
Selects the first item equal tostr, or does nothing when there is no match — AWT is silent here, unlikeremoveItem(String). Fires noItemEvent, same asselect(int). -
setValue
Converges withselect(int)so the fan-out doesn't depend on which API the caller reached for.- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.select.Select<Integer>, Integer>, Integer>- Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<com.vaadin.flow.component.select.Select<Integer>, Integer>- Parameters:
value- null clears the selection; anything else must be a valid position, and throws exactly asselectdoes
-
addItemListener
- Specified by:
addItemListenerin interfaceItemSelectable
-
removeItemListener
- Specified by:
removeItemListenerin interfaceItemSelectable
-
getItemListeners
-
processItemEvent
AWT's dispatch hook. Overriding it (and calling super) is the documented way forjava.awt.Choicesubclasses to intercept every selection before its listeners see it, so it stays the single funnel the peer's value change routes through. -
setEnabled
public void setEnabled(boolean enabled) VaadinHasEnabled's concrete default shadows the mixin'ssetEnabled(which carries SD_auto_pce's auto-PCE). Redirect explicitly, same asSButton.- Specified by:
setEnabledin interfaceComponentMixin- Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled
-
validate
public void validate()WidensSelect.validate()to public so the mixin'svalidate()contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile. TheSJComboBox.validate()precedent.- Specified by:
validatein interfaceComponentMixin- Overrides:
validatein classcom.vaadin.flow.component.select.Select<Integer>
-
paramString
AWT'sChoice.paramStringtail: the selected item. -
getAccessibleContext
-