Search in sources :

Example 1 with ImageWrapperResizableIcon

use of org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon in project freeplane by freeplane.

the class MenuBuilder method addMenuItem.

public void addMenuItem(final String relativeKey, final JMenuItem item, final String key, final int position) {
    // RIBBONS - to set the right icon size
    if (item.getIcon() != null && item.getIcon() instanceof ImageIcon) {
        ImageIcon ico = (ImageIcon) item.getIcon();
        ImageWrapperResizableIcon newIco = ImageWrapperResizableIcon.getIcon(ico.getImage(), new Dimension(ico.getIconWidth(), ico.getIconHeight()));
        newIco.setPreferredSize(new Dimension(16, 16));
        newIco.addAsynchronousLoadListener(new AsynchronousLoadListener() {

            public void completed(boolean success) {
                item.repaint();
            }
        });
        item.setIcon(newIco);
    }
    final Node element = (Node) addElement(relativeKey, item, key, position);
    if (null == getMenuBar(element)) {
        return;
    }
    AFreeplaneAction action = (item.getAction() instanceof AccelerateableAction ? ((AccelerateableAction) item.getAction()).getOriginalAction() : (AFreeplaneAction) item.getAction());
    actionNodeMap.put(action, element);
    // }
    if (action != null) {
        KeyStroke acceleratorKeyStroke = acceleratorManager.getAcceleratorKeyStroke(action);
        if (acceleratorKeyStroke != null) {
            acceleratorManager.setAccelerator(action, acceleratorKeyStroke);
            item.setAccelerator(acceleratorKeyStroke);
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyStroke(javax.swing.KeyStroke) ImageWrapperResizableIcon(org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon) Dimension(java.awt.Dimension) AsynchronousLoadListener(org.pushingpixels.flamingo.api.common.AsynchronousLoadListener)

Aggregations

Dimension (java.awt.Dimension)1 ImageIcon (javax.swing.ImageIcon)1 KeyStroke (javax.swing.KeyStroke)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 AsynchronousLoadListener (org.pushingpixels.flamingo.api.common.AsynchronousLoadListener)1 ImageWrapperResizableIcon (org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon)1