Changeset 32064 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-02-11T23:17:18+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Add ValidationUtil for validating sequence-keys and image-keys

Also some public attributes are now private with getters/setters where necessary.

Location:
applications/editors/josm/plugins/mapillary
Files:
1 added
10 edited

Legend:

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

    r32033 r32064  
    2828  private MapillarySequence sequence;
    2929  /** Position of the picture. */
    30   public final LatLon latLon;
     30  protected LatLon latLon;
    3131  /** Direction of the picture. */
    32   public final double ca;
     32  protected double ca;
    3333  /** Temporal position of the picture until it is uploaded. */
    3434  public LatLon tempLatLon;
     
    218218  }
    219219
     220  public void setCa(final double ca) {
     221    this.ca = ca;
     222  }
     223
    220224  /**
    221225   * Sets the Epoch time when the picture was captured.
     
    225229  public void setCapturedAt(final long capturedAt) {
    226230    this.capturedAt = capturedAt;
     231  }
     232
     233  public void setLatLon(final LatLon latLon) {
     234    if (latLon != null) {
     235      this.latLon = latLon;
     236    }
    227237  }
    228238
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31989 r32064  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.data.Bounds;
     13import org.openstreetmap.josm.data.coor.LatLon;
    1314import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
    1415import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     16import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    1517
    1618/**
     
    2224 */
    2325public class MapillaryData {
    24 
    2526  private final Set<MapillaryAbstractImage> images;
    2627  /**
     
    3940   * Listeners of the class.
    4041   */
    41   private final CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
     42  private final List<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
    4243  /**
    4344   * The bounds of the areas for which the pictures have been downloaded.
    4445   */
    45   public List<Bounds> bounds;
     46  private final List<Bounds> bounds;
    4647
    4748  /**
     
    5253    this.multiSelectedImages = Collections.newSetFromMap(new ConcurrentHashMap<MapillaryAbstractImage, Boolean>());
    5354    this.selectedImage = null;
     55    this.bounds = new CopyOnWriteArrayList<>();
    5456
    5557    // Adds the basic set of listeners.
     
    8284      this.images.add(image);
    8385    }
    84     if (update)
     86    if (update) {
    8587      dataUpdated();
     88    }
    8689    fireImagesAdded();
    8790  }
     
    151154    }
    152155    Main.map.mapView.repaint();
     156  }
     157
     158  public List<Bounds> getBounds() {
     159    return bounds;
    153160  }
    154161
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r32033 r32064  
    66
    77import org.openstreetmap.josm.data.coor.LatLon;
     8import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
     9import org.openstreetmap.josm.plugins.mapillary.utils.ValidationUtil;
    810
    911/**
     
    3335  public MapillaryImage(final String key, final LatLon latLon, final double ca) {
    3436    super(latLon, ca);
     37    ValidationUtil.throwExceptionForInvalidImgKey(key, true);
    3538    this.key = key;
    3639  }
     
    105108  @Override
    106109  public String toString() {
    107     return "Image[key=" + this.key + ";lat=" + this.latLon.lat() + ";lon="
    108         + this.latLon.lon() + ";ca=" + this.ca + ']';
     110    return String.format(
     111      "Image[key=%s,lat=%f,lon=%f,ca=%f,location=%s,user=%s,capturedAt=%d]",
     112      key, latLon.lat(), latLon.lon(), ca, location, user, capturedAt
     113    );
    109114  }
    110115
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r32039 r32064  
    2020import java.awt.image.AffineTransformOp;
    2121import java.awt.image.BufferedImage;
    22 import java.util.concurrent.CopyOnWriteArrayList;
    2322
    2423import javax.swing.AbstractAction;
     
    101100    super(tr("Mapillary Images"));
    102101    this.data = new MapillaryData();
    103     this.data.bounds = new CopyOnWriteArrayList<>();
    104102  }
    105103
     
    291289      // paint remainder
    292290      g.setPaint(this.hatched);
    293       g.fill(MapViewGeometryUtil.getNonDownloadedArea(mv, this.data.bounds));
     291      g.fill(MapViewGeometryUtil.getNonDownloadedArea(mv, this.data.getBounds()));
    294292    }
    295293
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r32039 r32064  
    22package org.openstreetmap.josm.plugins.mapillary;
    33
    4 import java.util.ArrayList;
    54import java.util.List;
    65import java.util.concurrent.CopyOnWriteArrayList;
     6
     7import org.openstreetmap.josm.plugins.mapillary.utils.ValidationUtil;
    78
    89/**
     
    3940   * @param key       The unique identifier of the sequence.
    4041   * @param createdAt The date the sequence was created.
     42   * @throws IllegalArgumentException if the key is invalid
     43   *           according to {@link ValidationUtil#validateSequenceKey(String)}
    4144   */
    4245  public MapillarySequence(String key, long createdAt) {
     46    ValidationUtil.throwExceptionForInvalidSeqKey(key, true);
     47
    4348    this.images = new CopyOnWriteArrayList<>();
    4449    this.key = key;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r32038 r32064  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.awt.*;
     6import java.awt.FlowLayout;
     7import java.awt.GridBagConstraints;
     8import java.awt.GridBagLayout;
    79import java.awt.event.ActionEvent;
    810import java.awt.event.KeyEvent;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r31987 r32064  
    104104    if (isViewDownloaded(view))
    105105      return;
    106     MapillaryLayer.getInstance().getData().bounds.add(view);
     106    MapillaryLayer.getInstance().getData().getBounds().add(view);
    107107    getImages(view);
    108108  }
     
    139139   */
    140140  private static boolean isInBounds(LatLon latlon) {
    141     for (Bounds bounds : MapillaryLayer.getInstance().getData().bounds) {
     141    for (Bounds bounds : MapillaryLayer.getInstance().getData().getBounds()) {
    142142      if (bounds.contains(latlon))
    143143        return true;
     
    162162    for (Bounds bounds : Main.map.mapView.getEditLayer().data
    163163        .getDataSourceBounds()) {
    164       if (!layer.getData().bounds.contains(bounds)) {
    165         layer.getData().bounds.add(bounds);
     164      if (!layer.getData().getBounds().contains(bounds)) {
     165        layer.getData().getBounds().add(bounds);
    166166        MapillaryDownloader.getImages(bounds.getMin(), bounds.getMax());
    167167      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThread.java

    r32033 r32064  
    127127
    128128  private static boolean isInside(MapillaryAbstractImage image) {
    129     for (Bounds b : MapillaryLayer.getInstance().getData().bounds) {
     129    for (Bounds b : MapillaryLayer.getInstance().getData().getBounds()) {
    130130      if (b.contains(image.getLatLon())) {
    131131        return true;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryURL.java

    r31969 r32064  
    2626  /**
    2727   * Gives you the URL for the online editor of a specific mapillary image.
    28    * @param key the key of the image to which you want to link
     28   * @param imgKey the key of the image to which you want to link
    2929   * @return the URL of the online editor for the image with the given image key
     30   * @throws IllegalArgumentException if the image key is <code>null</code> or invalid according
     31   *           to {@link ValidationUtil#validateImageKey(String)}
    3032   */
    31   public static URL browseEditURL(String key) {
    32     if (key == null || !key.matches("[a-zA-Z0-9\\-_]{22}")) {
    33       throw new IllegalArgumentException("Invalid image key");
    34     }
    35     return string2URL(BASE_WEBSITE_URL + "map/e/" + key);
     33  public static URL browseEditURL(String imgKey) {
     34    ValidationUtil.throwExceptionForInvalidImgKey(imgKey, false);
     35    return string2URL(BASE_WEBSITE_URL + "map/e/" + imgKey);
    3636  }
    3737
     
    4040   * @param key the key of the image to which you want to link
    4141   * @return the URL of the online viewer for the image with the given image key
     42   * @throws IllegalArgumentException if the image key is <code>null</code> or invalid according
     43   *           to {@link ValidationUtil#validateImageKey(String)}
    4244   */
    4345  public static URL browseImageURL(String key) {
    44     if (key == null || !key.matches("[a-zA-Z0-9\\-_]{22}")) {
    45       throw new IllegalArgumentException("Invalid image key");
    46     }
     46    ValidationUtil.throwExceptionForInvalidImgKey(key, false);
    4747    return string2URL(BASE_WEBSITE_URL + "map/im/" + key);
    4848  }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThreadTest.java

    r31833 r32064  
    4040    ExecutorService ex = Executors.newSingleThreadExecutor();
    4141    Bounds bounds = new Bounds(minLatLon, maxLatLon);
    42     MapillaryLayer.getInstance().getData().bounds.add(new Bounds(minLatLon,
     42    MapillaryLayer.getInstance().getData().getBounds().add(new Bounds(minLatLon,
    4343        maxLatLon));
    4444
Note: See TracChangeset for help on using the changeset viewer.