Class JtvMenuView
public class JtvMenuView
extends JtvView
Abstract base class for all menu view objects.
JtvMenuView provides the core event loop, keyboard navigation, mouse tracking, hot-key dispatch, and command-set update logic shared by JtvMenuBar (horizontal bar) and JtvMenuBox (drop-down or pop-up box). Direct instances of JtvMenuView are not useful; use one of the concrete subclasses instead.
Menu ownership chain
Menu views are nested via parentMenu: a JtvMenuBox opened from a bar entry knows its parent is the JtvMenuBar. Mouse and keyboard events propagate back up the chain so that moving the pointer between siblings or pressing Escape correctly closes child menus and returns focus to the parent.
Event loop — execute()
execute() runs a modal loop that processes mouse and keyboard
events until either a command item is selected or the menu is cancelled.
It is always called via org.viktor44.jtvision.views.JtvGroup.execView and must never be invoked
directly. The loop:
- Tracks the mouse to update current.
- Handles arrow-key navigation via trackKey(boolean).
- Opens submenus into a child JtvMenuBox via
execView. - Returns the selected command, or
0if cancelled.
Hot keys and shortcuts
handleEvent(JtvEvent) intercepts evKeyDown events before
the event loop and tries to match them against shortcut key codes stored
in the menu items (JtvMenuItem.keyCode). A match causes an
evCommand event to be posted without opening the menu visually.
Colour palette
The six-entry palette cpMenuView maps to:
2— normal text.3— disabled text.4— shortcut letter.5— selected shortcut.6— selected normal.7— selected disabled.
org.viktor44.jtvision.menus.JtvMenuView
Summary
Constructors
| Visibility | Signature |
|---|---|
| public | JtvMenuView(JtvRect bounds) |
| public | JtvMenuView(JtvRect bounds, JtvMenu menu) |
Fields
| Modifiers | Field name | Type |
|---|---|---|
| protected | menu | org.viktor44.jtvision.menus.JtvMenu |
| protected | parentMenu | org.viktor44.jtvision.menus.JtvMenuView |
| protected | current | org.viktor44.jtvision.menus.JtvMenuItem |
| private static final | cpMenuView | org.viktor44.jtvision.core.JtvPalette |
Methods
| Modifiers | Method signature | Return type |
|---|---|---|
| public | getPalette() | org.viktor44.jtvision.core.JtvPalette |
| public | getItemRect(JtvMenuItem item) | org.viktor44.jtvision.core.JtvRect |
| protected | tryCommandByShortcut(JtvEvent e) | boolean |
| protected | tryCommandByShortcutInMenu(JtvMenu searchMenu, int keyCode, JtvEvent sourceEvent) | boolean |
| public | execute() | int |
| protected | trackMouse(JtvEvent e, boolean active) | void |
| protected | trackKey(boolean findNext) | void |
| protected | nextItem() | void |
| protected | prevItem() | void |
| protected | mouseInOwner(JtvEvent e) | boolean |
| protected | mouseInMenus(JtvEvent e) | boolean |
| public | topMenu() | org.viktor44.jtvision.menus.JtvMenuView |
| protected | doASelect(JtvEvent event) | void |
| private | updateMenu(JtvMenu aMenu) | boolean |
| protected | firstItem(JtvMenu aMenu) | org.viktor44.jtvision.menus.JtvMenuItem |
| public | handleEvent(JtvEvent event) | void |
Constructors
JtvMenuView(JtvRect bounds)
Constructs a menu view with the given bounds and no menu assigned.
Adds evBroadcast to the event mask so the view receives
cmCommandSetChanged broadcasts.
Parameters
bounds- the bounding rectangle
JtvMenuView(JtvRect bounds, JtvMenu menu)
Constructs a menu view with the given bounds and an initial menu.
Adds evBroadcast to the event mask.
Parameters
bounds- the bounding rectanglemenu- theJtvMenuwhose items to display
Fields
org.viktor44.jtvision.menus.JtvMenu menu
The JtvMenu record whose items this view renders and processes.
null until assigned by a subclass constructor.
org.viktor44.jtvision.menus.JtvMenuView parentMenu
The parent menu view in the ownership chain, or null if this
is the top-level menu. Used to route mouse events and Escape-key
handling back to the owning bar or box.
org.viktor44.jtvision.menus.JtvMenuItem current
The currently highlighted (focused) menu item, or null if
no item is highlighted. Updated by mouse tracking and keyboard
navigation; saved to JtvMenu.defaultItem when the menu closes.
org.viktor44.jtvision.core.JtvPalette cpMenuView
Six-entry colour palette shared by all menu view descendants:
2— normal text.3— disabled text.4— shortcut letter.5— selected shortcut.6— selected normal.7— selected disabled.
Methods
getPalette()
Overrides:
getPalette() in org.viktor44.jtvision.views.JtvView
Returns the menu view's shared colour palette cpMenuView.
Returns
the six-entry palette
getItemRect(JtvMenuItem item)
Returns the bounding rectangle of item within this view.
The base implementation returns an empty rectangle. Concrete
subclasses (JtvMenuBar, JtvMenuBox) must override this
to support mouse hit-testing.
Parameters
item- the menu item whose position to compute
Returns
the rectangle occupied by the item in view-local coordinates
tryCommandByShortcut(JtvEvent e)
Searches menu (and recursively its submenus) for an item
whose JtvMenuItem.keyCode matches the key code in e.
If found and the item is enabled, posts an evCommand event
with the item's command and clears the key event.
Parameters
e- the key-down event to match
Returns
true if a shortcut was matched and consumed
tryCommandByShortcutInMenu(JtvMenu searchMenu, int keyCode, JtvEvent sourceEvent)
Recursively searches searchMenu for an item with the given
keyCode. Posts an evCommand if found and enabled.
Parameters
searchMenu- the menu to searchkeyCode- the scan code to matchsourceEvent- the original key-down event (cleared on match)
Returns
true if a match was found and the event consumed
execute()
Overrides:
execute() in org.viktor44.jtvision.views.JtvView
Runs the modal menu event loop.
Processes events until the user selects a command item (returns its
command code), presses Escape, or clicks outside all menus (returns
0). This method must only be called via
org.viktor44.jtvision.views.JtvGroup.execView.
The loop handles:
evMouseDown/Up/Move— track the pointer, auto-open submenus, and select the item on mouse-up.evKeyDown— Up/Down navigate within a box; Left/Right navigate across bar items; Enter selects; Escape exits; letter keys match hot-key characters.evCommand cmMenu— auto-opens the currently focused submenu.
Returns
the command code of the selected item, or 0 if
the menu was cancelled
trackMouse(JtvEvent e, boolean active)
Updates current to the item whose bounding rectangle
(from getItemRect(JtvMenuItem)) contains the mouse pointer
position reported in e.
Parameters
e- the mouse event providing the pointer positionactive- unused; reserved for subclass extensions
trackKey(boolean findNext)
Advances or retreats current by one non-separator item, wrapping around at the ends of the list.
Parameters
findNext-trueto move forward (Down/Right),falseto move backward (Up/Left)
nextItem()
Advances current to the next item in the list, wrapping
back to JtvMenu.items after the last item.
prevItem()
Retreats current by one position, wrapping to the last item when currently at the first item.
mouseInOwner(JtvEvent e)
Returns true if the mouse pointer reported in e is
within the bounding rectangle of the item currently highlighted in
parentMenu. Used to detect whether a mouse-up on the parent
bar should close the child box rather than selecting an item.
Parameters
e- the mouse event
Returns
true if the pointer is over the parent's current item
mouseInMenus(JtvEvent e)
Returns true if the mouse pointer is within any ancestor
menu view in the parentMenu chain. Used to route a click
that lands on a sibling menu entry back to the top-level handler.
Parameters
e- the mouse event
Returns
true if the pointer is inside an ancestor menu
topMenu()
Walks the parentMenu chain and returns the root (top-level) menu view, which is the one with no parent.
Returns
the top-most menu view in the chain
doASelect(JtvEvent event)
Executes this menu view as a modal sub-view via the owner group.
Posts event to signal activation, calls
org.viktor44.jtvision.views.JtvGroup.execView, and if a
non-zero command is returned and is enabled, posts an evCommand
event with that command. Clears the original event on return.
Parameters
event- the activating event (typicallyevMouseDownorevCommand cmMenu)
updateMenu(JtvMenu aMenu)
Walks the entire menu tree rooted at aMenu and refreshes the
JtvMenuItem.disabled flag on each command item by calling
JtvView.commandEnabled(int).
Parameters
aMenu- the menu to update recursively
Returns
true if any item's enabled state changed
firstItem(JtvMenu aMenu)
No method description provided
Parameters
aMenu
handleEvent(JtvEvent event)
Overrides:
handleEvent(JtvEvent event) in org.viktor44.jtvision.views.JtvView
Handles events for the menu view.
First tries shortcut keys via tryCommandByShortcut(JtvEvent). Then:
evMouseDown— activates the menu via doASelect.evCommand cmMenu— activates the menu.evBroadcast cmCommandSetChanged— refreshes disabled flags viaupdateMenuand redraws if changed.
Parameters
event- the incoming event