Class SChoice

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.select.Select<Integer>, Integer>
com.vaadin.flow.component.AbstractSinglePropertyField<com.vaadin.flow.component.select.Select<Integer>, Integer>
com.vaadin.flow.component.select.Select<Integer>
com.vaadin.swingbridge.surrogates.SChoice
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 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 is Integer: 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, no Store 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.SelectI18n

    Nested 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Appends an item.
    void
     
     
    getItemAt(int index)
     
    int
     
     
    int
     
     
     
    void
    insertItemAt(String item, int index)
     
    protected String
    AWT's Choice.paramString tail: the selected item.
    protected void
    AWT's dispatch hook.
    void
    Empties the list; the selection becomes "none" (-1).
    void
    Removes the first occurrence.
    void
    removeItemAt(int position)
     
    void
     
    void
    select(int pos)
    Selects by position.
    void
    Selects the first item equal to str, or does nothing when there is no match — AWT is silent here, unlike removeItem(String).
    void
    setEnabled(boolean enabled)
    Vaadin HasEnabled's concrete default shadows the mixin's setEnabled (which carries SD_auto_pce's auto-PCE).
    void
    setItemsAndSelection(List<String> texts, int selectedIndex)
    Replaces the items and the selection in one rebuild, applying none of the insert / remove selection rules above.
    void
    Converges with select(int) so the fan-out doesn't depend on which API the caller reached for.
    void
    Widens Select.validate() to public so the mixin's validate() 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, valueEquals

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValue

    Methods 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, whenAttached

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.BlurNotifier

    addBlurListener

    Methods 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, update

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.Focusable

    addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndex

    Methods inherited from interface com.vaadin.flow.component.FocusNotifier

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.HasAriaDescription

    setAriaDescribedBy

    Methods inherited from interface com.vaadin.flow.component.HasAriaLabel

    setAriaLabelledBy

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add

    Methods inherited from interface com.vaadin.flow.component.HasComponentsOfType

    add, bindChildren, getComponentAt, getComponentCount, indexOf, remove, replace

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    bindEnabled, isEnabled

    Methods inherited from interface com.vaadin.flow.component.HasHelper

    bindHelperText, getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView

    setItems, setItems

    Methods inherited from interface com.vaadin.flow.component.HasPlaceholder

    bindPlaceholder, getPlaceholder

    Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix

    getPrefixComponent, setPrefixComponent

    Methods 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, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasTheme

    addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, bindThemeVariant, bindThemeVariants, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipMarkdown, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    getErrorMessage, isInvalid, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.data.binder.HasValidator

    addValidationStatusChangeListener

    Methods inherited from interface com.vaadin.flow.component.HasValue

    addValueChangeListener, bindValue, clear, getEmptyValue, getOptionalValue, getValue, isEmpty

    Methods inherited from interface com.vaadin.flow.component.HasValueAndElement

    bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, setReadOnly
  • Constructor Details

    • SChoice

      public SChoice()
  • Method Details

    • getItemCount

      public int getItemCount()
    • getItemAt

      public String getItemAt(int index)
      Throws:
      ArrayIndexOutOfBoundsException - as AWT's Vector.elementAt does — explicitly, because ArrayList.get raises the plain IndexOutOfBoundsException superclass and a migrator's catch would miss it (R_match_swing_errors)
    • addItem

      public void addItem(String item)
      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

      public void insertItemAt(String item, int index)
      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

      public void removeItem(String item)
      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, unlike select(String)
    • removeItemAt

      public void removeItemAt(int position)
      Throws:
      ArrayIndexOutOfBoundsException - as AWT's Vector.removeElementAt does (R_match_swing_errors)
    • removeAllItems

      public void removeAllItems()
      Empties the list; the selection becomes "none" (-1).
    • setItemsAndSelection

      public void setItemsAndSelection(List<String> texts, int selectedIndex)
      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 emulator vaadinx.awt.Choice does.
      Parameters:
      texts - copied; the caller keeps ownership
      selectedIndex - -1 for none. AWT keeps a non-empty list selected, but a select(int) override that skips super can leave it unselected, so -1 is accepted with items too
      Throws:
      IllegalArgumentException - when selectedIndex is out of range
      NullPointerException - on a null item
    • getSelectedIndex

      public int getSelectedIndex()
      Returns:
      -1 when there is no selection, which for AWT means "no items"
    • getSelectedItem

      public String getSelectedItem()
      Returns:
      null when there is no selection
    • getSelectedObjects

      public Object[] getSelectedObjects()
      Specified by:
      getSelectedObjects in interface ItemSelectable
      Returns:
      a length-1 array, or null — not an empty array — when nothing is selected. SJComboBox.getSelectedObjects() returns new 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 no ItemEvent — in AWT only user interaction does, which is the sharpest divergence from SJComboBox (JComboBox fires on both paths).
      Throws:
      IllegalArgumentException - when out of range, as in AWT (R_match_swing_errors)
    • select

      public void select(String str)
      Selects the first item equal to str, or does nothing when there is no match — AWT is silent here, unlike removeItem(String). Fires no ItemEvent, same as select(int).
    • setValue

      public void setValue(Integer value)
      Converges with select(int) so the fan-out doesn't depend on which API the caller reached for.
      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.select.Select<Integer>, Integer>, Integer>
      Overrides:
      setValue in class com.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 as select does
    • addItemListener

      public void addItemListener(ItemListener l)
      Specified by:
      addItemListener in interface ItemSelectable
    • removeItemListener

      public void removeItemListener(ItemListener l)
      Specified by:
      removeItemListener in interface ItemSelectable
    • getItemListeners

      public ItemListener[] getItemListeners()
    • processItemEvent

      protected void processItemEvent(ItemEvent e)
      AWT's dispatch hook. Overriding it (and calling super) is the documented way for java.awt.Choice subclasses 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)
      Vaadin HasEnabled's concrete default shadows the mixin's setEnabled (which carries SD_auto_pce's auto-PCE). Redirect explicitly, same as SButton.
      Specified by:
      setEnabled in interface ComponentMixin
      Specified by:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
    • validate

      public void validate()
      Widens Select.validate() to public so the mixin's validate() contract is satisfied — a class member beats an interface default, and narrowing the visibility would not compile. The SJComboBox.validate() precedent.
      Specified by:
      validate in interface ComponentMixin
      Overrides:
      validate in class com.vaadin.flow.component.select.Select<Integer>
    • paramString

      protected String paramString()
      AWT's Choice.paramString tail: the selected item.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()