source: josm/trunk/src/org/openstreetmap/josm/command/SelectCommand.java@ 10599

Last change on this file since 10599 was 10364, checked in by stoecker, 8 years ago

gsoc-core - patch by Michael Zangl - see #12953 - remove deprecation usage

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.command;
3
4import static org.openstreetmap.josm.tools.I18n.trn;
5
6import java.util.Collection;
7import java.util.Objects;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11
12/**
13 * Command that selects OSM primitives
14 *
15 * @author Landwirt
16 */
17public 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.getLayerManager().getEditLayer().data.setSelected(oldSelection);
41 }
42
43 @Override
44 public boolean executeCommand() {
45 oldSelection = Main.getLayerManager().getEditLayer().data.getSelected();
46 Main.getLayerManager().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}
Note: See TracBrowser for help on using the repository browser.