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:
6— normal text colour.7— selected/highlighted colour.
org.viktor44.jtvision.views.JtvScroller
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvScroller(JtvRect bounds, JtvScrollBar aHScrollBar, JtvScrollBar aVScrollBar) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| protected | delta | org.viktor44.jtvision.core.JtvPoint |
| protected | limit | org.viktor44.jtvision.core.JtvPoint |
| protected | hScrollBar | org.viktor44.jtvision.views.JtvScrollBar |
| protected | vScrollBar | org.viktor44.jtvision.views.JtvScrollBar |
| protected | drawLock | int |
| protected | drawFlag | boolean |
| private static final | cpScroller | org.viktor44.jtvision.core.JtvPalette |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public | changeBounds(JtvRect bounds) | void |
| public | checkDraw() | void |
| public | getPalette() | org.viktor44.jtvision.core.JtvPalette |
| public | handleEvent(JtvEvent event) | void |
| public | scrollDraw() | void |
| public | scrollTo(int x, int y) | void |
| public | setLimit(int x, int y) | void |
| public | showSBar(JtvScrollBar sBar) | void |
| public | setState(int aState, boolean enable) | void |
| public | getDelta() | org.viktor44.jtvision.core.JtvPoint |
| public | setDelta(JtvPoint delta) | void |
| public | getLimit() | org.viktor44.jtvision.core.JtvPoint |
| public | setLimit(JtvPoint limit) | void |
| public | getDrawLock() | int |
| public | setDrawLock(int drawLock) | void |
| public | isDrawFlag() | boolean |
| public | setDrawFlag(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 rectangleaHScrollBar- the horizontal scroll bar, ornullaVScrollBar- the vertical scroll bar, ornull
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:
6— normal text.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 positiony- 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 columnsy- 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;nullis 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 modifyenable-trueto set;falseto 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