Class JtvGroup
public class JtvGroup
extends JtvView
A container view that owns and manages an ordered list of child views.
JtvGroup extends JtvView to hold a dynamically chained list of related views. It handles:
- Insertion and removal — insert(JtvView), remove(JtvView).
- Event routing — distributes events to children in three
phases:
phPreProcess,phFocused,phPostProcess. - Focus management — setCurrent(JtvView, int), resetCurrent(), selectNext(boolean).
- Modal execution — execute() runs an event loop; execView(JtvView) runs a child view modally.
- Double-buffered drawing — when the
ofBufferedoption is set (the default), the group draws all children into an off-screen JtvDrawBuffer and blits it to the screen in one pass. - Resize propagation — changeBounds(JtvRect) calls JtvView.calcBounds and JtvView.changeBounds on every child according to its grow-mode flags.
The child list is a circular singly-linked ring maintained through JtvView.next. last points to the back of the list (the view with the lowest z-order); first() returns the front (highest z-order). Views are inserted at the front by default.
Groups are created with ofSelectable | ofBuffered and an
eventMask of 0xFFFF so they receive all event types.
org.viktor44.jtvision.views.JtvGroup
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvGroup(JtvRect bounds) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| private static final | log | org.slf4j.Logger |
| private static | theTopView | org.viktor44.jtvision.views.JtvView |
| private | current | org.viktor44.jtvision.views.JtvView |
| protected | last | org.viktor44.jtvision.views.JtvView |
| protected | phase | int |
| protected | buffer | org.viktor44.jtvision.core.JtvDrawBuffer |
| protected | lockFlag | int |
| protected | endState | int |
| protected | clip | org.viktor44.jtvision.core.JtvRect |
Methods
Constructors
JtvGroup(JtvRect bounds)
Constructs a group with the given bounds.
Initialises options to ofSelectable | ofBuffered,
event mask to 0xFFFF (all events), phase to
JtvView.phFocused, and clip to the full extent.
Parameters
bounds- the initial bounding rectangle
Fields
org.slf4j.Logger log
No description provided
org.viktor44.jtvision.views.JtvView theTopView
The current top-level modal view, or null when no modal
view is active. Set and restored by JtvGroup.execView.
org.viktor44.jtvision.views.JtvView current
The currently focused (selected) child view, or null if no
child is selected. Set by setCurrent(JtvView, int).
org.viktor44.jtvision.views.JtvView last
The last (back-most) view in the circular linked-list of children,
or null when the group is empty. The front-most child is
last.next.
int phase
The current event-routing phase: JtvView.phFocused, JtvView.phPreProcess, or JtvView.phPostProcess.
org.viktor44.jtvision.core.JtvDrawBuffer buffer
The off-screen draw buffer used when ofBuffered is set.
Allocated lazily when the group is first drawn; freed when the
group is hidden (sfExposed is cleared).
int lockFlag
Lock counter used to defer drawView() calls while subviews are being moved or resized. The group is drawn once when this counter drops back to zero.
int endState
The command code that caused the current modal execute() loop to exit. Set by endModal(int).
org.viktor44.jtvision.core.JtvRect clip
The clipping rectangle used during drawing. Normally equals the group's extent, but is temporarily narrowed during occlusion-aware redraws.
Methods
awaken()
Overrides:
awaken() in org.viktor44.jtvision.views.JtvView
Calls JtvView.awaken() on every child view. Overrides the no-op in JtvView to propagate the awaken notification through the whole group hierarchy.
changeBounds(JtvRect bounds)
Overrides:
changeBounds(JtvRect bounds) in org.viktor44.jtvision.views.JtvView
Resizes the group to the new bounds and proportionally adjusts every child view according to its JtvView.growMode flags.
If the size does not change the group is simply redrawn. If the size changes, the group locks drawing, recalculates every child's bounds, then unlocks (triggering a single redraw).
Parameters
bounds- the new bounding rectangle
remove(JtvView p)
Removes a child view from this group without destroying it.
The view is temporarily hidden, unlinked, its JtvView.owner and JtvView.next are cleared, and then it is made visible again if it was visible before removal.
Parameters
p- the child view to remove, ornull(ignored)
draw()
Overrides:
draw() in org.viktor44.jtvision.views.JtvView
Draws the group by blitting its off-screen buffer (if available), or by re-drawing all child views within the current clip rectangle. If the buffer does not exist it is lazily allocated here.
drawSubViews(JtvView p, JtvView bottom)
Calls JtvView.drawView() on every child view from p
up to (but not including) bottom.
Parameters
p- the first child to draw (in list order)bottom- the child at which to stop, ornullto draw all
endModal(int command)
Overrides:
endModal(int command) in org.viktor44.jtvision.views.JtvView
Ends the modal state for this group if it is currently modal, or delegates to the parent via JtvView.endModal(int).
Parameters
command- the command code to return from#execute()
eventError(JtvEvent event)
Called when an event is not consumed by any child view. Delegates to the owner group, propagating unhandled events up the hierarchy.
Parameters
event- the unhandled event
execute()
Overrides:
execute() in org.viktor44.jtvision.views.JtvView
Runs the group's event loop until valid(int) returns
true for the exit command.
Each iteration fetches one event, routes it through
handleEvent(JtvEvent), and passes unhandled events to
eventError(JtvEvent). Runtime exceptions are wrapped into
cmError command events via handleRuntimeException.
Returns
the command that caused the loop to exit
handleException(Throwable ex)
Wraps an uncaught RuntimeException in a cmError
command event and delivers it to eventError(JtvEvent).
A second exception thrown from the error handler is silently swallowed.
Parameters
ex- the runtime exception to report
execView(JtvView p)
Runs a child view p as a modal subview of this group.
The method saves the current modal context (top-view, focused child,
command set), promotes p to modal, calls its
JtvView.execute() method, and then restores the saved context.
If p has no owner it is temporarily inserted into this group
and removed afterwards.
Parameters
p- the view to execute modally, ornull(returnscmCancelimmediately)
Returns
the command that ended the modal session
first()
Returns the first (front-most) child view in the group, or
null if the group is empty.
Returns
the first child view, or null
findNext(boolean forwards)
Finds the next focusable sibling after (or before) current
in the direction indicated by forwards.
A view is focusable if it is visible, not disabled, and has
ofSelectable set. Returns null if no other focusable
sibling exists.
Parameters
forwards-trueto search forward;falsebackward
Returns
the next focusable sibling, or null
focusNext(boolean forwards)
Focuses the next selectable sibling in the given direction by calling JtvView.focus() on the result of findNext(boolean).
Parameters
forwards-trueto move focus forward;falsebackward
Returns
true if focus was successfully transferred or no change
was needed
firstMatch(int state, int aOptions)
Returns the first child view that has all bits in aState set
and all bits in aOptions set. Iterates the list from
last backwards. Returns null if none matches.
Parameters
state- the state bits to requireaOptions- the option bits to require
Returns
the first matching view, or null
freeBuffer()
Releases the off-screen draw buffer if ofBuffered is set.
Called when the group is hidden so that memory is returned while the
group is not visible.
initBuffer()
Allocates the off-screen draw buffer if the group is exposed and
ofBuffered is set. The buffer is sized to hold the entire
group (width × height cells) and pre-filled with the
group's default background colour (palette entry 1) so that any
cells not painted by child views render with the background
instead of uninitialised (black) cells.
handleEvent(JtvEvent event)
Overrides:
handleEvent(JtvEvent event) in org.viktor44.jtvision.views.JtvView
Routes event through the three-phase delivery mechanism:
- JtvView.phPreProcess — views with
ofPreProcess. - JtvView.phFocused — the current focused view for keyboard/ command events, or the topmost view under the mouse for positional events.
- JtvView.phPostProcess — views with
ofPostProcess.
The base JtvView.handleEvent is called first to handle mouse-down focus transfers.
Parameters
event- the event to route
doHandleEvent(JtvView p, JtvEvent event)
Delivers event to a single child view, respecting phase and disable state.
Parameters
pevent
forEachHandleEvent(JtvEvent event)
Iterates all children from back to front, calling doHandleEvent on each.
Parameters
event
insert(JtvView p)
Inserts p into this group as the front-most child view.
If p has the ofCenterX or ofCenterY option
set, its origin is adjusted to centre it within the group.
Parameters
p- the view to insert; must not already have an owner
insertBefore(JtvView p, JtvView target)
Inserts p immediately before target in the z-order.
Parameters
ptarget
insertView(JtvView p, JtvView target)
Low-level insertion: links p into the circular list
immediately before target (or at the end if target
is null), and sets JtvView.owner to this group.
Parameters
p- the view to link intarget- the view to insert before, ornullto append
removeView(JtvView p)
Low-level removal: unlinks p from the circular list without
touching its owner or next pointers (those are cleared by
remove(JtvView)).
Parameters
p- the view to unlink
lock()
Increments the draw lock counter, deferring any drawView() calls until unlock() brings the counter back to zero. Has no effect if neither a buffer nor an existing lock is present.
unlock()
Decrements the draw lock counter. When it reaches zero, triggers a deferred drawView() to flush all buffered changes.
redraw()
Redraws all child views by calling drawSubViews from first() to the end of the list.
resetCurrent()
Selects the first visible, selectable child as the current focused view by calling setCurrent with JtvView.normalSelect.
resetCursor()
Overrides:
resetCursor() in org.viktor44.jtvision.views.JtvView
Delegates the cursor-reset to the currently focused child. If no child is focused the hardware cursor is not updated.
selectNext(boolean forwards)
Moves focus to the next selectable sibling in the given direction. Has no effect if no current view is focused.
Parameters
forwards-trueto move to the next sibling;falseto move to the previous sibling
selectView(JtvView p, boolean enable)
Sets or clears the sfSelected state on view p.
Parameters
p- the view to change, ornull(ignored)enable-trueto select;falseto deselect
focusView(JtvView p, boolean enable)
Sets or clears the sfFocused state on view p,
but only if this group itself is focused.
Parameters
p- the view to change, ornull(ignored)enable-trueto focus;falseto unfocus
setCurrent(JtvView p, int mode)
Changes the currently focused child to p using the selection
mode mode. Handles transferring sfSelected and
sfFocused state bits between the old and new current views.
Parameters
p- the new current view, ornullto clear selectionmode-JtvView#normalSelect,JtvView#enterSelect, orJtvView#leaveSelect
setDataFrom(Object rec)
Overrides:
setDataFrom(Object rec) in org.viktor44.jtvision.views.JtvView
No-op data-import override. Subclasses may override to distribute data records to child views.
Parameters
rec- the source data record
setState(int aState, boolean enable)
Overrides:
setState(int aState, boolean enable) in org.viktor44.jtvision.views.JtvView
Propagates state changes to all children and handles special cases:
sfActive/sfDragging— forwarded to all children.sfFocused— forwarded to the current child.sfExposed— forwarded to all visible children; clearing it also frees the draw buffer.
Parameters
aState- the state bits to modifyenable-trueto set;falseto clear
valid(int command)
Overrides:
valid(int command) in org.viktor44.jtvision.views.JtvView
Validates all child views for the given command. For
cmReleasedFocus only the current child (if it has
ofValidate) is checked; for all other commands every child
is validated.
Parameters
command- the command requesting validation
Returns
true if all applicable children return true
getHelpCtx()
Overrides:
getHelpCtx() in org.viktor44.jtvision.views.JtvView
Returns the effective help-context ID. Asks the current child first;
if it returns hcNoContext, falls back to the group's own
help context via the parent JtvView.getHelpCtx().
Returns
the current help-context ID
forEach(function.Consumer<org.viktor44.jtvision.views.JtvView> action)
Applies action to every child view exactly once,
iterating the circular list safely even if action modifies
the list.
Parameters
action- the consumer to invoke for each child view
firstThat(function.Predicate<org.viktor44.jtvision.views.JtvView> test)
Returns the first child view for which test returns
true, or null if none matches.
Parameters
test- the predicate to apply
Returns
the first matching child, or null
indexOf(JtvView p)
Returns the 1-based index of view p within the circular
list (starting at 1 for first()), or 0 if not found.
Parameters
p- the view whose index to find
Returns
the 1-based position, or 0 if not a child
at(int index)
Returns the child view at 1-based index in the circular list,
or null if the group is empty or the index is invalid.
Parameters
index- 1-based position (1 = first/front-most)
Returns
the view at that position, or null
writeClipped(JtvView target, int x1, int x2, int y, org.viktor44.jtvision.core.JtvScreenCell[] buf, int bufOffset, boolean inShadow)
Writes cells into the group's buffer or screen, skipping over any sibling views that occlude the target area and applying shadow colour transformations where needed.
Parameters
target- the child view that is writing (occlusion is checked only for children in front of it)x1- start column (group-local, inclusive)x2- end column (group-local, exclusive)y- row (group-local)buf- source cell arraybufOffset- starting index intobufinShadow-trueif this segment should be rendered as shadow
writeClippedAfter(JtvView after, JtvView target, int x1, int x2, int y, org.viktor44.jtvision.core.JtvScreenCell[] buf, int bufOffset, boolean inShadow)
Continuation of writeClipped starting after view after.
Parameters
aftertargetx1x2ybufbufOffsetinShadow
writeFinal(int x1, int x2, int y, org.viktor44.jtvision.core.JtvScreenCell[] buf, int bufOffset, boolean inShadow)
Writes cells to the off-screen buffer (if any) and/or the screen,
applying shadow colour transformation when inShadow is true.
When the draw lock is held, only the buffer is written (no screen
output). When the group has no owner, writes directly to the screen.
Parameters
x1- start column (inclusive)x2- end column (exclusive)y- rowbuf- source cell arraybufOffset- starting index intobufinShadow-trueto apply shadow colour transformation
getTheTopView()
The current top-level modal view, or null when no modal
view is active. Set and restored by JtvGroup.execView.
getCurrent()
The currently focused (selected) child view, or null if no
child is selected. Set by setCurrent(JtvView, int).