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 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Command that selects OSM primitives
|
---|
13 | *
|
---|
14 | * @author Landwirt
|
---|
15 | */
|
---|
16 | public class SelectCommand extends Command {
|
---|
17 |
|
---|
18 | /** the primitives to select when executing the command */
|
---|
19 | private final Collection<OsmPrimitive> newSelection;
|
---|
20 |
|
---|
21 | /** the selection before applying the new selection */
|
---|
22 | private Collection<OsmPrimitive> oldSelection;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new select command.
|
---|
26 | * @param newSelection the primitives to select when executing the command.
|
---|
27 | */
|
---|
28 | public SelectCommand(Collection<OsmPrimitive> newSelection) {
|
---|
29 | this.newSelection = newSelection;
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) {
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void undoCommand() {
|
---|
38 | Main.map.mapView.getEditLayer().data.setSelected(oldSelection);
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public boolean executeCommand() {
|
---|
43 | oldSelection = Main.map.mapView.getEditLayer().data.getSelected();
|
---|
44 | Main.map.mapView.getEditLayer().data.setSelected(newSelection);
|
---|
45 | return true;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public String getDescriptionText() {
|
---|
50 | int size = newSelection != null ? newSelection.size() : 0;
|
---|
51 | return trn("Selected {0} object", "Selected {0} objects", size, size);
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public int hashCode() {
|
---|
56 | final int prime = 31;
|
---|
57 | int result = super.hashCode();
|
---|
58 | result = prime * result + ((newSelection == null) ? 0 : newSelection.hashCode());
|
---|
59 | result = prime * result + ((oldSelection == null) ? 0 : oldSelection.hashCode());
|
---|
60 | return result;
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public boolean equals(Object obj) {
|
---|
65 | if (this == obj)
|
---|
66 | return true;
|
---|
67 | if (!super.equals(obj))
|
---|
68 | return false;
|
---|
69 | if (getClass() != obj.getClass())
|
---|
70 | return false;
|
---|
71 | SelectCommand other = (SelectCommand) obj;
|
---|
72 | if (newSelection == null) {
|
---|
73 | if (other.newSelection != null)
|
---|
74 | return false;
|
---|
75 | } else if (!newSelection.equals(other.newSelection))
|
---|
76 | return false;
|
---|
77 | if (oldSelection == null) {
|
---|
78 | if (other.oldSelection != null)
|
---|
79 | return false;
|
---|
80 | } else if (!oldSelection.equals(other.oldSelection))
|
---|
81 | return false;
|
---|
82 | return true;
|
---|
83 | }
|
---|
84 | }
|
---|