List of usage examples for com.jgoodies.common.swing MnemonicUtils configure
public static void configure(JLabel target, String markedText)
From source file:com.jnesto.platform.utils.ComponentFactory.java
License:Apache License
public static JMenuBar createJMenuBar(Collection<? extends Object> actions, JMenuBar mbar) { Objects.requireNonNull(actions); COMP_MAP.put(MENUBARTAG, mbar);//from www . ja v a2 s . com Predicate predicate = a -> ((a.getClass().isAnnotationPresent(ActionReferences.class) || a.getClass().isAnnotationPresent(ActionReference.class)) && (loadActionReferenceByTag(a.getClass(), MENUBARTAG) != null)); Comparator comparator = (a, b) -> { ActionReference arA = loadActionReferenceByTag(a.getClass(), MENUBARTAG); ActionReference arB = loadActionReferenceByTag(b.getClass(), MENUBARTAG); int r = arA.path().compareToIgnoreCase(arB.path()); return r == 0 ? Integer.compare(arA.position(), arB.position()) : r; }; Consumer consumer = a -> { ActionReference ar = loadActionReferenceByTag(a.getClass(), MENUBARTAG); if (ar != null) { Component comp = COMP_MAP.get(ar.path()); if (comp != null) { Component item = null; if (a instanceof JMenuItemAction) { item = new JMenuItem((JMenuItemAction) a); } else { if (a instanceof JCheckBoxAction) { item = new JCheckBoxMenuItem((JCheckBoxAction) a); JNestoTools.bindBuilder((JCheckBoxAction) a, SELECTED_TAG, (JCheckBoxMenuItem) item, SELECTED_TAG).bind(); } else { if (a instanceof JRadioButtonAction) { item = new JRadioButtonMenuItem((JRadioButtonAction) a); if (!BTNGROUP_MAP.containsKey(ar.path())) { BTNGROUP_MAP.put(ar.path(), new ButtonGroup()); } BTNGROUP_MAP.get(ar.path()).add((JRadioButtonMenuItem) item); JNestoTools.bindBuilder((JRadioButtonAction) a, SELECTED_TAG, (JRadioButtonMenuItem) item, SELECTED_TAG).bind(); } else { if (a instanceof JMenuAction) { item = new JMenu((JMenuAction) a); } else { if (a instanceof TopComponent && a instanceof Container && a.getClass().isAnnotationPresent(ServiceProvider.class)) { ServiceProvider sp = a.getClass().getAnnotation(ServiceProvider.class); AbstractAction aa = new DefaultDisplayAction(sp.id()); try { if (a.getClass().isAnnotationPresent(TopComponent.Description.class)) { TopComponent.Description description = a.getClass() .getAnnotation(TopComponent.Description.class); // aa.putValue(AbstractAction.NAME, description.title()); MnemonicUtils.configure(aa, description.title()); aa.putValue(AbstractAction.SMALL_ICON, new ImageIcon(ImageIO.read(ComponentFactory.class .getResourceAsStream(description.iconBase())))); Lookup.register(DefaultDisplayAction.class, aa); if (a.getClass().isAnnotationPresent(ActionReference.class)) { ActionReference aRef = a.getClass() .getAnnotation(ActionReference.class); Lookup.register(aRef.id(), aa); } } } catch (IOException ex) { } item = new JMenuItem(aa); } } } } } if (item != null) { if (comp instanceof JMenuItem) { if (ar.separatorBefore()) { ((JMenuItem) comp).add(new JSeparator()); } ((JMenuItem) comp).add(item); if (ar.separatorAfter()) { ((JMenuItem) comp).add(new JSeparator()); } } else { if (comp instanceof JMenuBar) { ((JMenuBar) comp).add(item); } } } COMP_MAP.put(ar.path() + PATHSEPARATOR + ar.id(), item); } } }; actions.stream().filter(predicate).sorted(comparator).forEach(consumer); BINDING_GROUP.bind(); return mbar; }