Changeset 6499 in josm for trunk/src


Ignore:
Timestamp:
2013-12-19T20:56:03+01:00 (11 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
Files:
1 added
3 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    }
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r6426 r6499  
    4747import org.openstreetmap.josm.actions.FullscreenToggleAction;
    4848import org.openstreetmap.josm.actions.GpxExportAction;
     49import org.openstreetmap.josm.actions.HatchAreaOutsideDownloadAction;
    4950import org.openstreetmap.josm.actions.HelpAction;
    5051import org.openstreetmap.josm.actions.HistoryInfoAction;
     
    199200    /** View -> Wireframe View */
    200201    public final WireframeToggleAction wireFrameToggleAction = new WireframeToggleAction();
     202    public final HatchAreaOutsideDownloadAction hatchAreaOutsideDownloadAction = new HatchAreaOutsideDownloadAction();
    201203    public final JosmAction toggleGPXLines = new ToggleGPXLinesAction();
    202204    /** View -> Advanced info */
     
    643645        wireframe.setAccelerator(wireFrameToggleAction.getShortcut().getKeyStroke());
    644646        wireFrameToggleAction.addButtonModel(wireframe.getModel());
     647        final JCheckBoxMenuItem hatchAreaOutsideDownloadMenuItem = hatchAreaOutsideDownloadAction.getCheckbox();
     648        viewMenu.add(hatchAreaOutsideDownloadMenuItem);
     649        ExpertToggleAction.addVisibilitySwitcher(hatchAreaOutsideDownloadMenuItem);
    645650
    646651        viewMenu.add(new MapPaintMenu());
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r6436 r6499  
    4141import org.openstreetmap.josm.Main;
    4242import org.openstreetmap.josm.actions.ExpertToggleAction;
     43import org.openstreetmap.josm.actions.HatchAreaOutsideDownloadAction;
    4344import org.openstreetmap.josm.actions.RenameLayerAction;
    4445import org.openstreetmap.josm.actions.SaveActionBase;
     
    317318
    318319            // paint remainder
    319             g.setPaint(hatched);
    320             g.fill(a);
     320            if (HatchAreaOutsideDownloadAction.isHatchEnabled()) {
     321                g.setPaint(hatched);
     322                g.fill(a);
     323            }
    321324        }
    322325
Note: See TracChangeset for help on using the changeset viewer.