I want to create some description of menu bars (items and connected with them actions-object or handler’s-methods) with some abstraction from gui library. In what way I can do it?
some draft
data structure (without access methods and other stuff):
public class MenuInfoHolder {
List<Column> menu;
public static class Column {
SimpleItem title;
List<Block> blocks;
}
public static class SimpleItem{
String title;
char key;
}
public static class Block{
List<SimpleItem> items;
}
public static abstract class ActionProducedItem extends SimpleItem {
abstract void invokeActionHandler(ActionHandler handler);
}
}
and here might be some using, like
Menu menu = new Menu();
ActionProducedItem item = new ActionProducedItem("Aaaa", 'a'){
@Override
void invokeActionHandler(ActionHandler handler) {
handler.foo();
}
};
Block block = new Block();
block.add(item);
Column column = new Column("BBB", 'B');
column.add(block);
menu.add(column);
Does exist any other better implementation (probably with Builder pattern or spring framework)?
UPD:
another worlds,
using SWT, smt like:
final Menu popupMenu = new Menu(shell, SWT.BAR);
MenuItem menuItem = new MenuItem(popupMenu, SWT.CASCADE);
menuItem.setText("More options");
Menu subMenu = new Menu(menuItem);
menuItem.setMenu(subMenu);
...
shell.setMenuBar(menu);
using Swing, smt like:
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu fileMenu = new JMenu("File");
JMenu editMenu = new JMenu("Edit");
menuBar.add(fileMenu);
But in both case we operate with same data. So I want make some abstraction about this.
Thanks.
How to Use Actions is all that comes to mind.