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 : images) { 041 image.move(-x, -y); 042 image.stopMoving(); 043 } 044 StreetsideLayer.invalidateInstance(); 045 } 046 047 @Override 048 public void redo() { 049 for (StreetsideAbstractImage image : images) { 050 image.move(x, y); 051 image.stopMoving(); 052 } 053 StreetsideLayer.invalidateInstance(); 054 } 055 056 @Override 057 public String toString() { 058 return trn("Moved {0} image", "Moved {0} images", images.size(), 059 images.size()); 060 } 061 062 @Override 063 public void sum(StreetsideCommand command) { 064 if (command instanceof CommandMove) { 065 x += ((CommandMove) command).x; 066 y += ((CommandMove) command).y; 067 } 068 } 069}