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:
- Normal item text.
- Selected item text.
- Shortcut key (normal state).
- Shortcut key (selected state).
- Disabled item text.
org.viktor44.jtvision.dialogs.JtvCluster
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvCluster(JtvRect bounds, String[] items) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| private static final | cpCluster | org.viktor44.jtvision.core.JtvPalette |
| protected | value | int |
| protected | sel | int |
| protected | strings | List<String> |
| protected | enableMask | long |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public | getDataTo(Object rec) | void |
| public | setDataFrom(Object rec) | void |
| public | drawBox(String icon, char marker) | void |
| public | drawMultiBox(String icon, String markers) | void |
| public | getPalette() | org.viktor44.jtvision.core.JtvPalette |
| public | getHelpCtx() | int |
| public | handleEvent(JtvEvent event) | void |
| public | moveSel(int count, int s) | void |
| public | mark(int item) | boolean |
| public | multiMark(int item) | int |
| public | movedTo(int item) | void |
| public | press(int item) | void |
| public | column(int item) | int |
| public | findSel(JtvPoint p) | int |
| public | row(int item) | int |
| public | buttonState(int item) | boolean |
| public | setButtonState(long mask, boolean enable) | void |
| public | setState(int aState, boolean enable) | void |
| public | getValue() | int |
| public | setValue(int value) | void |
Constructors
JtvCluster(JtvRect bounds, String[] items)
Creates a cluster with the given bounds and item labels.
Parameters
bounds- the bounding rectangleitems- the item label strings;nullentries are silently skipped
Fields
org.viktor44.jtvision.core.JtvPalette cpCluster
Five-entry colour palette:
0x10— normal item text.0x11— selected item text.0x12— shortcut key (normal state).0x12— shortcut key (selected state).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- anIntegercontaining 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 templatemarkers- 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 (biti= itemi)enable-trueto enable the masked items,falseto 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 changedenable-trueto set,falseto 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