Class SJProgressBar

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.progressbar.ProgressBar
com.vaadin.swingbridge.surrogates.SJProgressBar
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.progressbar.ProgressBarVariant>, ComponentMixin, ContainerMixin, JComponentMixin, Serializable

public class SJProgressBar extends com.vaadin.flow.component.progressbar.ProgressBar implements JComponentMixin
Surrogate for JProgressBar. Extends Vaadin ProgressBar directly (is-a) so it reaches the migrator either through the :emulators JProgressBar as peer, or as a richer-than-stock Vaadin component in its own right.

Model flow (SJSlider precedent)

The installed BoundedRangeModel is the source of truth. A single ChangeListener on the model fans out to user ChangeListeners and pushes value changes to the peer (this ProgressBar's own element). Unlike SJSlider, Vaadin ProgressBar is display-only — the browser can't drag a progress bar back, so there is no peer-originated value-change to mirror, no R_callswing_envelope SHelper.callSwing wrapping, and no preventPeerEvents feedback-loop guard (the loop it defends against can't physically happen).

VERTICAL: drop-and-WARN (R_vaadin_first)

VERTICAL is field-stored and the PCE fires, but the visual stays horizontal. CSS transform: rotate(-90deg) was tried first (SJSlider precedent) and rejected: a transform only rotates the element's visual; its layout box keeps its pre-rotation dimensions, so dropping a rotated ProgressBar into any non-fixed-size container (BorderLayout.WEST, BoxLayout column, …) collapses it to zero width because Vaadin ProgressBar has no intrinsic width — it relies on its parent to stretch it. Making VERTICAL truly work needs either a wrapper element with explicitly-sized rotated dimensions (incompatible with surrogate is-a-ProgressBar — user code calls Component.getElement() and expects the bar itself) or a shadow-DOM-aware rewrite of Vaadin's internal width: calc(progress * 100%) fill machinery. Neither is JLawyer-needed; revisit if a migration target surfaces a real VERTICAL JProgressBar.

setString / setStringPainted via CSS overlay

Vaadin <vaadin-progress-bar> has no per-bar text slot. We render the user-set string (or the JDK percent default) through a ::after pseudo-element reading a data-emul-progress-string attribute on the host. The CSS rule is injected once per UI via ensureProgressStringStyleInjected(UI); SJProgressBar just toggles the attribute. Centered text crossing the fill boundary may have low contrast on the filled half — accepted R_layouts_close_enough close-enough, refined if a real-app migration target complains.

Threading

UI-thread-confined, with one exception: the installed BoundedRangeModel may be mutated from any thread. A worker reporting progress hops onto this bar's UI thread for each model change and blocks until the fan-out has run, so the peer write and every ChangeListener run on the UI thread; while the bar is detached, inline on the worker (SD_background_model_hop):
SJProgressBar bar = new SJProgressBar(0, files.size());
layout.add(bar);
executor.submit(() -> {
    for (int i = 0; i < files.size(); i++) {
        importFile(files.get(i));
        bar.getModel().setValue(i + 1);
    }
});
See Also:
  • Constructor Details

    • SJProgressBar

      public SJProgressBar()
    • SJProgressBar

      public SJProgressBar(int orientation)
    • SJProgressBar

      public SJProgressBar(int min, int max)
    • SJProgressBar

      public SJProgressBar(int orientation, int min, int max)
    • SJProgressBar

      public SJProgressBar(BoundedRangeModel brm)
  • Method Details

    • setValue

      public void setValue(int n)
    • getMinimum

      public int getMinimum()
    • setMinimum

      public void setMinimum(int minimum)
      Fires no "minimum" property change: the JDK's JProgressBar.setMinimum is getModel().setMinimum(n) and the notification is the model's ChangeEvent (SD_property_fanout_audit). Contrast JSlider, whose own setMinimum does fire.
    • getMaximum

      public int getMaximum()
    • setMaximum

      public void setMaximum(int maximum)
      Fires no "maximum" property change — see setMinimum(int) (SD_property_fanout_audit).
    • getModel

      public BoundedRangeModel getModel()
    • setModel

      public void setModel(BoundedRangeModel newModel)
      Fires no "model" property change. JProgressBar is the exception in its family: AbstractButton, JSlider, JTable, JList, JTree, JComboBox and JSpinner all fire "model", but JProgressBar.setModel fires only AccessibleContext.ACCESSIBLE_VALUE_PROPERTY — on the accessible context's own listener list, which addPropertyChangeListener here never reaches (SD_property_fanout_audit).
    • getPercentComplete

      public double getPercentComplete()
      Fraction in [0.0, 1.0] indicating model progress. A span of zero (max == min) reads as zero, so the overlay shows 0%; the JDK answers NaN there.
    • setIndeterminate

      public void setIndeterminate(boolean indeterminate)
      Overrides:
      setIndeterminate in class com.vaadin.flow.component.progressbar.ProgressBar
    • getOrientation

      public int getOrientation()
    • setOrientation

      public void setOrientation(int orientation)
    • isStringPainted

      public boolean isStringPainted()
    • setStringPainted

      public void setStringPainted(boolean b)
    • getString

      public String getString()
      The string to render when isStringPainted() is true. Defaults to the JDK percent format ("33%") when no string is set — mirrors JProgressBar.getString which composes the locale-aware percent via NumberFormat.getPercentInstance().
    • setString

      public void setString(String s)
    • isBorderPainted

      public boolean isBorderPainted()
    • setBorderPainted

      public void setBorderPainted(boolean b)
    • addChangeListener

      public void addChangeListener(ChangeListener l)
    • removeChangeListener

      public void removeChangeListener(ChangeListener l)
    • getChangeListeners

      public ChangeListener[] getChangeListeners()
    • fireStateChanged

      protected void fireStateChanged()
    • createChangeListener

      protected ChangeListener createChangeListener()
      JDK hook for subclasses that want to swap the model-attached listener. Mirrors SJSlider's same-named hook — modelListener is created directly in installModel; an override wouldn't reach our code path today, but a migrated subclass calling super.createChangeListener() gets the real listener.
    • getUIClassID

      public String getUIClassID()
      JDK JProgressBar returns "ProgressBarUI". We don't drive a pluggable ComponentUI (R_layouts_close_enough — Vaadin owns the DOM), but keep the ID so migrated code that introspects via BeanInfo still finds the expected value.
      Specified by:
      getUIClassID in interface JComponentMixin