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 direction is changed.
013 *
014 * @author nokutu
015 *
016 */
017public class CommandTurn extends StreetsideCommand {
018  private double ca;
019
020  /**
021   * Main constructor.
022   *
023   * @param images
024   *          Set of images that is turned.
025   * @param ca
026   *          How much the images turn.
027   */
028  public CommandTurn(Set<StreetsideAbstractImage> images, double ca) {
029    super(images);
030    this.ca = ca;
031  }
032
033  @Override
034  public void undo() {
035    for (StreetsideAbstractImage image : this.images) {
036      image.turn(-this.ca);
037      image.stopMoving();
038    }
039    StreetsideLayer.invalidateInstance();
040  }
041
042  @Override
043  public void redo() {
044    for (StreetsideAbstractImage image : this.images) {
045      image.turn(this.ca);
046      image.stopMoving();
047    }
048    StreetsideLayer.invalidateInstance();
049  }
050
051  @Override
052  public String toString() {
053    // TODO: trn( RRH
054    return trn("Turned {0} image", "Turned {0} images", this.images.size(),
055        this.images.size());
056  }
057
058  @Override
059  public void sum(StreetsideCommand command) {
060    if (command instanceof CommandTurn) {
061      this.ca += ((CommandTurn) command).ca;
062    }
063  }
064}