Skip to main content

Class JtvCluster

public class JtvCluster
extends JtvView

Abstract base class for clustered controls such as check boxes and radio buttons.

A cluster is a group of labelled controls that all respond in a similar way. The user can select items with mouse clicks, cursor movement (Up/Down), and Alt+letter hot-keys. Each item can be enabled or disabled independently via the enableMask field.

The current state of the cluster is held in the value field; the exact semantics of value are defined by concrete subclasses (JtvCheckBoxes toggles bits; JtvRadioButtons stores the index of the selected item).

When the bounding rectangle is wide enough, items wrap into multiple columns.

Colour palette

The five-entry palette cpCluster maps to:

  1. Normal item text.
  2. Selected item text.
  3. Shortcut key (normal state).
  4. Shortcut key (selected state).
  5. Disabled item text.

org.viktor44.jtvision.dialogs.JtvCluster

Summary​

Constructors​

VisibilitySignature
publicJtvCluster(JtvRect bounds, String[] items)

Fields​

ModifiersField nameType
private static finalcpClusterorg.viktor44.jtvision.core.JtvPalette
protectedvalueint
protectedselint
protectedstringsList<String>
protectedenableMasklong

Methods​

ModifiersMethod signatureReturn type
publicgetDataTo(Object rec)void
publicsetDataFrom(Object rec)void
publicdrawBox(String icon, char marker)void
publicdrawMultiBox(String icon, String markers)void
publicgetPalette()org.viktor44.jtvision.core.JtvPalette
publicgetHelpCtx()int
publichandleEvent(JtvEvent event)void
publicmoveSel(int count, int s)void
publicmark(int item)boolean
publicmultiMark(int item)int
publicmovedTo(int item)void
publicpress(int item)void
publiccolumn(int item)int
publicfindSel(JtvPoint p)int
publicrow(int item)int
publicbuttonState(int item)boolean
publicsetButtonState(long mask, boolean enable)void
publicsetState(int aState, boolean enable)void
publicgetValue()int
publicsetValue(int value)void

Constructors​

JtvCluster(JtvRect bounds, String[] items)​

Creates a cluster with the given bounds and item labels.

Parameters

  • bounds - the bounding rectangle
  • items - the item label strings; null entries are silently skipped

Fields​

org.viktor44.jtvision.core.JtvPalette cpCluster​

Five-entry colour palette:

  1. 0x10 — normal item text.
  2. 0x11 — selected item text.
  3. 0x12 — shortcut key (normal state).
  4. 0x12 — shortcut key (selected state).
  5. 0x1F — disabled item text.

int value​

The current value of the cluster. For JtvCheckBoxes each bit corresponds to a checked item. For JtvRadioButtons this is the zero-based index of the selected item.

int sel​

The index of the currently highlighted (cursor-over) item within the cluster.

List<String> strings​

Ordered list of item label strings (may contain tilde-delimited hot-key characters).

long enableMask​

Bitmask controlling which items are enabled. Bit i (0-based) enables item i; a cleared bit disables the item. Initialised to all-ones so all items start enabled.

Methods​

getDataTo(Object rec)​

Reads the cluster's current value into a record object. Callers should read the value field directly in this implementation.

Parameters

  • rec - the destination record (unused in base implementation)

setDataFrom(Object rec)​

Overrides:

setDataFrom(Object rec) in org.viktor44.jtvision.views.JtvView

Sets the cluster value from a record object and redraws the view.

Parameters

  • rec - an Integer containing the new #value

drawBox(String icon, char marker)​

Draws all items using a simple two-state (unmarked/marked) icon. Delegates to drawMultiBox(String, String) with a two-character marker string.

Parameters

  • icon - the icon template (e.g., " [ ] " or " ( ) ")
  • marker - the character placed inside the icon when an item is marked

drawMultiBox(String icon, String markers)​

Draws all cluster items in columns across the view. Each item is rendered with the supplied icon; the character from markers at the index returned by multiMark(int) is placed in the icon's slot.

Parameters

  • icon - the icon template
  • markers - string whose characters correspond to possible mark states

getPalette()​

Overrides:

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

Returns the default color palette cpCluster.

Returns

the cluster's color palette

getHelpCtx()​

Overrides:

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

Returns the help context for the currently highlighted item. If the base help context is hcNoContext it is returned unchanged; otherwise the item index is added to give per-item help.

Returns

the help context identifier

handleEvent(JtvEvent event)​

Overrides:

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

Handles mouse and keyboard events for the cluster.

Mouse clicks highlight and optionally press the item under the cursor. Up/Down arrow keys move the selection. Alt+letter hot-keys and Space (when focused) activate the corresponding item.

Parameters

  • event - the incoming event

moveSel(int count, int s)​

Moves the selection cursor to item s (if within range) and redraws.

Parameters

  • count - the number of steps taken; must be <= strings.size()
  • s - the target item index

mark(int item)​

Returns whether the given item is currently marked (checked/selected). The base implementation always returns false; subclasses override this.

Parameters

  • item - the zero-based item index

Returns

true if the item is marked

multiMark(int item)​

Returns the mark-state index used by drawMultiBox to select the display character from the markers string. Returns 1 if mark(int) is true, 0 otherwise.

Parameters

  • item - the zero-based item index

Returns

the index into the markers string

movedTo(int item)​

Called when the cursor moves to a new item without pressing it. The base implementation does nothing; subclasses (e.g., JtvRadioButtons) override this to update the value.

Parameters

  • item - the zero-based index of the item now under the cursor

press(int item)​

Called when the user presses the item at item. The base implementation does nothing; subclasses override this to change value.

Parameters

  • item - the zero-based index of the pressed item

column(int item)​

Returns the X-coordinate of the left edge of the column containing item. Items are laid out in rows of height size.y; this calculates the pixel column offset for the given item index.

Parameters

  • item - the zero-based item index

Returns

the column offset in character cells

findSel(JtvPoint p)​

Returns the item index at mouse position p, or -1 if the position is outside the cluster or does not correspond to a valid item.

Parameters

  • p - the mouse position in local coordinates

Returns

zero-based item index, or -1

row(int item)​

Returns the row (Y offset) of item item within the cluster view.

Parameters

  • item - the zero-based item index

Returns

the row index (0-based)

buttonState(int item)​

Returns whether item item is currently enabled. An item is enabled when its corresponding bit in enableMask is set. Items beyond index 31 are always considered disabled.

Parameters

  • item - the zero-based item index

Returns

true if the item is enabled

setButtonState(long mask, boolean enable)​

Enables or disables the items selected by aMask. Also updates org.viktor44.jtvision.core.ViewFlags.ofSelectable based on whether any items remain enabled.

Parameters

  • mask - bitmask of items to enable/disable (bit i = item i)
  • enable - true to enable the masked items, false to disable them

setState(int aState, boolean enable)​

Overrides:

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

Extends the inherited setState to redraw when the selected state changes.

Parameters

  • aState - the state flag(s) being changed
  • enable - true to set, false to clear

getValue()​

The current value of the cluster. For JtvCheckBoxes each bit corresponds to a checked item. For JtvRadioButtons this is the zero-based index of the selected item.

setValue(int value)​

The current value of the cluster. For JtvCheckBoxes each bit corresponds to a checked item. For JtvRadioButtons this is the zero-based index of the selected item.

Parameters

  • value