Menus and trees
This might be a silly question--but has anyone looked into creating a
(type of) TreeModel for menus? I saw someone starting to blog about
this, and had never thought of it before, myself. In an app I'm
working on I need to have different panels control whether main menu
options are enabled or not, and seems like having a backing model for
the menus would be a cleaner way to do it (cleaner than the weird
solution I have in place).
The model's main purpose would be to organize the menu hierarchy, not
necessarily to make it dynamically changeable. TreeModel and its
implementations is thus maybe a little heavyweight for this purpose,
but if we had something like a DefaultMutableTreeNode, which had as a
user object an Action, you could define the menubar, associate the
model, and menu items would have their actions already bound.
What I've found in the past is that the lack of a common way to
identify and associate with menu items between different visual
components is a drawback, I usually add some public methods on the
frame that allow features triggered by menus to be turned on or off.
Right now I do that through actions, the active panel declares the
actions it has available, mapped to constants declared in the frame.
The constants are bound to menu items, so when a panel becomes active
(think panel=tab in this case), its actions are bound to the
menuitems, so items can be enabled and disabled by the panel itself.
Kind of wacky, I know.