Ignore:
Timestamp:
2013-12-19T20:56:03+01:00 (6 years ago)
Author:
simon04
Message:

Add checkbox to main menu to toggle hatched background rendering of areas outside of the downloaded areas

This is useful, e.g, for mapping public transport relations when one
downloads a relation modify by id and missing stops by bbox.

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/PreferenceToggleAction.java

    r5927 r6499  
    77import org.openstreetmap.josm.data.Preferences;
    88import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     9import org.openstreetmap.josm.data.preferences.BooleanProperty;
     10import org.openstreetmap.josm.tools.CheckParameterUtil;
    911
    1012public class PreferenceToggleAction extends JosmAction implements PreferenceChangedListener {
    1113
    12     private final JCheckBoxMenuItem checkbox;
    13     private final String prefKey;
    14     private final boolean prefDefault;
     14    protected final JCheckBoxMenuItem checkbox;
     15    protected final BooleanProperty property;
    1516
    1617    public PreferenceToggleAction(String name, String tooltip, String prefKey, boolean prefDefault) {
     18        this(name, tooltip, new BooleanProperty(prefKey, prefDefault));
     19    }
     20
     21    public PreferenceToggleAction(String name, String tooltip, BooleanProperty property) {
    1722        super(name, null, tooltip, null, false);
    18         putValue("toolbar", "toggle-" + prefKey);
    19         this.prefKey = prefKey;
    20         this.prefDefault = prefDefault;
     23        CheckParameterUtil.ensureParameterNotNull(property, "property");
     24        putValue("toolbar", "toggle-" + property.getKey());
     25        this.property = property;
    2126        this.checkbox = new JCheckBoxMenuItem(this);
    22         this.checkbox.setSelected(Main.pref.getBoolean(prefKey, prefDefault));
     27        this.checkbox.setSelected(property.get());
    2328        Main.pref.addPreferenceChangeListener(this);
    2429    }
     
    2631    @Override
    2732    public void actionPerformed(ActionEvent e) {
    28         Main.pref.put(prefKey, checkbox.isSelected());
     33        property.put(checkbox.isSelected());
    2934    }
    3035
     
    3540    @Override
    3641    public void preferenceChanged(Preferences.PreferenceChangeEvent e) {
    37         if (prefKey.equals(e.getKey())) {
    38             checkbox.setSelected(Main.pref.getBoolean(prefKey, prefDefault));
     42        if (property.getKey().equals(e.getKey())) {
     43            checkbox.setSelected(property.get());
    3944        }
    4045    }
Note: See TracChangeset for help on using the changeset viewer.