Changeset 16409 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2020-05-14T23:05:12+02:00 (5 years ago)
Author:
simon04
Message:

fix #19237 - Add more icons to text box context menu

resources/images/cut.svg taken from https://commons.wikimedia.org/wiki/File:Gnome-edit-cut.svg

Remove TextContextualPopupMenu#iconCache since ImageProvider uses caching as well.

File:
1 edited

Legend:

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

    r14977 r16409  
    88import java.awt.event.KeyEvent;
    99import java.beans.PropertyChangeListener;
    10 import java.util.HashMap;
    11 import java.util.Map;
    1210
    1311import javax.swing.AbstractAction;
     
    4644    private static final String EDITABLE = "editable";
    4745
    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(x).setOptional(true).setSize(ImageProvider.ImageSizes.SMALLICON).get());
    53     }
    54 
    5546    protected JTextComponent component;
    5647    protected boolean undoRedo;
     
    132123        if (component.isEditable()) {
    133124            if (undoRedo) {
    134                 add(new JMenuItem(undoAction));
    135                 add(new JMenuItem(redoAction));
     125                addMenuEntry(new JMenuItem(undoAction), "undo");
     126                addMenuEntry(new JMenuItem(redoAction), "redo");
    136127                addSeparator();
    137128            }
    138             addMenuEntry(component, tr("Cut"), DefaultEditorKit.cutAction, null);
     129            addMenuEntry(component, tr("Cut"), DefaultEditorKit.cutAction, "cut");
    139130        }
    140131        addMenuEntry(component, tr("Copy"), DefaultEditorKit.copyAction, "copy");
    141132        if (component.isEditable()) {
    142133            addMenuEntry(component, tr("Paste"), DefaultEditorKit.pasteAction, "paste");
    143             addMenuEntry(component, tr("Delete"), DefaultEditorKit.deleteNextCharAction, null);
     134            addMenuEntry(component, tr("Delete"), DefaultEditorKit.deleteNextCharAction, "dialogs/delete");
    144135        }
    145136        addSeparator();
    146         addMenuEntry(component, tr("Select All"), DefaultEditorKit.selectAllAction, null);
     137        addMenuEntry(component, tr("Select All"), DefaultEditorKit.selectAllAction, "dialogs/select");
    147138    }
    148139
     
    213204            JMenuItem mi = new JMenuItem(action);
    214205            mi.setText(label);
    215             if (iconName != null && Config.getPref().getBoolean("text.popupmenu.useicons", true)) {
    216                 ImageIcon icon = loadIcon(iconName);
    217                 if (icon != null) {
    218                     mi.setIcon(icon);
    219                 }
    220             }
    221             add(mi);
    222         }
     206            addMenuEntry(mi, iconName);
     207        }
     208    }
     209
     210    protected void addMenuEntry(JMenuItem mi, String iconName) {
     211        if (iconName != null && Config.getPref().getBoolean("text.popupmenu.useicons", true)) {
     212            ImageIcon icon = new ImageProvider(iconName).setSize(ImageProvider.ImageSizes.SMALLICON).get();
     213            mi.setIcon(icon);
     214        }
     215        add(mi);
    223216    }
    224217
     
    263256        public RedoAction() {
    264257            super(tr("Redo"));
     258            new ImageProvider("redo").getResource().attachImageIcon(this);
    265259            setEnabled(false);
    266260        }
Note: See TracChangeset for help on using the changeset viewer.