Skip to main content

Class JtvScroller

public class JtvScroller
extends JtvView

A scrollable view that provides a viewport onto a larger virtual surface.

JtvScroller extends JtvView to link two optional JtvScrollBar controls to a scrolling offset (delta) that subclasses use in their draw() method to determine which portion of a larger content area to render.

How scrolling works

When either scroll bar's value changes, the scroll bar broadcasts cmScrollBarChanged. JtvScroller receives this broadcast in handleEvent(JtvEvent) and calls scrollDraw(), which reads the new values from both scroll bars, updates delta, and redraws the view. Subclasses render the part of their content starting at delta.

Programmatic scrolling is done via scrollTo(int, int), which sets both scroll bar values and triggers a redraw through the same broadcast path. The virtual content size is reported via setLimit(int, int), which adjusts the scroll bar ranges to [0, limit - viewSize].

Draw locking

The drawLock counter defers redraws while multiple scroll bar parameters are being updated. When the counter drops to zero, checkDraw() triggers a deferred redraw if drawFlag was set.

Scroll bar visibility

Scroll bars are shown only when the scroller is both active (sfActive) and selected (sfSelected). The setState(int, boolean) override calls showSBar(JtvScrollBar) whenever either flag changes.

Default palette

The two-entry palette cpScroller maps to:

  1. 6 — normal text colour.
  2. 7 — selected/highlighted colour.

org.viktor44.jtvision.views.JtvScroller

Summary​

Constructors​

VisibilitySignature
publicJtvScroller(JtvRect bounds, JtvScrollBar aHScrollBar, JtvScrollBar aVScrollBar)

Fields​

ModifiersField nameType
protecteddeltaorg.viktor44.jtvision.core.JtvPoint
protectedlimitorg.viktor44.jtvision.core.JtvPoint
protectedhScrollBarorg.viktor44.jtvision.views.JtvScrollBar
protectedvScrollBarorg.viktor44.jtvision.views.JtvScrollBar
protecteddrawLockint
protecteddrawFlagboolean
private static finalcpScrollerorg.viktor44.jtvision.core.JtvPalette

Methods​

ModifiersMethod signatureReturn type
publicchangeBounds(JtvRect bounds)void
publiccheckDraw()void
publicgetPalette()org.viktor44.jtvision.core.JtvPalette
publichandleEvent(JtvEvent event)void
publicscrollDraw()void
publicscrollTo(int x, int y)void
publicsetLimit(int x, int y)void
publicshowSBar(JtvScrollBar sBar)void
publicsetState(int aState, boolean enable)void
publicgetDelta()org.viktor44.jtvision.core.JtvPoint
publicsetDelta(JtvPoint delta)void
publicgetLimit()org.viktor44.jtvision.core.JtvPoint
publicsetLimit(JtvPoint limit)void
publicgetDrawLock()int
publicsetDrawLock(int drawLock)void
publicisDrawFlag()boolean
publicsetDrawFlag(boolean drawFlag)void

Constructors​

JtvScroller(JtvRect bounds, JtvScrollBar aHScrollBar, JtvScrollBar aVScrollBar)​

Constructs a scroller with the given bounds and optional scroll bars.

Sets ofSelectable on options so the scroller can receive focus, and adds evBroadcast to the event mask so it receives cmScrollBarChanged broadcasts.

Parameters

  • bounds - the bounding rectangle
  • aHScrollBar - the horizontal scroll bar, or null
  • aVScrollBar - the vertical scroll bar, or null

Fields​

org.viktor44.jtvision.core.JtvPoint delta​

The current horizontal and vertical scroll offset. Subclasses add this to row/column indices when drawing their content.

org.viktor44.jtvision.core.JtvPoint limit​

The total virtual content size. Scroll bar ranges are computed from this field via setLimit(int, int): the scroll bar maximum is limit - viewSize.

org.viktor44.jtvision.views.JtvScrollBar hScrollBar​

The optional horizontal scroll bar. null if this scroller has no horizontal scrolling.

org.viktor44.jtvision.views.JtvScrollBar vScrollBar​

The optional vertical scroll bar. null if this scroller has no vertical scrolling.

int drawLock​

Deferred-redraw lock counter. Incremented by callers that update multiple scroll bar parameters in one logical operation; decremented by checkDraw() after the updates are complete.

boolean drawFlag​

Set to true when a redraw is pending but deferred because drawLock is non-zero. Cleared and actioned by checkDraw() when the lock reaches zero.

org.viktor44.jtvision.core.JtvPalette cpScroller​

Two-entry colour palette:

  1. 6 — normal text.
  2. 7 — highlighted text.

Methods​

changeBounds(JtvRect bounds)​

Overrides:

changeBounds(JtvRect bounds) in org.viktor44.jtvision.views.JtvView

Updates the bounding rectangle and refreshes the scroll bar ranges via setLimit(int, int) without triggering an immediate redraw (uses the draw lock). Clears drawFlag and redraws afterwards.

Parameters

  • bounds - the new bounding rectangle

checkDraw()​

Triggers a deferred redraw if the draw lock has reached zero and a redraw was requested (drawFlag is true).

getPalette()​

Overrides:

getPalette() in org.viktor44.jtvision.views.JtvView

Returns the default scroller colour palette cpScroller.

Returns

the scroller's colour palette

handleEvent(JtvEvent event)​

Overrides:

handleEvent(JtvEvent event) in org.viktor44.jtvision.views.JtvView

Handles cmScrollBarChanged broadcasts from the associated scroll bars by calling scrollDraw() to update delta and redraw the view.

Parameters

  • event - the incoming event

scrollDraw()​

Reads the current values from both scroll bars, updates delta, and redraws the view. If the draw lock is held, sets drawFlag to request a deferred redraw. Also adjusts the cursor position to track the scroll offset change.

scrollTo(int x, int y)​

Sets both scroll bars to the given (x, y) position. Uses the draw lock to defer the resulting redraws until both values are set, then calls checkDraw().

Parameters

  • x - the desired horizontal scroll position
  • y - the desired vertical scroll position

setLimit(int x, int y)​

Sets the virtual content size and adjusts the scroll bar ranges to [0, limit - viewSize], using the current view size as the page step and 1 is kept as the arrow step. Uses the draw lock to defer redraws until both bars are updated.

Parameters

  • x - the total virtual width in columns
  • y - the total virtual height in rows

showSBar(JtvScrollBar sBar)​

Shows or hides sBar based on whether this scroller is both active and selected. Called from setState(int, boolean) when either flag changes.

Parameters

  • sBar - the scroll bar to show or hide; null is ignored

setState(int aState, boolean enable)​

Overrides:

setState(int aState, boolean enable) in org.viktor44.jtvision.views.JtvView

Propagates state changes and updates scroll bar visibility when sfActive or sfSelected change.

Parameters

  • aState - the state bits to modify
  • enable - true to set; false to clear

getDelta()​

The current horizontal and vertical scroll offset. Subclasses add this to row/column indices when drawing their content.

setDelta(JtvPoint delta)​

The current horizontal and vertical scroll offset. Subclasses add this to row/column indices when drawing their content.

Parameters

  • delta

getLimit()​

The total virtual content size. Scroll bar ranges are computed from this field via setLimit(int, int): the scroll bar maximum is limit - viewSize.

setLimit(JtvPoint limit)​

The total virtual content size. Scroll bar ranges are computed from this field via setLimit(int, int): the scroll bar maximum is limit - viewSize.

Parameters

  • limit

getDrawLock()​

Deferred-redraw lock counter. Incremented by callers that update multiple scroll bar parameters in one logical operation; decremented by checkDraw() after the updates are complete.

setDrawLock(int drawLock)​

Deferred-redraw lock counter. Incremented by callers that update multiple scroll bar parameters in one logical operation; decremented by checkDraw() after the updates are complete.

Parameters

  • drawLock

isDrawFlag()​

Set to true when a redraw is pending but deferred because drawLock is non-zero. Cleared and actioned by checkDraw() when the lock reaches zero.

setDrawFlag(boolean drawFlag)​

Set to true when a redraw is pending but deferred because drawLock is non-zero. Cleared and actioned by checkDraw() when the lock reaches zero.

Parameters

  • drawFlag