Changeset 12726 in josm for trunk/src


Ignore:
Timestamp:
2017-09-04T23:45:49+02:00 (7 years ago)
Author:
Don-vip
Message:

see #13036 - deprecate Command() default constructor, fix unit tests and java warnings

Location:
trunk/src/org/openstreetmap/josm
Files:
46 edited

Legend:

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

    r12641 r12726  
    1212import org.openstreetmap.josm.command.AddCommand;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6667
    6768        // add the node
    68         MainApplication.undoRedo.add(new AddCommand(nnew));
    69         getLayerManager().getEditDataSet().setSelected(nnew);
     69        DataSet ds = getLayerManager().getEditDataSet();
     70        MainApplication.undoRedo.add(new AddCommand(ds, nnew));
     71        ds.setSelected(nnew);
    7072        MapView mapView = MainApplication.getMap().mapView;
    7173        if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r12641 r12726  
    2525import org.openstreetmap.josm.data.coor.EastNorth;
    2626import org.openstreetmap.josm.data.coor.LatLon;
     27import org.openstreetmap.josm.data.osm.DataSet;
    2728import org.openstreetmap.josm.data.osm.Node;
    2829import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    137138        }
    138139
    139         Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
     140        DataSet ds = getLayerManager().getEditDataSet();
     141        Collection<OsmPrimitive> sel = ds.getSelected();
    140142        List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class);
    141143        List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class);
     
    222224                Node n = new Node(ll);
    223225                nodesToAdd.add(n);
    224                 cmds.add(new AddCommand(n));
     226                cmds.add(new AddCommand(ds, n));
    225227            }
    226228        }
     
    234236            Way newWay = new Way();
    235237            newWay.setNodes(nodesToAdd);
    236             cmds.add(new AddCommand(newWay));
     238            cmds.add(new AddCommand(ds, newWay));
    237239        } else {
    238240            Way newWay = new Way(existingWay);
    239241            newWay.setNodes(nodesToAdd);
    240             cmds.add(new ChangeCommand(existingWay, newWay));
     242            cmds.add(new ChangeCommand(ds, existingWay, newWay));
    241243        }
    242244
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r12641 r12726  
    248248        final String commandName;
    249249        if (existingRelation == null) {
    250             list.add(new AddCommand(relation));
     250            list.add(new AddCommand(selectedWays.iterator().next().getDataSet(), relation));
    251251            commandName = getName(false);
    252252        } else {
  • trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java

    r12641 r12726  
    1515import org.openstreetmap.josm.command.SelectCommand;
    1616import org.openstreetmap.josm.command.SequenceCommand;
     17import org.openstreetmap.josm.data.osm.DataSet;
    1718import org.openstreetmap.josm.data.osm.Node;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2021import org.openstreetmap.josm.gui.MainApplication;
    2122import org.openstreetmap.josm.gui.MapFrame;
    22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2323import org.openstreetmap.josm.tools.Shortcut;
    2424import org.openstreetmap.josm.tools.Utils;
     
    6161    @Override
    6262    public void actionPerformed(ActionEvent evt) {
    63         OsmDataLayer osmLayer = getLayerManager().getEditLayer();
    64         if (osmLayer == null)
     63        DataSet ds = getLayerManager().getEditDataSet();
     64        if (ds == null)
    6565            return;
    6666        MapFrame map = MainApplication.getMap();
    6767        if (!(map.mapMode instanceof DrawAction)) return; // We are not on draw mode
    6868
    69         Collection<Node> selectedPoints = osmLayer.data.getSelectedNodes();
    70         Collection<Way> selectedLines = osmLayer.data.getSelectedWays();
     69        Collection<Node> selectedPoints = ds.getSelectedNodes();
     70        Collection<Way> selectedLines = ds.getSelectedWays();
    7171        if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection
    7272            return;
     
    115115            }
    116116            MainApplication.undoRedo.add(new SequenceCommand(tr("Follow line"),
    117                     new ChangeCommand(follower, newFollower),
    118                     new SelectCommand(newFollower.isClosed() // see #10028 - unselect last node when closing a way
     117                    new ChangeCommand(ds, follower, newFollower),
     118                    new SelectCommand(ds, newFollower.isClosed() // see #10028 - unselect last node when closing a way
    119119                            ? Arrays.<OsmPrimitive>asList(follower)
    120120                            : Arrays.<OsmPrimitive>asList(follower, newPoint)
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r12641 r12726  
    2424import org.openstreetmap.josm.command.SequenceCommand;
    2525import org.openstreetmap.josm.data.coor.EastNorth;
     26import org.openstreetmap.josm.data.osm.DataSet;
    2627import org.openstreetmap.josm.data.osm.Node;
    2728import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    8485        if (!isEnabled())
    8586            return;
    86         Collection<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes();
     87        DataSet ds = getLayerManager().getEditDataSet();
     88        Collection<Node> selectedNodes = ds.getSelectedNodes();
    8789        Collection<Command> cmds = new LinkedList<>();
    8890        Map<Way, MultiMap<Integer, Node>> data = new HashMap<>();
    8991
    9092        // If the user has selected some ways, only join the node to these.
    91         boolean restrictToSelectedWays =
    92                 !getLayerManager().getEditDataSet().getSelectedWays().isEmpty();
     93        boolean restrictToSelectedWays = !ds.getSelectedWays().isEmpty();
    9394
    9495        // Planning phase: decide where we'll insert the nodes and put it all in "data"
     
    155156            Way wnew = new Way(w);
    156157            wnew.setNodes(wayNodes);
    157             cmds.add(new ChangeCommand(w, wnew));
     158            cmds.add(new ChangeCommand(ds, w, wnew));
    158159        }
    159160
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r12641 r12726  
    157157            corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew);
    158158        }
    159         return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w.getDataSet(), w, wnew));
     159        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew));
    160160    }
    161161
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r12718 r12726  
    593593        final Way changedWay = new Way(way);
    594594        changedWay.setNodes(wayToKeep.getNodes());
    595         commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay));
     595        commandList.add(new ChangeCommand(way, changedWay));
    596596        if (!isMapModeDraw && !newSelection.contains(way)) {
    597597            newSelection.add(way);
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r12663 r12726  
    303303
    304304        List<Command> cmds = new LinkedList<>();
    305         cmds.add(new AddCommand(n));
     305        cmds.add(new AddCommand(selectedNode.getDataSet(), n));
    306306        if (dialog != null) {
    307307            dialog.update(selectedNode, Collections.singletonList(n), cmds);
     
    440440        Node newNode = new Node(originalNode, true /* clear OSM ID */);
    441441        newNodes.add(newNode);
    442         cmds.add(new AddCommand(newNode));
     442        cmds.add(new AddCommand(originalNode.getDataSet(), newNode));
    443443
    444444        List<Node> nn = new ArrayList<>();
     
    583583                if (seen) {
    584584                    Node newNode = new Node(n, true /* clear OSM ID */);
    585                     cmds.add(new AddCommand(newNode));
     585                    cmds.add(new AddCommand(selectedNode.getDataSet(), newNode));
    586586                    newNodes.add(newNode);
    587587                    addNodes.add(newNode);
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r12643 r12726  
    487487                return;
    488488            }
    489             cmds.add(new AddCommand(n));
     489            cmds.add(new AddCommand(ds, n));
    490490
    491491            if (!ctrl) {
     
    576576                    way = new Way();
    577577                    way.addNode(n0);
    578                     cmds.add(new AddCommand(way));
     578                    cmds.add(new AddCommand(ds, way));
    579579                    wayToSelect = way;
    580580                } else {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r12689 r12726  
    4040import org.openstreetmap.josm.data.coor.EastNorth;
    4141import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
     42import org.openstreetmap.josm.data.osm.DataSet;
    4243import org.openstreetmap.josm.data.osm.Node;
    4344import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    592593            Way wnew = new Way(ws.way);
    593594            wnew.addNode(ws.lowerIndex+1, n);
    594             SequenceCommand cmds = new SequenceCommand(tr("Add a new node to an existing way"),
    595                     new AddCommand(n), new ChangeCommand(ws.way, wnew));
    596             MainApplication.undoRedo.add(cmds);
     595            DataSet ds = ws.way.getDataSet();
     596            MainApplication.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"),
     597                    new AddCommand(ds, n), new ChangeCommand(ds, ws.way, wnew)));
    597598        }
    598599    }
     
    603604    private void createNewRectangle() {
    604605        if (selectedSegment == null) return;
    605         // crete a new rectangle
     606        DataSet ds = getLayerManager().getEditDataSet();
     607        // create a new rectangle
    606608        Collection<Command> cmds = new LinkedList<>();
    607609        Node third = new Node(newN2en);
     
    618620        wnew.addNode(selectedSegment.getFirstNode());
    619621        // undo support
    620         cmds.add(new AddCommand(third));
     622        cmds.add(new AddCommand(ds, third));
    621623        if (!dualAlignSegmentCollapsed) {
    622             cmds.add(new AddCommand(fourth));
    623         }
    624         cmds.add(new AddCommand(wnew));
     624            cmds.add(new AddCommand(ds, fourth));
     625        }
     626        cmds.add(new AddCommand(ds, wnew));
    625627        Command c = new SequenceCommand(tr("Extrude Way"), cmds);
    626628        MainApplication.undoRedo.add(c);
    627         getLayerManager().getEditDataSet().setSelected(wnew);
     629        ds.setSelected(wnew);
    628630    }
    629631
     
    634636     */
    635637    private void performExtrusion() {
     638        DataSet ds = getLayerManager().getEditDataSet();
    636639        // create extrusion
    637640        Collection<Command> cmds = new LinkedList<>();
     
    661664            wnew.removeNode(n1Old);
    662665            wayWasModified = true;
    663             cmds.add(new AddCommand(n1New));
     666            cmds.add(new AddCommand(ds, n1New));
    664667            changedNodes.add(n1New);
    665668        } else {
     
    669672            wayWasModified = true;
    670673            insertionPoint++;
    671             cmds.add(new AddCommand(n1New));
     674            cmds.add(new AddCommand(ds, n1New));
    672675            changedNodes.add(n1New);
    673676        }
     
    691694            wnew.removeNode(n2Old);
    692695            wayWasModified = true;
    693             cmds.add(new AddCommand(n2New));
     696            cmds.add(new AddCommand(ds, n2New));
    694697            changedNodes.add(n2New);
    695698        } else {
     
    698701            wnew.addNode(insertionPoint, n2New);
    699702            wayWasModified = true;
    700             cmds.add(new AddCommand(n2New));
     703            cmds.add(new AddCommand(ds, n2New));
    701704            changedNodes.add(n2New);
    702705        }
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r12718 r12726  
    399399        }
    400400
     401        DataSet ds = getLayerManager().getEditDataSet();
    401402        updateKeyModifiers(e);
    402403        mousePos = e.getPoint();
     
    404405        if (state == State.SELECTING) {
    405406            if (targetWay != null) {
    406                 getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId());
     407                ds.setSelected(targetWay.getPrimitiveId());
    407408                updateStateByCurrentSelection();
    408409            }
     
    425426                Node virtualNode = new Node(mv.getEastNorth(mousePos.x,
    426427                        mousePos.y));
    427                 virtualCmds.add(new AddCommand(virtualNode));
     428                virtualCmds.add(new AddCommand(ds, virtualNode));
    428429
    429430                // Looking for candidateSegment copies in ways that are
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java

    r12641 r12726  
    1111import java.util.Set;
    1212
     13import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.command.AddCommand;
    1415import org.openstreetmap.josm.command.Command;
    1516import org.openstreetmap.josm.command.SequenceCommand;
    1617import org.openstreetmap.josm.data.coor.EastNorth;
     18import org.openstreetmap.josm.data.osm.DataSet;
    1719import org.openstreetmap.josm.data.osm.Node;
    1820import org.openstreetmap.josm.data.osm.NodeGraph;
     
    186188
    187189    private List<Command> makeAddWayAndNodesCommandList() {
     190        DataSet ds = Main.main.getEditDataSet();
    188191        List<Command> commands = new ArrayList<>(sortedNodes.size() + ways.size());
    189192        for (int i = 0; i < sortedNodes.size() - (isClosedPath() ? 1 : 0); i++) {
    190             commands.add(new AddCommand(sortedNodes.get(i)));
     193            commands.add(new AddCommand(ds, sortedNodes.get(i)));
    191194        }
    192195        for (Way w : ways) {
    193             commands.add(new AddCommand(w));
     196            commands.add(new AddCommand(ds, w));
    194197        }
    195198        return commands;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r12641 r12726  
    12351235
    12361236        private void createMiddleNodeFromVirtual(EastNorth currentEN) {
     1237            DataSet ds = getLayerManager().getEditDataSet();
    12371238            Collection<Command> virtualCmds = new LinkedList<>();
    1238             virtualCmds.add(new AddCommand(virtualNode));
     1239            virtualCmds.add(new AddCommand(ds, virtualNode));
    12391240            for (WaySegment virtualWay : virtualWays) {
    12401241                Way w = virtualWay.way;
    12411242                Way wnew = new Way(w);
    12421243                wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
    1243                 virtualCmds.add(new ChangeCommand(w, wnew));
     1244                virtualCmds.add(new ChangeCommand(ds, w, wnew));
    12441245            }
    12451246            virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
     
    12481249                    virtualWays.size());
    12491250            MainApplication.undoRedo.add(new SequenceCommand(text, virtualCmds));
    1250             getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
     1251            ds.setSelected(Collections.singleton((OsmPrimitive) virtualNode));
    12511252            clear();
    12521253        }
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r12718 r12726  
    3636     * Creates the command and specify the element to add in the context of the current edit layer, if any.
    3737     * @param osm The primitive to add
     38     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
    3839     */
     40    @Deprecated
    3941    public AddCommand(OsmPrimitive osm) {
    4042        this.osm = Objects.requireNonNull(osm, "osm");
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r12718 r12726  
    3939     * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
    4040     * @param data The OSM primitives data to add. Must not be {@code null}
    41      */
     41     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, DataSet)} instead
     42     */
     43    @Deprecated
    4244    public AddPrimitivesCommand(List<PrimitiveData> data) {
    4345        this(data, data);
     
    4951     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
    5052     * @since 5953
    51      */
     53     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
     54     */
     55    @Deprecated
    5256    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
    5357        init(data, toSelect);
     
    7781        super(ds);
    7882        init(data, toSelect);
     83    }
     84
     85    /**
     86     * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set.
     87     * @param data The OSM primitives data to add and select. Must not be {@code null}
     88     * @param ds The target data set. Must not be {@code null}
     89     * @since 12726
     90     */
     91    public AddPrimitivesCommand(List<PrimitiveData> data, DataSet ds) {
     92        this(data, data, ds);
    7993    }
    8094
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r12718 r12726  
    3030
    3131    /**
    32      * Constructs a new {@code ChangeCommand} in the context of the current edit layer, if any.
    33      * @param osm The existing primitive to modify
     32     * Constructs a new {@code ChangeCommand} in the context of {@code osm} data set.
     33     * @param osm The existing primitive to modify. It must belong to a data set
    3434     * @param newOsm The new primitive
    3535     */
    3636    public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
    37         this.osm = osm;
    38         this.newOsm = newOsm;
    39         sanityChecks();
     37        this(osm.getDataSet(), osm, newOsm);
    4038    }
    4139
  • trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java

    r12663 r12726  
    1010import javax.swing.Icon;
    1111
     12import org.openstreetmap.josm.data.osm.DataSet;
    1213import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1314import org.openstreetmap.josm.data.osm.Node;
     
    3637     */
    3738    public ChangeNodesCommand(Way way, List<Node> newNodes) {
     39        this(way.getDataSet(), way, newNodes);
     40    }
     41
     42    /**
     43     * Constructs a new {@code ChangeNodesCommand}.
     44     * @param ds The target data set. Must not be {@code null}
     45     * @param way The way to modify
     46     * @param newNodes The new list of nodes for the given way
     47     * @since 12726
     48     */
     49    public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) {
     50        super(ds);
    3851        this.way = way;
    3952        this.newNodes = newNodes;
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java

    r12663 r12726  
    1313import java.util.List;
    1414import java.util.Map;
     15import java.util.NoSuchElementException;
    1516import java.util.Objects;
    1617import java.util.stream.Collectors;
     
    7273     * Creates a command to change multiple tags of multiple objects
    7374     *
    74      * @param objects the objects to modify
     75     * @param ds The target data set. Must not be {@code null}
     76     * @param objects the objects to modify. Must not be empty
    7577     * @param tags the tags to set
    76      */
    77     public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     78     * @since 12726
     79     */
     80    public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     81        super(ds);
    7882        this.tags = tags;
    7983        init(objects);
     
    8185
    8286    /**
     87     * Creates a command to change multiple tags of multiple objects
     88     *
     89     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
     90     * @param tags the tags to set
     91     * @throws NullPointerException if objects is null or contain null item
     92     * @throws NoSuchElementException if objects is empty
     93     */
     94    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
     95        this(objects.iterator().next().getDataSet(), objects, tags);
     96    }
     97
     98    /**
    8399     * Creates a command to change one tag of multiple objects
    84100     *
    85      * @param objects the objects to modify
     101     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
    86102     * @param key the key of the tag to set
    87103     * @param value the value of the key to set
     104     * @throws NullPointerException if objects is null or contain null item
     105     * @throws NoSuchElementException if objects is empty
    88106     */
    89107    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
     108        super(objects.iterator().next().getDataSet());
    90109        this.tags = new HashMap<>(1);
    91110        this.tags.put(key, value);
     
    96115     * Creates a command to change one tag of one object
    97116     *
    98      * @param object the object to modify
     117     * @param object the object to modify. Must belong to a data set
    99118     * @param key the key of the tag to set
    100119     * @param value the value of the key to set
     120     * @throws NullPointerException if object is null
    101121     */
    102122    public ChangePropertyCommand(OsmPrimitive object, String key, String value) {
     
    134154    @Override
    135155    public boolean executeCommand() {
    136         if (objects.isEmpty())
    137             return true;
    138156        final DataSet dataSet = objects.get(0).getDataSet();
    139157        if (dataSet != null) {
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java

    r11608 r12726  
    1010import java.util.LinkedList;
    1111import java.util.List;
     12import java.util.NoSuchElementException;
    1213import java.util.Objects;
    1314
    1415import javax.swing.Icon;
    1516
     17import org.openstreetmap.josm.data.osm.DataSet;
    1618import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1719import org.openstreetmap.josm.data.validation.util.NameVisitor;
     
    6668     * Constructs a new {@code ChangePropertyKeyCommand}.
    6769     *
    68      * @param object the object subject to change replacement
     70     * @param object the object subject to change replacement. Must not be null, and belong to a data set
    6971     * @param key The key to replace
    7072     * @param newKey the new value of the key
     
    7880     * Constructs a new {@code ChangePropertyKeyCommand}.
    7981     *
    80      * @param objects all objects subject to change replacement
     82     * @param objects all objects subject to change replacement. Must not be null or empty, and objects must belong to a data set
    8183     * @param key The key to replace
    8284     * @param newKey the new value of the key
     85     * @throws NullPointerException if objects is null or contain null item
     86     * @throws NoSuchElementException if objects is empty
    8387     */
    8488    public ChangePropertyKeyCommand(Collection<? extends OsmPrimitive> objects, String key, String newKey) {
     89        this(objects.iterator().next().getDataSet(), objects, key, newKey);
     90    }
     91
     92    /**
     93     * Constructs a new {@code ChangePropertyKeyCommand}.
     94     *
     95     * @param ds The target data set. Must not be {@code null}
     96     * @param objects all objects subject to change replacement.
     97     * @param key The key to replace
     98     * @param newKey the new value of the key
     99     * @since 12726
     100     */
     101    public ChangePropertyKeyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, String key, String newKey) {
     102        super(ds);
    85103        this.objects = new LinkedList<>(objects);
    86104        this.key = key;
  • trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java

    r12663 r12726  
    3737    /**
    3838     * Constructs a new {@code ChangeRelationMemberRoleCommand}.
    39      * @param relation The relation to be changed
     39     * @param relation The relation to be changed. Must not be null, and belong to a data set
    4040     * @param position Member position
    4141     * @param newRole New role
    4242     */
    4343    public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
    44         this.relation = relation;
    45         this.position = position;
    46         this.newRole = newRole;
     44        this(relation.getDataSet(), relation, position, newRole);
    4745    }
    4846
    4947    /**
    5048     * Constructs a new {@code ChangeRelationMemberRoleCommand}.
    51      * @param dataSet The data set the role is in
     49     * @param dataSet The data set the role is in. Must not be {@code null}
    5250     * @param relation The relation to be changed
    5351     * @param position Member position
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r12718 r12726  
    147147    /**
    148148     * Creates a new command in the context of the current edit layer, if any
    149      */
     149     * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead
     150     */
     151    @Deprecated
    150152    public Command() {
    151153        this.layer = MainApplication.getLayerManager().getEditLayer();
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12718 r12726  
    7575        @Override
    7676        public String toString() {
    77             return "DeleteChildCommand [osm=" + osm + "]";
     77            return "DeleteChildCommand [osm=" + osm + ']';
    7878        }
    7979    }
     
    8888     * Constructor. Deletes a collection of primitives in the current edit layer.
    8989     *
    90      * @param data the primitives to delete. Must neither be null nor empty.
     90     * @param data the primitives to delete. Must neither be null nor empty, and belong to a data set
    9191     * @throws IllegalArgumentException if data is null or empty
    9292     */
    9393    public DeleteCommand(Collection<? extends OsmPrimitive> data) {
    94         CheckParameterUtil.ensureParameterNotNull(data, "data");
    95         this.toDelete = data;
    96         checkConsistency();
     94        this(data.iterator().next().getDataSet(), data);
    9795    }
    9896
  • trunk/src/org/openstreetmap/josm/command/MoveCommand.java

    r12348 r12726  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.NoSuchElementException;
    1112import java.util.Objects;
    1213
     
    8485    /**
    8586     * Constructs a new {@code MoveCommand} and assign the initial object set and movement vector.
    86      * @param objects The primitives to move
     87     * @param objects The primitives to move. Must neither be null nor empty. Objects must belong to a data set
    8788     * @param x X difference movement. Coordinates are in northern/eastern
    8889     * @param y Y difference movement. Coordinates are in northern/eastern
     90     * @throws NullPointerException if objects is null or contain null item
     91     * @throws NoSuchElementException if objects is empty
    8992     */
    9093    public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
     94        super(objects.iterator().next().getDataSet());
    9195        startEN = null;
    9296        saveCheckpoint(); // (0,0) displacement will be saved
  • trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java

    r12663 r12726  
    3333    /**
    3434     * Constructs a new {@code RemoveNodesCommand}.
    35      * @param way The way to modify
     35     * @param way The way to modify. Must not be null, and belong to a data set
    3636     * @param rmNodes The list of nodes to remove
    3737     */
    3838    public RemoveNodesCommand(Way way, List<Node> rmNodes) {
     39        super(way.getDataSet());
    3940        this.way = way;
    4041        this.rmNodes = new HashSet<>(rmNodes);
  • trunk/src/org/openstreetmap/josm/command/SelectCommand.java

    r12350 r12726  
    2828     * Constructs a new select command.
    2929     * @param newSelection the primitives to select when executing the command.
     30     * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead
    3031     */
     32    @Deprecated
    3133    public SelectCommand(Collection<OsmPrimitive> newSelection) {
    3234        if (newSelection == null || newSelection.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r12721 r12726  
    1111import javax.swing.Icon;
    1212
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.gui.layer.Layer;
     
    3334    /**
    3435     * Create the command by specifying the list of commands to execute.
     36     * @param ds The target data set. Must not be {@code null}
     37     * @param name The description text
     38     * @param sequenz The sequence that should be executed
     39     * @param continueOnError Determines if the sequence execution should continue after one of its commands fails
     40     * @since 12726
     41     */
     42    public SequenceCommand(DataSet ds, String name, Collection<Command> sequenz, boolean continueOnError) {
     43        super(ds);
     44        this.name = name;
     45        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
     46        this.continueOnError = continueOnError;
     47    }
     48
     49    /**
     50     * Create the command by specifying the list of commands to execute.
    3551     * @param name The description text
    3652     * @param sequenz The sequence that should be executed. Must not be null or empty
     
    3955     */
    4056    public SequenceCommand(String name, Collection<Command> sequenz, boolean continueOnError) {
    41         super(sequenz.iterator().next().getAffectedDataSet());
    42         this.name = name;
    43         this.sequence = sequenz.toArray(new Command[sequenz.size()]);
    44         this.continueOnError = continueOnError;
     57        this(sequenz.iterator().next().getAffectedDataSet(), name, sequenz, continueOnError);
    4558    }
    4659
  • trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java

    r10663 r12726  
    66import java.util.Collection;
    77import java.util.HashMap;
    8 import java.util.LinkedList;
    98import java.util.Map;
     9import java.util.NoSuchElementException;
    1010import java.util.Objects;
    1111
     
    2828     * The nodes to transform.
    2929     */
    30     protected Collection<Node> nodes = new LinkedList<>();
     30    protected final Collection<Node> nodes;
    3131
    3232    /**
    3333     * List of all old states of the nodes.
    3434     */
    35     protected Map<Node, OldNodeState> oldStates = new HashMap<>();
     35    protected final Map<Node, OldNodeState> oldStates = new HashMap<>();
    3636
    3737    /**
     
    4747     * Creates a TransformNodesObject.
    4848     * Find out the impacted nodes and store their initial state.
    49      * @param objects objects to fetch nodes from
     49     * @param objects objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set
     50     * @throws NullPointerException if objects is null or contain null item
     51     * @throws NoSuchElementException if objects is empty
    5052     */
    5153    public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
     54        super(objects.iterator().next().getDataSet());
    5255        this.nodes = AllNodesVisitor.getAllNodes(objects);
    5356        storeOldState();
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r12718 r12726  
    7979    public void undoCommand() {
    8080        DataSet ds = getAffectedDataSet();
    81         if (!Main.main.containsDataSet(ds)) {
     81        if (Main.main != null && !Main.main.containsDataSet(ds)) {
    8282            Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
    8383                    ds.getName(),
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r12718 r12726  
    2828    /**
    2929     * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
     30     * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead
    3031     */
     32    @Deprecated
    3133    public ConflictResolveCommand() {
    32         // Do nothing
     34        this(Main.main.getEditDataSet());
    3335    }
    3436
     
    8183
    8284        DataSet ds = getAffectedDataSet();
    83         if (!Main.main.containsDataSet(ds)) {
    84             Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
    85                     this.toString(),
    86                     ds.getName()
    87             ));
    88             return;
     85        if (Main.main != null) {
     86            if (!Main.main.containsDataSet(ds)) {
     87                Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
     88                        this.toString(),
     89                        ds.getName()
     90                ));
     91                return;
     92            }
     93
     94            Main.main.setEditDataSet(ds);
    8995        }
    90 
    91         Main.main.setEditDataSet(ds);
    9296        reconstituteConflicts();
    9397    }
  • trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java

    r11452 r12726  
    3434     */
    3535    public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
     36        super(conflict.getMy().getDataSet());
    3637        this.conflict = conflict;
    3738        this.decision = decision;
  • trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12718 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Relation>) conflict;
    3940        this.mergedMembers = mergedMembers;
  • trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java

    r10671 r12726  
    5050     */
    5151    public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
     52        super(conflict.getMy().getDataSet());
    5253        this.conflict = conflict;
    5354        this.mergeItems = mergeItems;
  • trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java

    r12672 r12726  
    2929     */
    3030    public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     31        super(conflict.getMy().getDataSet());
    3132        this.conflict = conflict;
    3233    }
  • trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    r12620 r12726  
    3636    @SuppressWarnings("unchecked")
    3737    public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
     38        super(conflict.getMy().getDataSet());
    3839        this.conflict = (Conflict<Way>) conflict;
    3940        this.mergedNodeList = mergedNodeList;
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12718 r12726  
    263263
    264264    /**
     265     * Constructs a new {@code DataSet} initially filled with the given primitives.
     266     * @param osmPrimitives primitives to add to this data set
     267     * @since 12726
     268     */
     269    public DataSet(OsmPrimitive... osmPrimitives) {
     270        this();
     271        beginUpdate();
     272        try {
     273            for (OsmPrimitive o : osmPrimitives) {
     274                addPrimitive(o);
     275            }
     276        } finally {
     277            endUpdate();
     278        }
     279    }
     280
     281    /**
    265282     * Adds a new data source.
    266283     * @param source data source to add
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r12725 r12726  
    106106     * @return the east north coordinates or {@code null} if #is
    107107     */
     108    @Override
    108109    public EastNorth getEastNorth() {
    109110        return getEastNorth(Main.getProjection());
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r12691 r12726  
    168168        mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
    169169        minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
    170         DataSet dataSet = Main.main.getEditDataSet();
     170        DataSet dataSet = Main.main != null ? Main.main.getEditDataSet() : null;
    171171        dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
    172172    }
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12718 r12726  
    197197    public static UndoRedoHandler undoRedo;
    198198
     199    private static final LayerChangeListener undoRedoCleaner = new LayerChangeListener() {
     200        @Override
     201        public void layerRemoving(LayerRemoveEvent e) {
     202            Layer layer = e.getRemovedLayer();
     203            if (layer instanceof OsmDataLayer) {
     204                undoRedo.clean(((OsmDataLayer) layer).data);
     205            }
     206        }
     207
     208        @Override
     209        public void layerOrderChanged(LayerOrderChangeEvent e) {
     210            // Do nothing
     211        }
     212
     213        @Override
     214        public void layerAdded(LayerAddEvent e) {
     215            // Do nothing
     216        }
     217    };
     218
    199219    /**
    200220     * Listener that sets the enabled state of undo/redo menu entries.
     
    220240        this.mainFrame = mainFrame;
    221241        undoRedo = super.undoRedo;
    222         getLayerManager().addLayerChangeListener(new LayerChangeListener() {
    223             @Override
    224             public void layerRemoving(LayerRemoveEvent e) {
    225                 Layer layer = e.getRemovedLayer();
    226                 if (layer instanceof OsmDataLayer) {
    227                     undoRedo.clean(((OsmDataLayer) layer).data);
    228                 }
    229             }
    230 
    231             @Override
    232             public void layerOrderChanged(LayerOrderChangeEvent e) {
    233                 // Do nothing
    234             }
    235 
    236             @Override
    237             public void layerAdded(LayerAddEvent e) {
    238                 // Do nothing
    239             }
    240         });
     242        getLayerManager().addLayerChangeListener(undoRedoCleaner);
    241243    }
    242244
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r12663 r12726  
    7777import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
    7878import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     79import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    7980import org.openstreetmap.josm.data.osm.search.SearchCompiler;
    8081import org.openstreetmap.josm.data.osm.search.SearchSetting;
    81 import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
    8282import org.openstreetmap.josm.data.preferences.StringProperty;
    8383import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r12718 r12726  
    103103     */
    104104    protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) {
    105         Relation editedRelation = new Relation(editor.getRelation());
     105        Relation originRelation = editor.getRelation();
     106        Relation editedRelation = new Relation(originRelation);
    106107        tagEditorModel.applyToPrimitive(editedRelation);
    107108        memberTableModel.applyToRelation(editedRelation);
    108         if (!editedRelation.hasEqualSemanticAttributes(editor.getRelation(), false)) {
    109             MainApplication.undoRedo.add(new ChangeCommand(editor.getRelation(), editedRelation));
     109        if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) {
     110            MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation));
    110111        }
    111112    }
  • trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java

    r12719 r12726  
    158158    class ChangesetReviewChangeListener implements ChangeListener {
    159159
    160         private final String key = "review_requested";
     160        private static final String KEY = "review_requested";
    161161
    162162        @Override
     
    164164            if (e.getSource() instanceof ChangesetReviewModel) {
    165165                boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested();
    166                 boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(key)).orElse(""));
     166                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(KEY)).orElse(""));
    167167                if (oldState != newState) {
    168                     setProperty(key, newState ? "yes" : null);
     168                    setProperty(KEY, newState ? "yes" : null);
    169169                }
    170170            }
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java

    r12641 r12726  
    1212import org.openstreetmap.josm.command.AddCommand;
    1313import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    9697        }
    9798
     99        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    98100        if (node == null) {
    99101            node = new Node(ll);
    100102            // Now execute the commands to add this node.
    101             MainApplication.undoRedo.add(new AddCommand(node));
     103            MainApplication.undoRedo.add(new AddCommand(ds, node));
    102104        }
    103105
    104         MainApplication.getLayerManager().getEditDataSet().setSelected(node);
     106        ds.setSelected(node);
    105107        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    106108            AutoScaleAction.autoScale("selection");
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java

    r12641 r12726  
    1919import org.openstreetmap.josm.command.SequenceCommand;
    2020import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.osm.DataSet;
    2122import org.openstreetmap.josm.data.osm.Node;
    2223import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    148149            nd = new Node(ll);
    149150            // Now execute the commands to add this node.
    150             commands.add(new AddCommand(nd));
     151            commands.add(new AddCommand(Main.main.getEditDataSet(), nd));
    151152            addedNodes.put(ll, nd);
    152153        }
     
    166167        }
    167168        allCoordinates.clear();
    168         commands.add(new AddCommand(way));
     169        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     170        commands.add(new AddCommand(ds, way));
    169171        MainApplication.undoRedo.add(new SequenceCommand(tr("Add way"), commands));
    170         MainApplication.getLayerManager().getEditDataSet().setSelected(way);
     172        ds.setSelected(way);
    171173        if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
    172174            AutoScaleAction.autoScale("selection");
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r12718 r12726  
    228228            newWay.setNodes(newNodes[pos]);
    229229
    230             cmds.add(new ChangeCommand(way, newWay));
     230            cmds.add(new ChangeCommand(dataset, way, newWay));
    231231        }
    232232
Note: See TracChangeset for help on using the changeset viewer.