Changeset 13965 in josm for trunk


Ignore:
Timestamp:
2018-06-22T20:19:02+02:00 (12 months ago)
Author:
Don-vip
Message:

cache contextual popup menu icons to improve performance when filtering plugin preferences panel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/TextContextualPopupMenu.java

    r13647 r13965  
    88import java.awt.event.KeyEvent;
    99import java.beans.PropertyChangeListener;
     10import java.util.HashMap;
     11import java.util.Map;
    1012
    1113import javax.swing.AbstractAction;
     
    4446    private static final String EDITABLE = "editable";
    4547
     48    private static final Map<String, ImageIcon> iconCache = new HashMap<>();
     49
     50    private static ImageIcon loadIcon(String iconName) {
     51        return iconCache.computeIfAbsent(iconName,
     52                x -> new ImageProvider(iconName).setOptional(true).setSize(ImageProvider.ImageSizes.SMALLICON).get());
     53    }
     54
    4655    protected JTextComponent component;
    4756    protected boolean undoRedo;
     
    173182            mi.setText(label);
    174183            if (iconName != null && Config.getPref().getBoolean("text.popupmenu.useicons", true)) {
    175                 ImageIcon icon = new ImageProvider(iconName).setOptional(true).setSize(ImageProvider.ImageSizes.SMALLICON).get();
     184                ImageIcon icon = loadIcon(iconName);
    176185                if (icon != null) {
    177186                    mi.setIcon(icon);
Note: See TracChangeset for help on using the changeset viewer.