001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.command; 003 004import static org.openstreetmap.josm.tools.I18n.trn; 005 006import java.util.Collection; 007 008import org.openstreetmap.josm.Main; 009import org.openstreetmap.josm.data.osm.OsmPrimitive; 010 011/** 012 * Command that selects OSM primitives 013 * 014 * @author Landwirt 015 */ 016public class SelectCommand extends Command { 017 018 /** the primitives to select when executing the command */ 019 private final Collection<OsmPrimitive> newSelection; 020 021 /** the selection before applying the new selection */ 022 private Collection<OsmPrimitive> oldSelection; 023 024 /** 025 * Constructs a new select command. 026 * @param newSelection the primitives to select when executing the command. 027 */ 028 public SelectCommand(Collection<OsmPrimitive> newSelection) { 029 this.newSelection = newSelection; 030 } 031 032 @Override 033 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) { 034 } 035 036 @Override 037 public void undoCommand() { 038 Main.map.mapView.getEditLayer().data.setSelected(oldSelection); 039 } 040 041 @Override 042 public boolean executeCommand() { 043 oldSelection = Main.map.mapView.getEditLayer().data.getSelected(); 044 Main.map.mapView.getEditLayer().data.setSelected(newSelection); 045 return true; 046 } 047 048 @Override 049 public String getDescriptionText() { 050 int size = newSelection != null ? newSelection.size() : 0; 051 return trn("Selected {0} object", "Selected {0} objects", size, size); 052 } 053}