Class Scrollbar

All Implemented Interfaces:
Adjustable, ImageObserver, MenuContainer, Serializable, Accessible

public class Scrollbar extends Component implements Adjustable, Accessible
Emulator for Scrollbar — the AWT 1.0 scrollbar, not JScrollBar. Holds the JDK's value model itself, so every getter answers on any thread without reaching the SScrollbar peer, which renders it. The fan-out lives here too: the peer cannot hold the Adjustable identity that AdjustmentEvent demands of its source.
Scrollbar zoom = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 255);
zoom.addAdjustmentListener(e -> setZoom(e.getValue()));
zoom.setValue(128);            // silent: no AdjustmentEvent, as in AWT

It is a value control, and it renders as a slider

AWT's scroll pane does not use this class — ScrollPane hands out ScrollPaneAdjustable, a different final class — so a Scrollbar exists only because migrated code constructed one. AWT 1.0 had no slider, so that code is overwhelmingly using it as a zoom / volume / colour knob, which is why the peer is a range slider rather than the inert Div vaadinx.swing.JScrollBar peers on (D_viewport_scrollbar_shadows's "it is chrome the scroll container renders for us" is true in Swing and false here). The visual cost — no end arrows, and a thumb whose length cannot carry visibleAmount — is R_match_swing_errors sub-bucket (c); see SScrollbar.

Only the browser posts events

setValue and setValues fire nothing: their javadoc says so outright, and the JDK source fires only an accessibility PCE. That inverts JScrollBar, whose BoundedRangeModel fires on every write, and it means no preventPeerEvents flag is needed here — a server-side push is precisely the case AWT stays silent for, so the bridge gates on isFromClient() instead (the SCheckbox precedent).

A browser gesture reaches the model through the public methods, as a platform peer's does: a drag step calls setValueIsAdjusting(boolean) and setValue(int) before the event posts, so a migrator's setValue override sees the user's traffic too. Every browser-sourced event reports AdjustmentEvent.TRACK: nothing distinguishes an end-arrow click from a track click from a keypress server-side, and a wrong adjustment type is worse than a consistently honest one.

Leaf lock-down (R_leaf_peer_lockdown)

Nothing in java.awt extends Scrollbar (javax.swing.JScrollBar descends from JComponent; ScrollPaneAdjustable is final and merely implements Adjustable), so there is no protected (Component peer) ctor and every instance peers over an SScrollbar. Both orientations ride one peer type, so no D_frame_strategy-style peer dispatch is needed either.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • addNotify

      public void addNotify()
      Overrides:
      addNotify in class Component
    • getOrientation

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

      public void setOrientation(int orientation)
      Parameters:
      orientation - an unchanged value returns early before the legality check, as in AWT, so an illegal int equal to the current orientation cannot be reached
      Throws:
      IllegalArgumentException - "illegal scrollbar orientation"
    • getValue

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

      public void setValue(int value)
      Routes through setValues(int, int, int, int) rather than writing the peer directly — setValues is the JDK's single funnel and the natural override point for a migrator tightening clamping, so a direct write here would leave that override never running (R_no_vaadin_in_api limb 2).
      Specified by:
      setValue in interface Adjustable
      Parameters:
      value - clamped into [minimum, maximum - visibleAmount]; fires no AdjustmentEvent
    • getMinimum

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

      public void setMinimum(int minimum)
      Specified by:
      setMinimum in interface Adjustable
      Parameters:
      minimum - see setValue(int) on the setValues funnel
    • getMaximum

      public int getMaximum()
      Specified by:
      getMaximum in interface Adjustable
    • setMaximum

      public void setMaximum(int maximum)
      The rewritten minimum is stored straight into the field, as the JDK does, so it holds even when an overriding setValues(int, int, int, int) does not call super.
      Specified by:
      setMaximum in interface Adjustable
      Parameters:
      maximum - Integer.MIN_VALUE is nudged up by one, and a minimum that would meet or pass the new maximum is rewritten before the funnel runs — both are AWT's own pre-steps, outside setValues
    • getVisibleAmount

      public int getVisibleAmount()
      Specified by:
      getVisibleAmount in interface Adjustable
    • setVisibleAmount

      public void setVisibleAmount(int visible)
      Specified by:
      setVisibleAmount in interface Adjustable
      Parameters:
      visible - see setValue(int) on the setValues funnel
    • setValues

      public void setValues(int value, int visible, int minimum, int maximum)
      The single clamping funnel every value mutator routes through — and the override point AWT subclasses use to tighten clamping, so it must stay the only path to the peer.

      Never throws: every int, Integer.MIN_VALUE and Integer.MAX_VALUE included, is clamped. Fires no AdjustmentEvent.

    • getUnitIncrement

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

      public void setUnitIncrement(int v)
      Specified by:
      setUnitIncrement in interface Adjustable
      Parameters:
      v - clamped up to 1, as AWT does. Stored but inert: the only browser lever is the peer's step, which would quantize the whole value space rather than just the arrow delta (R_match_swing_errors sub-bucket (c); rationale in SScrollbar)
    • getBlockIncrement

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

      public void setBlockIncrement(int v)
      Specified by:
      setBlockIncrement in interface Adjustable
      Parameters:
      v - clamped up to 1, as AWT does. Stored but inert — PageUp / PageDown on <input type=range> move by a browser-chosen amount that is not settable (R_match_swing_errors sub-bucket (c))
    • getVisible

      @Deprecated public int getVisible()
      Deprecated.
      as of JDK 1.1, replaced by getVisibleAmount()
    • setLineIncrement

      @Deprecated public void setLineIncrement(int v)
      Deprecated.
      as of JDK 1.1, replaced by setUnitIncrement(int)
    • getLineIncrement

      @Deprecated public int getLineIncrement()
      Deprecated.
      as of JDK 1.1, replaced by getUnitIncrement()
    • setPageIncrement

      @Deprecated public void setPageIncrement(int v)
      Deprecated.
      as of JDK 1.1, replaced by setBlockIncrement(int)
    • getPageIncrement

      @Deprecated public int getPageIncrement()
      Deprecated.
      as of JDK 1.1, replaced by getBlockIncrement()
    • getValueIsAdjusting

      public boolean getValueIsAdjusting()
      Returns:
      true while a browser drag is in flight, or after a setValueIsAdjusting(true)
    • setValueIsAdjusting

      public void setValueIsAdjusting(boolean b)
      Parameters:
      b - advisory on the peer — the browser overwrites its flag on the next gesture (R_match_swing_errors sub-bucket (c)), and the drag writes this one back through here
    • addAdjustmentListener

      public void addAdjustmentListener(AdjustmentListener l)
      Specified by:
      addAdjustmentListener in interface Adjustable
      Parameters:
      l - null is a documented no-op, not an NPE
    • removeAdjustmentListener

      public void removeAdjustmentListener(AdjustmentListener l)
      Specified by:
      removeAdjustmentListener in interface Adjustable
      Parameters:
      l - null is a documented no-op
    • getAdjustmentListeners

      public AdjustmentListener[] getAdjustmentListeners()
    • processEvent

      protected void processEvent(AWTEvent e)
      Overrides:
      processEvent in class Component
    • processAdjustmentEvent

      protected void processAdjustmentEvent(AdjustmentEvent e)
      The single funnel every adjustment reaches the listeners through — both the peer bridge and a user-code processEvent call. AWT subclasses override this (calling super) to intercept adjustments wholesale, so it must stay the only dispatch path.
      Parameters:
      e - null is a no-op; the JDK calls the behaviour "unspecified" there, and D_awt_button settled that as no-op rather than NPE
    • paramString

      protected String paramString()
      Overrides:
      paramString in class Component
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()
      Specified by:
      getAccessibleContext in interface Accessible
      Overrides:
      getAccessibleContext in class Component