Ignore:
Timestamp:
2015-08-12T12:39:16+02:00 (9 years ago)
Author:
nokutu
Message:

Added command used to delete images, so it can be undone.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31460 r31487  
    2020public class MapillaryData {
    2121
    22   private final List<MapillaryAbstractImage> images;
     22  private List<MapillaryAbstractImage> images;
    2323  private MapillaryAbstractImage selectedImage;
    2424  /** The image under the cursor */
     
    6464  public synchronized void add(MapillaryAbstractImage image) {
    6565    add(image, true);
     66  }
     67
     68  /**
     69   * Removes an image from the database.
     70   *
     71   * @param image
     72   */
     73  public synchronized void delete(MapillaryAbstractImage image) {
     74    if (MapillaryMainDialog.getInstance().getImage() != null) {
     75      MapillaryMainDialog.getInstance().setImage(null);
     76      MapillaryMainDialog.getInstance().updateImage();
     77    }
     78    setSelectedImage(null);
     79    this.images.remove(image);
     80    if (image.getSequence() != null)
     81      image.getSequence().remove(image);
     82    if (Main.main != null)
     83      dataUpdated();
     84  }
     85
     86  /**
     87   * Removes a set of images from the database.
     88   *
     89   * @param images
     90   */
     91  public synchronized void delete(List<MapillaryAbstractImage> images) {
     92    for (MapillaryAbstractImage img : images)
     93      delete(img);
    6694  }
    6795
     
    359387
    360388  /**
     389   * Sets a new ArrayList object as the used set of images.
     390   *
     391   * @param images
     392   */
     393  public synchronized void setImages(List<MapillaryAbstractImage> images) {
     394    this.images = new ArrayList<>(images);
     395  }
     396
     397  /**
    361398   * Returns the amount of images contained by this object.
    362399   *
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31460 r31487  
    55
    66import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
     7import org.openstreetmap.josm.plugins.mapillary.commands.CommandDeleteImage;
     8import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    79import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    810import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
     
    4446import java.awt.Rectangle;
    4547import java.awt.TexturePaint;
     48import java.awt.event.ActionEvent;
    4649import java.awt.geom.AffineTransform;
    4750import java.awt.geom.Area;
     
    4952import java.awt.image.BufferedImage;
    5053
     54import javax.swing.AbstractAction;
    5155import javax.swing.ImageIcon;
    5256import javax.swing.Action;
    5357import javax.swing.Icon;
     58import javax.swing.JComponent;
     59import javax.swing.KeyStroke;
    5460
    5561import java.util.List;
     
    126132    }
    127133    createHatchTexture();
     134
     135    MapillaryMainDialog.getInstance()
     136        .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
     137        .put(KeyStroke.getKeyStroke("DELETE"), "MapillaryDel");
     138    MapillaryMainDialog.getInstance().getActionMap()
     139        .put("MapillaryDel", new DeleteImageAction());
     140
    128141    if (Main.main != null)
    129142      MapillaryData.dataUpdated();
     
    176189  public void destroy() {
    177190    setMode(null);
     191
    178192    AbstractMode.resetThread();
    179193    MapillaryDownloader.stopAll();
     
    593607    // Nothing
    594608  }
     609
     610  /**
     611   * Action used to delete images.
     612   *
     613   * @author nokutu
     614   *
     615   */
     616  private class DeleteImageAction extends AbstractAction {
     617
     618    private static final long serialVersionUID = -982809854631863962L;
     619
     620    @Override
     621    public void actionPerformed(ActionEvent e) {
     622      if (INSTANCE != null) {
     623        MapillaryRecord.getInstance().addCommand(
     624            new CommandDeleteImage(getData().getMultiSelectedImages()));
     625      }
     626    }
     627  }
    595628}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java

    r31479 r31487  
    33import static org.openstreetmap.josm.tools.I18n.trn;
    44
    5 import java.util.ArrayList;
    65import java.util.List;
    76
     
    3130  public CommandMoveImage(List<MapillaryAbstractImage> images, double x,
    3231      double y) {
    33     this.images = new ArrayList<MapillaryAbstractImage>(images);
     32    super(images);
    3433    this.x = x;
    3534    this.y = y;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java

    r31479 r31487  
    33import static org.openstreetmap.josm.tools.I18n.trn;
    44
    5 import java.util.ArrayList;
    65import java.util.List;
    76
     
    2726   */
    2827  public CommandTurnImage(List<MapillaryAbstractImage> images, double ca) {
    29     this.images = new ArrayList<MapillaryAbstractImage>(images);
     28    super(images);
    3029    this.ca = ca;
    3130  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryCommand.java

    r31445 r31487  
    11package org.openstreetmap.josm.plugins.mapillary.commands;
    22
     3import java.util.ArrayList;
    34import java.util.List;
    45
     
    1314public abstract class MapillaryCommand {
    1415  protected List<MapillaryAbstractImage> images;
     16
     17  /**
     18   * Main constructor.
     19   *
     20   * @param images
     21   *          The images that are affected by the command.
     22   */
     23  public MapillaryCommand(List<MapillaryAbstractImage> images) {
     24    this.images = new ArrayList<MapillaryAbstractImage>(images);
     25  }
    1526
    1627  /**
     
    2839   * they are summed in order to reduce them to just one command.
    2940   *
    30    * @param command The command to be summed to last command.
     41   * @param command
     42   *          The command to be summed to last command.
    3143   */
    3244  public abstract void sum(MapillaryCommand command);
     
    3951      image.isModified = (image.tempLatLon == image.latLon || image.tempCa == image.ca);
    4052  }
     53
     54  @Override
     55  public abstract String toString();
    4156}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java

    r31479 r31487  
    6969   */
    7070  public void addCommand(MapillaryCommand command) {
     71    if (command instanceof MapillaryExecutableCommand)
     72      ((MapillaryExecutableCommand) command).execute();
    7173    // Checks if it is a continuation of last command
    7274    if (this.position != -1) {
Note: See TracChangeset for help on using the changeset viewer.