Changeset 12474 in josm for trunk/src/org


Ignore:
Timestamp:
2017-07-13T22:05:49+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #14997 - fix reported issues for autofilter buttons

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

Legend:

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

    r12432 r12474  
    6565        return Objects.equals(filter, other.filter);
    6666    }
     67
     68    @Override
     69    public String toString() {
     70        return "AutoFilter [label=" + label + ", description=" + description + ", filter=" + filter + ']';
     71    }
    6772}
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterButton.java

    r12400 r12474  
    3434            public synchronized void actionPerformed(ActionEvent e) {
    3535                AutoFilterManager afm = AutoFilterManager.getInstance();
    36                 if (afm.getCurrentAutoFilter() == filter) {
     36                if (filter.equals(afm.getCurrentAutoFilter())) {
    3737                    afm.setCurrentAutoFilter(null);
    3838                    Main.map.filterDialog.getFilterModel().executeFilters();
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java

    r12471 r12474  
    4747import org.openstreetmap.josm.gui.NavigatableComponent;
    4848import org.openstreetmap.josm.gui.NavigatableComponent.ZoomChangeListener;
     49import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     50import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     51import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     52import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    4953import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5054import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;
     
    5660 * @since 12400
    5761 */
    58 public final class AutoFilterManager implements ZoomChangeListener, MapModeChangeListener, DataSetListener, PreferenceChangedListener {
     62public final class AutoFilterManager implements ZoomChangeListener, MapModeChangeListener, DataSetListener, PreferenceChangedListener, LayerChangeListener {
    5963
    6064    /**
     
    118122        Main.pref.addPreferenceChangeListener(this);
    119123        NavigatableComponent.addZoomChangeListener(this);
     124        Main.getLayerManager().addLayerChangeListener(this);
    120125        DatasetEventManager.getInstance().addDatasetListener(this, FireMode.IN_EDT_CONSOLIDATED);
    121126        registerAutoFilterRules(AutoFilterRule.defaultRules());
     
    125130        if (enabledRule != null && Main.map != null
    126131                && enabledRule.getMinZoomLevel() <= Selector.GeneralSelector.scale2level(Main.map.mapView.getDist100Pixel())) {
     132            // Retrieve the values from current rule visible on screen
    127133            NavigableSet<String> values = getNumericValues(enabledRule.getKey(), enabledRule.getValueComparator());
     134            // Make sure current auto filter button remains visible even if no data is found, to allow user to disable it
     135            if (currentAutoFilter != null) {
     136                values.add(currentAutoFilter.getFilter().text.split("=")[1]);
     137            }
    128138            if (!values.equals(buttons.keySet())) {
    129139                removeAllButtons();
     
    397407        }
    398408    }
     409
     410    @Override
     411    public void layerAdded(LayerAddEvent e) {
     412        // Do nothing
     413    }
     414
     415    @Override
     416    public void layerRemoving(LayerRemoveEvent e) {
     417        if (Main.getLayerManager().getEditLayer() == null) {
     418            resetCurrentAutoFilter();
     419        }
     420    }
     421
     422    @Override
     423    public void layerOrderChanged(LayerOrderChangeEvent e) {
     424        // Do nothing
     425    }
    399426}
Note: See TracChangeset for help on using the changeset viewer.