Changeset 11905 in josm


Ignore:
Timestamp:
2017-04-14T21:23:29+02:00 (3 months ago)
Author:
Don-vip
Message:

sonar - squid:S2301 - Public methods should not contain selector arguments

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r11746 r11905  
    133133
    134134            new Timer(true).schedule(this, TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(PROP_INTERVAL.get()));
    135             Main.getLayerManager().addLayerChangeListener(this, true);
     135            Main.getLayerManager().addAndFireLayerChangeListener(this);
    136136        }
    137137    }
  • trunk/src/org/openstreetmap/josm/gui/MainFrame.java

    r11713 r11905  
    9494        // This listener is never removed, since the main frame exists forever.
    9595        Main.getLayerManager().addActiveLayerChangeListener(e -> refreshTitle());
    96         Main.getLayerManager().addLayerChangeListener(new ManageLayerListeners(), true);
     96        Main.getLayerManager().addAndFireLayerChangeListener(new ManageLayerListeners());
    9797
    9898        refreshTitle();
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r11807 r11905  
    255255        this.layerManager = layerManager;
    256256        initialViewport = viewportData;
    257         layerManager.addLayerChangeListener(this, true);
     257        layerManager.addAndFireLayerChangeListener(this);
    258258        layerManager.addActiveLayerChangeListener(this);
    259259        Main.pref.addPreferenceChangeListener(this);
     
    746746     */
    747747    public void destroy() {
    748         layerManager.removeLayerChangeListener(this, true);
     748        layerManager.removeAndFireLayerChangeListener(this);
    749749        layerManager.removeActiveLayerChangeListener(this);
    750750        Main.pref.removePreferenceChangeListener(this);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r11893 r11905  
    323323    public void showNotify() {
    324324        layerManager.addActiveLayerChangeListener(activateLayerAction);
    325         layerManager.addLayerChangeListener(model, true);
     325        layerManager.addAndFireLayerChangeListener(model);
    326326        layerManager.addAndFireActiveLayerChangeListener(model);
    327327        model.populate();
     
    330330    @Override
    331331    public void hideNotify() {
    332         layerManager.removeLayerChangeListener(model, true);
     332        layerManager.removeAndFireLayerChangeListener(model);
    333333        layerManager.removeActiveLayerChangeListener(model);
    334334        layerManager.removeActiveLayerChangeListener(activateLayerAction);
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerManager.java

    r11774 r11905  
    6464    }
    6565
     66    /**
     67     * Base class of layer manager events.
     68     */
    6669    protected static class LayerManagerEvent {
    6770        private final LayerManager source;
     
    215218    }
    216219
     220    /**
     221     * Add a layer (implementation).
     222     * @param layer The layer to add
     223     * @param initialZoom whether if the mapview must be zoomed at layer projection bounds
     224     */
    217225    protected synchronized void realAddLayer(Layer layer, boolean initialZoom) {
    218226        if (containsLayer(layer)) {
     
    240248    }
    241249
     250    /**
     251     * Remove the layer from the mapview (implementation).
     252     * @param layer The layer to remove
     253     */
    242254    protected synchronized void realRemoveLayer(Layer layer) {
    243255        GuiHelper.assertCallFromEdt();
     
    256268    }
    257269
     270    /**
     271     * Remove a single layer from the mapview (implementation).
     272     * @param layerToRemove The layer to remove
     273     * @return A list of layers that should be removed afterwards.
     274     */
    258275    protected Collection<Layer> realRemoveSingleLayer(Layer layerToRemove) {
    259276        updateLayers(mutableLayers -> mutableLayers.remove(layerToRemove));
     
    273290    }
    274291
     292    /**
     293     * Move a layer to a new position (implementation).
     294     * @param layer The layer to move.
     295     * @param position The position.
     296     * @throws IndexOutOfBoundsException if the position is out of bounds.
     297     */
    275298    protected synchronized void realMoveLayer(Layer layer, int position) {
    276299        checkContainsLayer(layer);
     
    360383    }
    361384
     385    /**
     386     * Checks if the specified layer is handled by this layer manager.
     387     * @param layer layer to check
     388     * @throws IllegalArgumentException if layer is not handled by this layer manager
     389     */
    362390    protected void checkContainsLayer(Layer layer) {
    363391        if (!containsLayer(layer)) {
     
    371399     * @param listener the listener.
    372400     * @throws IllegalArgumentException If the listener was added twice.
     401     * @see #addAndFireLayerChangeListener
    373402     */
    374403    public synchronized void addLayerChangeListener(LayerChangeListener listener) {
    375         addLayerChangeListener(listener, false);
    376     }
    377 
    378     /**
    379      * Adds a layer change listener
    380      *
    381      * @param listener the listener.
    382      * @param fireAdd if we should fire an add event for every layer in this manager.
    383      * @throws IllegalArgumentException If the listener was added twice.
    384      */
    385     public synchronized void addLayerChangeListener(LayerChangeListener listener, boolean fireAdd) {
    386404        if (layerChangeListeners.contains(listener)) {
    387405            throw new IllegalArgumentException("Listener already registered.");
    388406        }
    389407        layerChangeListeners.add(listener);
    390         if (fireAdd) {
    391             for (Layer l : getLayers()) {
    392                 listener.layerAdded(new LayerAddEvent(this, l, true));
    393             }
     408    }
     409
     410    /**
     411     * Adds a layer change listener and fire an add event for every layer in this manager.
     412     *
     413     * @param listener the listener.
     414     * @throws IllegalArgumentException If the listener was added twice.
     415     * @see #addLayerChangeListener
     416     * @since 11905
     417     */
     418    public synchronized void addAndFireLayerChangeListener(LayerChangeListener listener) {
     419        addLayerChangeListener(listener);
     420        for (Layer l : getLayers()) {
     421            listener.layerAdded(new LayerAddEvent(this, l, true));
    394422        }
    395423    }
     
    399427     *
    400428     * @param listener the listener. Ignored if null or already registered.
     429     * @see #removeAndFireLayerChangeListener
    401430     */
    402431    public synchronized void removeLayerChangeListener(LayerChangeListener listener) {
    403         removeLayerChangeListener(listener, false);
    404     }
    405 
    406     /**
    407      * Removes a layer change listener
    408      *
    409      * @param listener the listener.
    410      * @param fireRemove if we should fire a remove event for every layer in this manager. The event is fired as if the layer was deleted but
    411      * {@link LayerRemoveEvent#scheduleRemoval(Collection)} is ignored.
    412      */
    413     public synchronized void removeLayerChangeListener(LayerChangeListener listener, boolean fireRemove) {
    414432        if (!layerChangeListeners.remove(listener)) {
    415433            throw new IllegalArgumentException("Listener was not registered before: " + listener);
    416         } else {
    417             if (fireRemove) {
    418                 for (Layer l : getLayers()) {
    419                     listener.layerRemoving(new LayerRemoveEvent(this, l));
    420                 }
    421             }
     434        }
     435    }
     436
     437    /**
     438     * Removes a layer change listener and fire a remove event for every layer in this manager.
     439     * The event is fired as if the layer was deleted but
     440     * {@link LayerRemoveEvent#scheduleRemoval(Collection)} is ignored.
     441     *
     442     * @param listener the listener.
     443     * @see #removeLayerChangeListener
     444     * @since 11905
     445     */
     446    public synchronized void removeAndFireLayerChangeListener(LayerChangeListener listener) {
     447        removeLayerChangeListener(listener);
     448        for (Layer l : getLayers()) {
     449            listener.layerRemoving(new LayerRemoveEvent(this, l));
    422450        }
    423451    }
     
    475503    }
    476504
     505    /**
     506     * Reset all layer manager state (implementation).
     507     */
    477508    protected synchronized void realResetState() {
    478509        // The listeners trigger the removal of other layers
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java

    r11000 r11905  
    159159    }
    160160
     161    /** the tested layer manager */
    161162    protected LayerManager layerManager;
    162163
     
    397398
    398399    /**
    399      * {@link LayerManager#addLayerChangeListener(LayerChangeListener, boolean)} fires fake add events
     400     * {@link LayerManager#addAndFireLayerChangeListener(LayerChangeListener)} fires fake add events
    400401     */
    401402    @Test
     
    406407        layerManager.addLayer(layer1);
    407408        layerManager.addLayer(layer2);
    408         layerManager.addLayerChangeListener(new LayerChangeListener() {
     409        layerManager.addAndFireLayerChangeListener(new LayerChangeListener() {
    409410            @Override
    410411            public void layerRemoving(LayerRemoveEvent e) {
     
    421422                fired.add(e.getAddedLayer());
    422423            }
    423         }, true);
     424        });
    424425
    425426        assertEquals(Arrays.asList(layer1, layer2), fired);
     
    452453
    453454    /**
    454      * {@link LayerManager#removeLayerChangeListener(LayerChangeListener, boolean)} fires fake remove events
     455     * {@link LayerManager#removeAndFireLayerChangeListener(LayerChangeListener)} fires fake remove events
    455456     */
    456457    @Test
     
    477478            }
    478479        };
    479         layerManager.addLayerChangeListener(listener, false);
    480         layerManager.removeLayerChangeListener(listener, true);
     480        layerManager.addLayerChangeListener(listener);
     481        layerManager.removeAndFireLayerChangeListener(listener);
    481482
    482483        assertEquals(Arrays.asList(layer1, layer2), fired);
Note: See TracChangeset for help on using the changeset viewer.