[7122] | 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;
|
---|
[9371] | 7 | import java.util.Objects;
|
---|
[7122] | 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 | }
|
---|
| 36 |
|
---|
| 37 | @Override
|
---|
| 38 | public void undoCommand() {
|
---|
| 39 | Main.map.mapView.getEditLayer().data.setSelected(oldSelection);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | @Override
|
---|
| 43 | public boolean executeCommand() {
|
---|
| 44 | oldSelection = Main.map.mapView.getEditLayer().data.getSelected();
|
---|
| 45 | Main.map.mapView.getEditLayer().data.setSelected(newSelection);
|
---|
| 46 | return true;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | @Override
|
---|
| 50 | public String getDescriptionText() {
|
---|
| 51 | int size = newSelection != null ? newSelection.size() : 0;
|
---|
| 52 | return trn("Selected {0} object", "Selected {0} objects", size, size);
|
---|
| 53 | }
|
---|
[8456] | 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public int hashCode() {
|
---|
[9371] | 57 | return Objects.hash(super.hashCode(), newSelection, oldSelection);
|
---|
[8456] | 58 | }
|
---|
| 59 |
|
---|
| 60 | @Override
|
---|
| 61 | public boolean equals(Object obj) {
|
---|
[9371] | 62 | if (this == obj) return true;
|
---|
| 63 | if (obj == null || getClass() != obj.getClass()) return false;
|
---|
| 64 | if (!super.equals(obj)) return false;
|
---|
| 65 | SelectCommand that = (SelectCommand) obj;
|
---|
| 66 | return Objects.equals(newSelection, that.newSelection) &&
|
---|
| 67 | Objects.equals(oldSelection, that.oldSelection);
|
---|
[8456] | 68 | }
|
---|
[7122] | 69 | }
|
---|