Changeset 5088 in josm


Ignore:
Timestamp:
Mar 15, 2012 10:19:24 AM (14 months ago)
Author:
simon04
Message:

fix #6895 - improve MapPaintMenu (add "Preference", keep menu open after clicking checkbox) - thanks: http://tips4java.wordpress.com/2010/09/12/keeping-menus-open/

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 added
3 edited

Legend:

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

    r4593 r5088  
    1010import java.awt.event.ActionEvent; 
    1111import java.awt.event.ActionListener; 
    12 import java.awt.event.MouseWheelEvent; 
    13 import java.awt.event.MouseWheelListener; 
    14 import java.beans.PropertyChangeEvent; 
    15 import java.beans.PropertyChangeListener; 
    1612import javax.swing.Icon; 
    1713import javax.swing.JComponent; 
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r5030 r5088  
    362362     * Opens preferences window and selects the mappaint tab. 
    363363     */ 
    364     static class LaunchMapPaintPreferencesAction extends AbstractAction { 
     364    public static class LaunchMapPaintPreferencesAction extends AbstractAction { 
    365365        public LaunchMapPaintPreferencesAction() { 
    366366            putValue(NAME, tr("Preferences")); 
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r5086 r5088  
    55import java.awt.event.ActionEvent; 
    66import java.util.HashMap; 
    7 import java.util.HashSet; 
    87import java.util.Map; 
    9 import java.util.Set; 
    108import javax.swing.JCheckBoxMenuItem; 
    119import javax.swing.JMenu; 
    1210import org.openstreetmap.josm.Main; 
    1311import org.openstreetmap.josm.actions.JosmAction; 
     12import org.openstreetmap.josm.gui.dialogs.MapPaintDialog; 
     13import org.openstreetmap.josm.gui.dialogs.MapPaintDialog.LaunchMapPaintPreferencesAction; 
    1414import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 
     15import org.openstreetmap.josm.gui.util.StayOpenCheckBoxMenuItem; 
    1516import org.openstreetmap.josm.tools.ImageProvider; 
    1617 
     
    2930                Main.toolbar.register(this); 
    3031            } 
    31             this.button = new JCheckBoxMenuItem(this); 
     32            this.button = new StayOpenCheckBoxMenuItem(this); 
    3233            this.style = style; 
    3334            updateButton(); 
     
    5758        } 
    5859    } 
    59     private Map<String, MapPaintAction> actions = new HashMap<String, MapPaintAction>(); 
     60    private final Map<String, MapPaintAction> actions = new HashMap<String, MapPaintAction>(); 
     61    private final LaunchMapPaintPreferencesAction mapPaintPreferencesAction = new MapPaintDialog.LaunchMapPaintPreferencesAction() { 
     62 
     63        { 
     64            putValue("toolbar", "mappaintpreference"); 
     65        } 
     66    }; 
    6067 
    6168    public MapPaintMenu() { 
     
    6774    @Override 
    6875    public void mapPaintStylesUpdated() { 
    69         final Set<String> actionsToRemove = new HashSet<String>(actions.keySet()); 
     76        removeAll(); 
    7077        for (StyleSource style : MapPaintStyles.getStyles().getStyleSources()) { 
    7178            final String k = style.getDisplayString(); 
    7279            MapPaintAction a = actions.get(k); 
    7380            if (a == null) { 
    74                 a = new MapPaintAction(style); 
     81                actions.put(k, a = new MapPaintAction(style)); 
    7582                add(a.getButton()); 
    76                 actions.put(k, a); 
    7783            } else { 
     84                add(a.getButton()); 
    7885                a.updateButton(); 
    79                 actionsToRemove.remove(k); 
    8086            } 
    8187        } 
    82         for (String k : actionsToRemove) { 
    83             final MapPaintAction a = actions.get(k); 
    84             if (a != null) { 
    85                 remove(a.getButton()); 
    86                 actions.remove(k); 
    87             } 
    88         } 
     88        addSeparator(); 
     89        add(mapPaintPreferencesAction); 
    8990    } 
    9091 
Note: See TracChangeset for help on using the changeset viewer.