001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.plugins.streetside.history.commands;
003
004import static org.openstreetmap.josm.tools.I18n.trn;
005
006import java.util.Set;
007
008import org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage;
009import org.openstreetmap.josm.plugins.streetside.StreetsideLayer;
010
011/**
012 * Command created when an image's position is changed.
013 *
014 * @author nokutu
015 *
016 */
017public class CommandMove extends StreetsideCommand {
018  private double x;
019  private double y;
020
021  /**
022   * Main constructor.
023   *
024   * @param images
025   *          Set of images that are going to be moved.
026   * @param x
027   *          How much the x coordinate increases.
028   * @param y
029   *          How much the y coordinate increases.
030   */
031  public CommandMove(Set<StreetsideAbstractImage> images, double x,
032                     double y) {
033    super(images);
034    this.x = x;
035    this.y = y;
036  }
037
038  @Override
039  public void undo() {
040    for (StreetsideAbstractImage image : this.images) {
041      image.move(-this.x, -this.y);
042      image.stopMoving();
043    }
044    StreetsideLayer.invalidateInstance();
045  }
046
047  @Override
048  public void redo() {
049    for (StreetsideAbstractImage image : this.images) {
050      image.move(this.x, this.y);
051      image.stopMoving();
052    }
053    StreetsideLayer.invalidateInstance();
054  }
055
056  @Override
057  public String toString() {
058    // TODO: trn( RRH
059    return trn("Moved {0} image", "Moved {0} images", this.images.size(),
060        this.images.size());
061  }
062
063  @Override
064  public void sum(StreetsideCommand command) {
065    if (command instanceof CommandMove) {
066      this.x += ((CommandMove) command).x;
067      this.y += ((CommandMove) command).y;
068    }
069  }
070}