Changeset 31490 in osm for applications/editors


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

Added several new commands to improve history record system.

Location:
applications/editors/josm/plugins/mapillary
Files:
3 added
8 edited
9 moved

Legend:

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

    r31487 r31490  
    7171   * @param image
    7272   */
    73   public synchronized void delete(MapillaryAbstractImage image) {
     73  public synchronized void remove(MapillaryAbstractImage image) {
    7474    if (MapillaryMainDialog.getInstance().getImage() != null) {
    7575      MapillaryMainDialog.getInstance().setImage(null);
     
    8989   * @param images
    9090   */
    91   public synchronized void delete(List<MapillaryAbstractImage> images) {
     91  public synchronized void remove(List<MapillaryAbstractImage> images) {
    9292    for (MapillaryAbstractImage img : images)
    93       delete(img);
     93      remove(img);
    9494  }
    9595
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31488 r31490  
    55
    66import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
    7 import org.openstreetmap.josm.plugins.mapillary.commands.CommandDeleteImage;
    8 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    97import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    108import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    119import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     10import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     11import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
    1212import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode;
    1313import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
     
    623623      if (INSTANCE != null) {
    624624        MapillaryRecord.getInstance().addCommand(
    625             new CommandDeleteImage(getData().getMultiSelectedImages()));
     625            new CommandDelete(getData().getMultiSelectedImages()));
    626626      }
    627627    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31456 r31490  
    77import java.io.File;
    88import java.io.IOException;
     9import java.util.ArrayList;
     10import java.util.List;
    911
    1012import javax.swing.JFileChooser;
     
    2224import org.openstreetmap.josm.actions.JosmAction;
    2325import org.openstreetmap.josm.data.coor.LatLon;
     26import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    2427import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2528import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    2629import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     30import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     31import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandImport;
    2732import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2833import org.openstreetmap.josm.tools.Shortcut;
     
    7075    this.chooser.setMultiSelectionEnabled(true);
    7176    if (this.chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
     77      List<MapillaryAbstractImage> images = new ArrayList<>();
    7278      for (int i = 0; i < this.chooser.getSelectedFiles().length; i++) {
    7379        File file = this.chooser.getSelectedFiles()[i];
     
    8591            try {
    8692              if (extension.equals("jpg") || extension.equals("jpeg"))
    87                 MapillaryLayer.getInstance().getData()
    88                     .add(readJPG(file.listFiles()[j]));
     93                images.add(readJPG(file.listFiles()[j]));
    8994
    9095              else if (extension.equals("png"))
    91                 MapillaryLayer.getInstance().getData()
    92                     .add(readPNG(file.listFiles()[j]));
     96                images.add(readPNG(file.listFiles()[j]));
    9397            } catch (ImageReadException | IOException | NullPointerException e1) {
    9498              Main.error(e1);
     
    101105                  .equals(".jpeg")) {
    102106            try {
    103               MapillaryLayer.getInstance().getData().add(readJPG(file));
     107              images.add(readJPG(file));
    104108            } catch (ImageReadException ex) {
    105109              Main.error(ex);
     
    109113          } else if (file.getPath().substring(file.getPath().length() - 4)
    110114              .equals(".png")) {
    111             MapillaryLayer.getInstance().getData().add(readPNG(file));
     115            images.add(readPNG(file));
    112116          }
    113117        }
    114118      }
     119      MapillaryRecord.getInstance().addCommand(new CommandImport(images));
    115120      MapillaryLayer.getInstance().showAllPictures();
    116 
    117121    }
    118122  }
     
    154158      double caValue = 0;
    155159      if (lat.getValue() instanceof RationalNumber[])
    156         latValue = MapillaryUtils.degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref
    157             .getValue().toString());
     160        latValue = MapillaryUtils.degMinSecToDouble(
     161            (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
    158162      if (lon.getValue() instanceof RationalNumber[])
    159         lonValue = MapillaryUtils.degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref
    160             .getValue().toString());
     163        lonValue = MapillaryUtils.degMinSecToDouble(
     164            (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    161165      if (ca != null && ca.getValue() instanceof RationalNumber)
    162166        caValue = ((RationalNumber) ca.getValue()).doubleValue();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31473 r31490  
    1010import java.util.Comparator;
    1111import java.util.LinkedList;
     12import java.util.List;
    1213
    1314import javax.swing.JFileChooser;
     
    2930import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    3031import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
     32import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     33import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandImport;
    3134import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    3235import org.openstreetmap.josm.tools.Shortcut;
     
    4447  private JFileChooser chooser;
    4548
    46   private LinkedList<MapillaryImportedImage> images;
     49  private List<MapillaryAbstractImage> images;
    4750
    4851  /**
     
    111114      }
    112115      joinImages();
    113     }
    114 
     116      MapillaryRecord.getInstance().addCommand(new CommandImport(this.images));
     117    }
    115118    MapillaryLayer.getInstance().showAllPictures();
    116119  }
     
    161164      MapillaryImportedImage image = new MapillaryImportedImage(latValue,
    162165          lonValue, caValue, file, datetimeOriginal.getStringValue());
    163       MapillaryLayer.getInstance().getData().add(image);
    164       image.getCapturedAt();
    165 
    166166      this.images.add(image);
    167167    }
     
    174174    Collections.sort(this.images, new MapillaryEpochComparator());
    175175    MapillarySequence seq = new MapillarySequence();
    176     for (MapillaryImportedImage img : this.images) {
     176    for (MapillaryAbstractImage img : this.images) {
    177177      seq.add(img);
    178178      img.setSequence(seq);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r31445 r31490  
    2222import org.openstreetmap.josm.gui.SideButton;
    2323import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    24 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryCommand;
    25 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    26 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecordListener;
     24import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     25import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecordListener;
     26import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand;
    2727import org.openstreetmap.josm.tools.GBC;
    2828import org.openstreetmap.josm.tools.ImageProvider;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history;
    22
    33import java.util.ArrayList;
    44
    55import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     6import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand;
     7import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryExecutableCommand;
    68
    79/**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecordListener.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history;
    22
    33/**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandDelete.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import static org.openstreetmap.josm.tools.I18n.trn;
     
    1313 *
    1414 */
    15 public class CommandDeleteImage extends MapillaryExecutableCommand {
     15public class CommandDelete extends MapillaryExecutableCommand {
    1616
    1717  private HashMap<MapillaryAbstractImage, Integer> changesHash;
     
    2020   * @param images
    2121   */
    22   public CommandDeleteImage(List<MapillaryAbstractImage> images) {
     22  public CommandDelete(List<MapillaryAbstractImage> images) {
    2323    super(images);
    2424    this.changesHash = new HashMap<>();
     
    3434    for (MapillaryAbstractImage img : this.images) {
    3535      this.changesHash.put(img, img.getSequence().getImages().indexOf(img));
    36       MapillaryLayer.getInstance().getData().delete(img);
     36      MapillaryLayer.getInstance().getData().remove(img);
    3737    }
    3838  }
     
    5555  @Override
    5656  public void redo() {
    57     MapillaryLayer.getInstance().getData().delete(this.images);
     57    MapillaryLayer.getInstance().getData().remove(this.images);
    5858  }
    5959}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandJoin.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandMove.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import static org.openstreetmap.josm.tools.I18n.trn;
     
    1414 *
    1515 */
    16 public class CommandMoveImage extends MapillaryCommand {
     16public class CommandMove extends MapillaryCommand {
    1717  private double x;
    1818  private double y;
     
    2828   *          How much the y coordinate increases.
    2929   */
    30   public CommandMoveImage(List<MapillaryAbstractImage> images, double x,
     30  public CommandMove(List<MapillaryAbstractImage> images, double x,
    3131      double y) {
    3232    super(images);
     
    6565  @Override
    6666  public void sum(MapillaryCommand command) {
    67     if (command instanceof CommandMoveImage) {
    68       this.x += ((CommandMoveImage) command).x;
    69       this.y += ((CommandMoveImage) command).y;
     67    if (command instanceof CommandMove) {
     68      this.x += ((CommandMove) command).x;
     69      this.y += ((CommandMove) command).y;
    7070    }
    7171  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandTurn.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import static org.openstreetmap.josm.tools.I18n.trn;
     
    1414 *
    1515 */
    16 public class CommandTurnImage extends MapillaryCommand {
     16public class CommandTurn extends MapillaryCommand {
    1717  private double ca;
    1818
     
    2525   *          How much the images turn.
    2626   */
    27   public CommandTurnImage(List<MapillaryAbstractImage> images, double ca) {
     27  public CommandTurn(List<MapillaryAbstractImage> images, double ca) {
    2828    super(images);
    2929    this.ca = ca;
     
    6060  @Override
    6161  public void sum(MapillaryCommand command) {
    62     if (command instanceof CommandTurnImage) {
    63       this.ca += ((CommandTurnImage) command).ca;
     62    if (command instanceof CommandTurn) {
     63      this.ca += ((CommandTurn) command).ca;
    6464    }
    6565  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandUnjoin.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import static org.openstreetmap.josm.tools.I18n.tr;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/MapillaryCommand.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import java.util.ArrayList;
     
    1313 */
    1414public abstract class MapillaryCommand {
    15   protected List<MapillaryAbstractImage> images;
     15  /** Set of {@link MapillaryAbstractImage} objects affected by the command */
     16  public List<MapillaryAbstractImage> images;
    1617
    1718  /**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/MapillaryExecutableCommand.java

    r31489 r31490  
    1 package org.openstreetmap.josm.plugins.mapillary.commands;
     1package org.openstreetmap.josm.plugins.mapillary.history.commands;
    22
    33import java.util.List;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java

    r31489 r31490  
    1515import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1616import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    17 import org.openstreetmap.josm.plugins.mapillary.commands.CommandJoin;
    18 import org.openstreetmap.josm.plugins.mapillary.commands.CommandUnjoin;
    19 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
     17import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     18import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandJoin;
     19import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandUnjoin;
    2020
    2121/**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31460 r31490  
    1717import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    1818import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    19 import org.openstreetmap.josm.plugins.mapillary.commands.CommandMoveImage;
    20 import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage;
    21 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord;
    2219import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     20import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     21import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandMove;
     22import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandTurn;
    2323
    2424/**
     
    134134      double from = this.data.getSelectedImage().getTempCa();
    135135      double to = this.data.getSelectedImage().getCa();
    136       this.record.addCommand(new CommandTurnImage(this.data.getMultiSelectedImages(), to
     136      this.record.addCommand(new CommandTurn(this.data.getMultiSelectedImages(), to
    137137          - from));
    138138    } else if (this.data.getSelectedImage().getTempLatLon() != this.data
     
    140140      LatLon from = this.data.getSelectedImage().getTempLatLon();
    141141      LatLon to = this.data.getSelectedImage().getLatLon();
    142       this.record.addCommand(new CommandMoveImage(this.data.getMultiSelectedImages(), to
     142      this.record.addCommand(new CommandMove(this.data.getMultiSelectedImages(), to
    143143          .getX() - from.getX(), to.getY() - from.getY()));
    144144    }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java

    r31482 r31490  
    1010import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    1111import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
     12import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     13import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandMove;
     14import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandTurn;
     15import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand;
    1216
    1317/**
     
    4145  @Test
    4246  public void commandTest() {
    43     MapillaryCommand cmd12 = new CommandMoveImage(
     47    MapillaryCommand cmd12 = new CommandMove(
    4448        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
    4549        0.1, 0.1);
    46     MapillaryCommand cmd23 = new CommandMoveImage(
     50    MapillaryCommand cmd23 = new CommandMove(
    4751        Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 }),
    4852        0.1, 0.1);
    49     MapillaryCommand cmd13 = new CommandMoveImage(
     53    MapillaryCommand cmd13 = new CommandMove(
    5054        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img3 }),
    5155        0.1, 0.1);
    52     MapillaryCommand cmd1 = new CommandMoveImage(
     56    MapillaryCommand cmd1 = new CommandMove(
    5357        Arrays.asList(new MapillaryAbstractImage[] { this.img1 }),
    5458        0.1, 0.1);
    55     MapillaryCommand cmd31 = new CommandMoveImage(
     59    MapillaryCommand cmd31 = new CommandMove(
    5660        Arrays.asList(new MapillaryAbstractImage[] { this.img3, this.img1 }),
    5761        0.2, 0.2);
     
    98102  @Test
    99103  public void commandMoveTest() {
    100     CommandMoveImage cmd1 = new CommandMoveImage(
     104    CommandMove cmd1 = new CommandMove(
    101105        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
    102106        0.1, 0.1);
    103     CommandMoveImage cmd2 = new CommandMoveImage(
     107    CommandMove cmd2 = new CommandMove(
    104108        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
    105109        0.1, 0.1);
     
    132136  @Test
    133137  public void commandTurnTest() {
    134     CommandTurnImage cmd1 = new CommandTurnImage(
     138    CommandTurn cmd1 = new CommandTurn(
    135139        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
    136140        0.2);
    137     CommandTurnImage cmd2 = new CommandTurnImage(
     141    CommandTurn cmd2 = new CommandTurn(
    138142        Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 }),
    139143        0.1);
Note: See TracChangeset for help on using the changeset viewer.