Class SJToggleButton
java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.button.Button
com.vaadin.swingbridge.surrogates.SJToggleButton
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.button.ButtonVariant>, com.vaadin.flow.component.shared.HasTooltip, ComponentMixin, ContainerMixin, AbstractButtonMixin, JComponentMixin, ItemSelectable, Serializable
@StyleSheet("emul/sjtogglebutton.css")
public class SJToggleButton
extends com.vaadin.flow.component.button.Button
implements AbstractButtonMixin
Surrogate for
JToggleButton (SD_sjtogglebutton_button_peer). Extends Vaadin
Button directly (is-a), rendering a stays-pressed button —
JToggleButton's actual Swing look — rather than a checkbox glyph.
Reaches the migrator either through :emulators.JToggleButton as
peer, or as a richer-than-stock Vaadin toggle in its own right.
SJToggleButton bold = new SJToggleButton("Bold");
bold.addItemListener(e -> font.bold = e.getStateChange() == ItemEvent.SELECTED);
// browser click -> Button ClickEvent -> ToggleButtonModel pulse ->
// Item + Change + Action, and aria-pressed flips.
Button peer vs. the Checkbox-family toggles
SJCheckBox / SJRadioButton peer over HasValue<Boolean>
widgets (Checkbox / radio) and render a glyph; this one peers over
Button, which is not HasValue. That single
difference drives every divergence from those siblings:
- Browser wire is
ClickNotifier, notValueChange. A Button emitsClickEvent; there is no boolean value to listen on. So the mixin's defaultClickNotifierwire fits —installButtonBindings()only swaps the default model forJToggleButton.ToggleButtonModelso press→release-while-armed togglesselectedand fires Item + Change + Action. - Selection shows as an
aria-pressedattribute + CSS, not a checked box. ThesetModel(ButtonModel)push wire mirrorsmodel.isSelected()onto thearia-pressedhost attribute;emul/sjtogglebutton.csspaints the depressed look off it. No feedback-loop guard is needed (unlike the Checkbox siblings'preventPeerEvents) because writing an attribute doesn't echo back as aClickEvent. - Layout + icon bind for real, inherited straight from
AbstractButtonMixin: Button's host isdisplay: inline-flexper Lumo, so alignment / text-position / iconTextGap write host CSS and read back, andsetIconhits the mixin's Vaadin-first Button branch. The Checkbox siblings drop-and-WARN these (shadow DOM won't honor host flex, no icon slot) — this surrogate doesn't. setTextroutes through Button'sHasText(SJButton shape) — Button is texted, not labelled.
ButtonGroup mutex lives at the emulator layer (D_buttongroup_browser_click)
The surrogate carries noButtonGroup awareness — standalone, a
click toggles on/off via the ToggleButtonModel pulse. Stage-3 group
mutex uses :emulators.JToggleButton + vaadinx.swing.ButtonGroup
per D_buttongroup: the emulator hands this surrogate a model whose
setSelected consults the group (D_emulator_button_model).- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface AbstractButtonMixin
AbstractButtonMixin.ButtonActionPropertyChangeListenerNested 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.component.HasText
com.vaadin.flow.component.HasText.WhiteSpaceNested classes/interfaces inherited from interface JComponentMixin
JComponentMixin.ActionStandin -
Field Summary
Fields inherited from interface JComponentMixin
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW -
Constructor Summary
ConstructorsConstructorDescriptionSJToggleButton(String text) SJToggleButton(String text, boolean selected) SJToggleButton(String text, Icon icon) SJToggleButton(String text, Icon icon, boolean selected) SJToggleButton(Action action) SJToggleButton(Icon icon) SJToggleButton(Icon icon, boolean selected) -
Method Summary
Modifier and TypeMethodDescriptionDeliberate no-op — L&F key.voidOverride of the mixin's default: the sole change is installingJToggleButton.ToggleButtonModel(toggle-on-release) instead ofDefaultButtonModel(momentary).protected StringJDK JToggleButton's paramString is essentially empty (returns AbstractButton's).voidsetEnabled(boolean enabled) Java "classes beat interfaces" shadows the mixin chain's setEnabled (SD_auto_pce auto-PCE + model propagation) with VaadinHasEnabled's default.voidsetModel(ButtonModel newModel) Override ofAbstractButtonMixin.setModel(ButtonModel)to additionally install a model→peer pushItemListenerthat mirrorsmodel.isSelected()onto thearia-pressedhost attribute.voidAbstract — each concrete surrogate implements via super (its Vaadin parent's HasText.setText, e.g.Methods inherited from class com.vaadin.flow.component.button.Button
addBlurListener, addFocusListener, addFocusShortcut, bindEnabled, bindText, click, clickInClient, getIcon, getText, isAutofocus, isDisableOnClick, isIconAfterText, remove, setAutofocus, setDisableOnClick, setIcon, setIconAfterTextMethods 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 AbstractButtonMixin
actionPropertyChanged, addActionListener, addChangeListener, addItemListener, configurePropertiesFromAction, createActionPropertyChangeListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getVerticalAlignment, getVerticalTextPosition, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setVerticalAlignment, setVerticalTextPosition, synthesizePeerClick, updateUIMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods 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, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validateMethods inherited from interface ContainerMixin
addContainerListener, getContainerListeners, getLayout, paintComponents, printComponents, removeContainerListener, setLayoutMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy, setAriaLabelledByMethods 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.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.shared.HasSuffix
getSuffixComponent, setSuffixComponentMethods inherited from interface com.vaadin.flow.component.HasText
getWhiteSpace, setWhiteSpaceMethods 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 JComponentMixin
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, isDoubleBuffered, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintImmediately, paintImmediately, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, requestDefaultFocus, resetKeyboardActions, reshape, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDoubleBuffered, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction
-
Constructor Details
-
SJToggleButton
public SJToggleButton() -
SJToggleButton
-
SJToggleButton
-
SJToggleButton
-
SJToggleButton
-
SJToggleButton
-
SJToggleButton
-
SJToggleButton
-
-
Method Details
-
installButtonBindings
public void installButtonBindings()Override of the mixin's default: the sole change is installingJToggleButton.ToggleButtonModel(toggle-on-release) instead ofDefaultButtonModel(momentary). TheClickNotifierwire and inline-flex CSS seed are identical to the default — Button is aClickNotifierand honors host flex — so both are kept. Idempotent: a no-op oncemodelis installed.- Specified by:
installButtonBindingsin interfaceAbstractButtonMixin
-
setModel
Override ofAbstractButtonMixin.setModel(ButtonModel)to additionally install a model→peer pushItemListenerthat mirrorsmodel.isSelected()onto thearia-pressedhost attribute. Catches directmyModel.setSelected(...)mutations as well as mixin-routed ones. Tracks teardown inpeerSyncRegistrationso a subsequentsetModelswap detaches cleanly.- Specified by:
setModelin interfaceAbstractButtonMixin
-
setText
Description copied from interface:AbstractButtonMixinAbstract — each concrete surrogate implements via super (its Vaadin parent's HasText.setText, e.g. Button.setText → textSupport) plus the"text"PCE fire. Pulled out of the mixin's default surface for the same reason asAbstractButtonMixin.getText().- Specified by:
setTextin interfaceAbstractButtonMixin- Specified by:
setTextin interfacecom.vaadin.flow.component.HasText- Overrides:
setTextin classcom.vaadin.flow.component.button.Button
-
setEnabled
public void setEnabled(boolean enabled) Java "classes beat interfaces" shadows the mixin chain's setEnabled (SD_auto_pce auto-PCE + model propagation) with VaadinHasEnabled's default. Redirect explicitly so the mixin chain runs — matters because ToggleButtonModel'ssetPressedshort-circuits when disabled.- Specified by:
setEnabledin interfaceComponentMixin- Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled- Specified by:
setEnabledin interfaceJComponentMixin- Overrides:
setEnabledin classcom.vaadin.flow.component.button.Button
-
getUIClassID
Description copied from interface:JComponentMixinDeliberate no-op — L&F key.- Specified by:
getUIClassIDin interfaceAbstractButtonMixin- Specified by:
getUIClassIDin interfaceJComponentMixin
-
paramString
JDK JToggleButton's paramString is essentially empty (returns AbstractButton's). We skip the AbstractButton.paramString chain (Vaadin's Component.toString is the honest host-side equivalent) and report nothing extra. -
getAccessibleContext
-