static JComponent createMenuComponent(JComponent menu, ActionMap actionMap, List actions) { MenuAdapter menuAdapter = new MenuAdapter(menu); for (Object menuElement : actions) { if (MenuFactory.SEPARATOR.equals(menuElement)) { menuAdapter.addSeparator(); } else if (menuElement instanceof Object[]) { Object[] items = (Object[]) menuElement; if (items.length > 1) { JMenu subMenu = new JMenu(items[0].toString()); List<Object> keys = Arrays.asList(items).subList(1, items.length); createMenuComponent(subMenu, actionMap, keys); if (subMenu.getMenuComponents().length > 0) { menuAdapter.addSubMenu(subMenu); } } } else if (menuElement instanceof List) { List items = (List) menuElement; if (items.size() > 1) { JMenu subMenu = new JMenu(items.get(0).toString()); List<List> keys = Arrays.asList(items).subList(1, items.size()); createMenuComponent(subMenu, actionMap, keys); if (subMenu.getMenuComponents().length > 0) { menuAdapter.addSubMenu(subMenu); } } } else { Action action = actionMap.get(menuElement); if (action != null) { menuAdapter.add(action); } } } return trim(menuAdapter); }
static JComponent createMenuComponent(JComponent menu, Collection items) { MenuAdapter menuAdapter = new MenuAdapter(menu); for (Iterator it = items.iterator(); it.hasNext(); ) { Object item = (Object) it.next(); if (item instanceof Action) { menuAdapter.add((Action) item); } else if (item instanceof Action[]) { Action[] actions = (Action[]) item; if (actions.length > 1) { String name = (String) actions[0].getValue(Action.NAME); JMenu subMenu = menuAdapter.addSubMenu(name); List<Action> keys = Arrays.asList(actions).subList(1, actions.length); createMenuComponent(subMenu, keys); } } else if (item instanceof JMenuItem) { menuAdapter.add((JMenuItem) item); } else if (item instanceof JSeparator) { menuAdapter.addSeparator(); } } return trim(menuAdapter); }