Ignore:
Timestamp:
2017-09-04T00:50:22+02:00 (2 years ago)
Author:
Don-vip
Message:

see #13036 - see #15229 - see #15182 - make Commands depends only on a DataSet, not a Layer. This removes a lot of GUI dependencies

Location:
trunk/src/org/openstreetmap/josm/data
Files:
3 edited

Legend:

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

    r12691 r12718  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    13 import org.openstreetmap.josm.gui.MainApplication;
    14 import org.openstreetmap.josm.gui.layer.Layer;
    15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
    17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    20 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2113import org.openstreetmap.josm.tools.CheckParameterUtil;
    2214
    2315/**
    24  * This is the global undo/redo handler for all {@link OsmDataLayer}s.
     16 * This is the global undo/redo handler for all {@link DataSet}s.
    2517 * <p>
    26  * If you want to change a data layer, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
     18 * If you want to change a data set, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
    2719 */
    28 public class UndoRedoHandler implements LayerChangeListener {
     20public class UndoRedoHandler {
    2921
    3022    /**
     
    4537     */
    4638    public UndoRedoHandler() {
    47         MainApplication.getLayerManager().addLayerChangeListener(this);
     39        // Do nothing
     40    }
     41
     42    /**
     43     * A listener that gets notified of command queue (undo/redo) size changes.
     44     * @since 12718 (moved from {@code OsmDataLayer}
     45     */
     46    @FunctionalInterface
     47    public interface CommandQueueListener {
     48        /**
     49         * Notifies the listener about the new queue size
     50         * @param queueSize Undo stack size
     51         * @param redoSize Redo stack size
     52         */
     53        void commandChanged(int queueSize, int redoSize);
    4854    }
    4955
     
    9298        }
    9399        addNoRedraw(c);
    94         c.invalidateAffectedLayers();
    95100        afterAdd();
    96101
     
    125130                final Command c = commands.removeLast();
    126131                c.undoCommand();
    127                 c.invalidateAffectedLayers();
    128132                redoCommands.addFirst(c);
    129133                if (commands.isEmpty()) {
     
    161165            final Command c = redoCommands.removeFirst();
    162166            c.executeCommand();
    163             c.invalidateAffectedLayers();
    164167            commands.add(c);
    165168            if (redoCommands.isEmpty()) {
     
    197200
    198201    /**
    199      * Resets all commands that affect the given layer.
    200      * @param layer The layer that was affected.
    201      */
    202     public void clean(Layer layer) {
    203         if (layer == null)
     202     * Resets all commands that affect the given dataset.
     203     * @param dataSet The data set that was affected.
     204     * @since 12718
     205     */
     206    public void clean(DataSet dataSet) {
     207        if (dataSet == null)
    204208            return;
    205209        boolean changed = false;
    206210        for (Iterator<Command> it = commands.iterator(); it.hasNext();) {
    207             if (it.next().invalidBecauselayerRemoved(layer)) {
     211            if (it.next().getAffectedDataSet() == dataSet) {
    208212                it.remove();
    209213                changed = true;
     
    211215        }
    212216        for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) {
    213             if (it.next().invalidBecauselayerRemoved(layer)) {
     217            if (it.next().getAffectedDataSet() == dataSet) {
    214218                it.remove();
    215219                changed = true;
     
    219223            fireCommandsChanged();
    220224        }
    221     }
    222 
    223     @Override
    224     public void layerRemoving(LayerRemoveEvent e) {
    225         clean(e.getRemovedLayer());
    226     }
    227 
    228     @Override
    229     public void layerAdded(LayerAddEvent e) {
    230         // Do nothing
    231     }
    232 
    233     @Override
    234     public void layerOrderChanged(LayerOrderChangeEvent e) {
    235         // Do nothing
    236225    }
    237226
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12672 r12718  
    169169    private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<>();
    170170
     171    private String name;
    171172    private UploadPolicy uploadPolicy;
    172173
     
    13601361    }
    13611362
     1363    /**
     1364     * Returns the name of this data set (optional).
     1365     * @return the name of this data set. Can be {@code null}
     1366     * @since 12718
     1367     */
     1368    public String getName() {
     1369        return name;
     1370    }
     1371
     1372    /**
     1373     * Sets the name of this data set.
     1374     * @param name the new name of this data set. Can be {@code null} to reset it
     1375     * @since 12718
     1376     */
     1377    public void setName(String name) {
     1378        this.name = name;
     1379    }
     1380
    13621381    /* --------------------------------------------------------------------------------- */
    13631382    /* interface ProjectionChangeListner                                                 */
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r12667 r12718  
    2323import org.openstreetmap.josm.data.osm.search.SearchCompiler.NotOutsideDataSourceArea;
    2424import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    25 import org.openstreetmap.josm.gui.MainApplication;
    2625import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2726import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    331330        }
    332331        if (!primitivesToDelete.isEmpty()) {
    333             return DeleteCommand.delete(MainApplication.getLayerManager().getEditLayer(), primitivesToDelete);
     332            return DeleteCommand.delete(primitivesToDelete);
    334333        } else {
    335334            return null;
Note: See TracChangeset for help on using the changeset viewer.