Class ScrollPaneAdjustable

java.lang.Object
vaadinx.awt.ScrollPaneAdjustable
All Implemented Interfaces:
Adjustable, Serializable

public final class ScrollPaneAdjustable extends Object implements Adjustable, Serializable
Emulator for ScrollPaneAdjustable — the value model behind one axis of a ScrollPane. Emulator-only: it is not a Component, has no DOM of its own, and Vaadin ships no scrollbar-object concept (the web component renders its scrollbars internally). D_viewport_scrollbar_shadows's "shadow JDK component" pattern — except that, unlike JScrollBar, this one is not inert: setValue(int) really does scroll the pane.
Adjustable v = pane.getVAdjustable();
v.addAdjustmentListener(e -> log(e.getValue()));
v.setValue(200);               // scrolls, and fires
v.setMaximum(500);             // AWTError, as in AWT

The range is not yours to set

setMinimum(int) / setMaximum(int) / setVisibleAmount(int) throw AWTError, verbatim as the JDK does — in AWT the span is derived by ScrollPane.layout() from the child's preferred size against the viewport, never set by user code. getMinimum() ignores its own field and hard-returns 0, also as the JDK does.

Programmatic scrolls fire; user scrolls do not

setValue fires an AdjustmentEvent on change, synchronously and inline, exactly as the JDK's setTypedValue does (the JDK comments that the synchronous delivery is deliberate, so listeners are up to date before the Adjustable mutates again). A user scroll fires nothing: the browser→server channel is descoped per D_awt_scrollpane, so no gesture reaches the server. A migrator syncing two panes, or paging on scroll, will find their listener silent — see the class javadoc of ScrollPane.

Deliberate divergence: no clamping

The JDK clamps to [minimum, maximum - visibleAmount]. Since the span is only ever written by setSpan — which only ScrollPane .layout() calls, and we never compute a pixel span (R_layouts_close_enough) — a faithful clamp would be min(max(v, 0), 0), i.e. every setValue would collapse to 0 and fire nothing, forever, killing setScrollPosition outright. So this port does not clamp: the value is stored verbatim, and the browser clamps it on arrival (verified synchronous). One consequence, named so it is not rediscovered as a bug: getValue() can exceed getMaximum() (200 against 0), which the JDK's clamp makes impossible. A migrator computing value / (double) maximum gets nonsense — but under a faithful port they would have got 0 / 0, so no working idiom is lost.
See Also:
  • Method Details

    • getOrientation

      public int getOrientation()
      Specified by:
      getOrientation in interface Adjustable
    • setMinimum

      public void setMinimum(int min)
      Specified by:
      setMinimum in interface Adjustable
      Throws:
      AWTError - always — the span belongs to the scroll pane
    • getMinimum

      public int getMinimum()
      Specified by:
      getMinimum in interface Adjustable
      Returns:
      always 0; the JDK ignores its own field here for the same reason
    • setMaximum

      public void setMaximum(int max)
      Specified by:
      setMaximum in interface Adjustable
      Throws:
      AWTError - always — the span belongs to the scroll pane
    • getMaximum

      public int getMaximum()
      Specified by:
      getMaximum in interface Adjustable
      Returns:
      always 0 — the JDK's field default, only ever overwritten by setSpan, which needs a laid-out pane we never produce. Not 1: that is setSpan's floor, reachable only after a layout, so 0 is what an un-laid-out JDK pane actually answers
    • setVisibleAmount

      public void setVisibleAmount(int v)
      Specified by:
      setVisibleAmount in interface Adjustable
      Throws:
      AWTError - always — the span belongs to the scroll pane
    • getVisibleAmount

      public int getVisibleAmount()
      Specified by:
      getVisibleAmount in interface Adjustable
      Returns:
      always 0, for the same reason as getMaximum()
    • setUnitIncrement

      public void setUnitIncrement(int u)
      Stores the arrow-key delta. Inert: the browser owns wheel and arrow-key scroll deltas and exposes no hook to override them (R_match_swing_errors sub-bucket (c)). The value round-trips so a migrator's own arithmetic over it still works.
      Specified by:
      setUnitIncrement in interface Adjustable
    • getUnitIncrement

      public int getUnitIncrement()
      Specified by:
      getUnitIncrement in interface Adjustable
    • setBlockIncrement

      public void setBlockIncrement(int b)
      Stores the page delta. Inert, as setUnitIncrement(int) is.

      Unlike the JDK, the stored value survives: AWT's setSpan silently overwrites blockIncrement with 0.9 * visible on every layout, and setSpan never runs here.

      Specified by:
      setBlockIncrement in interface Adjustable
    • getBlockIncrement

      public int getBlockIncrement()
      Specified by:
      getBlockIncrement in interface Adjustable
    • setValueIsAdjusting

      public void setValueIsAdjusting(boolean b)
      Fires an AdjustmentEvent on a genuine flip, as the JDK does. Only user code can flip it — the browser gives no scroll-drag start/end signal, and we are not listening for one anyway.
    • getValueIsAdjusting

      public boolean getValueIsAdjusting()
    • setValue

      public void setValue(int v)
      Scrolls this axis to v and pushes to the browser.

      No clamping — see the class javadoc. Fires only on a real change, matching the JDK, and fires before nothing: the JDK's setTypedValue notifies synchronously, and so do we.

      Specified by:
      setValue in interface Adjustable
    • getValue

      public int getValue()
      Specified by:
      getValue in interface Adjustable
    • addAdjustmentListener

      public void addAdjustmentListener(AdjustmentListener l)
      Null listener is a documented no-op, as in AWT.
      Specified by:
      addAdjustmentListener in interface Adjustable
    • removeAdjustmentListener

      public void removeAdjustmentListener(AdjustmentListener l)
      Null listener is a documented no-op, as in AWT.
      Specified by:
      removeAdjustmentListener in interface Adjustable
    • getAdjustmentListeners

      public AdjustmentListener[] getAdjustmentListeners()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • paramString

      public String paramString()
      Verbatim JDK format.