1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.command;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
5 |
|
---|
6 | import java.util.Collection;
|
---|
7 | import java.util.Objects;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.Main;
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Command that selects OSM primitives
|
---|
14 | *
|
---|
15 | * @author Landwirt
|
---|
16 | */
|
---|
17 | public class SelectCommand extends Command {
|
---|
18 |
|
---|
19 | /** the primitives to select when executing the command */
|
---|
20 | private final Collection<OsmPrimitive> newSelection;
|
---|
21 |
|
---|
22 | /** the selection before applying the new selection */
|
---|
23 | private Collection<OsmPrimitive> oldSelection;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new select command.
|
---|
27 | * @param newSelection the primitives to select when executing the command.
|
---|
28 | */
|
---|
29 | public SelectCommand(Collection<OsmPrimitive> newSelection) {
|
---|
30 | this.newSelection = newSelection;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
35 | // Do nothing
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public void undoCommand() {
|
---|
40 | Main.map.mapView.getEditLayer().data.setSelected(oldSelection);
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public boolean executeCommand() {
|
---|
45 | oldSelection = Main.map.mapView.getEditLayer().data.getSelected();
|
---|
46 | Main.map.mapView.getEditLayer().data.setSelected(newSelection);
|
---|
47 | return true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public String getDescriptionText() {
|
---|
52 | int size = newSelection != null ? newSelection.size() : 0;
|
---|
53 | return trn("Selected {0} object", "Selected {0} objects", size, size);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public int hashCode() {
|
---|
58 | return Objects.hash(super.hashCode(), newSelection, oldSelection);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public boolean equals(Object obj) {
|
---|
63 | if (this == obj) return true;
|
---|
64 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
65 | if (!super.equals(obj)) return false;
|
---|
66 | SelectCommand that = (SelectCommand) obj;
|
---|
67 | return Objects.equals(newSelection, that.newSelection) &&
|
---|
68 | Objects.equals(oldSelection, that.oldSelection);
|
---|
69 | }
|
---|
70 | }
|
---|