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 | }
|
---|