Ignore:
Timestamp:
2015-08-21T20:44:15+02:00 (9 years ago)
Author:
nokutu
Message:

Minor code enhances.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
15 edited

Legend:

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

    r31496 r31513  
    11package org.openstreetmap.josm.plugins.mapillary;
    22
    3 import java.util.Date;
    4 import java.text.ParseException;
    53import java.text.SimpleDateFormat;
    64import java.util.Calendar;
     5import java.util.Date;
    76import java.util.concurrent.locks.Lock;
    87import java.util.concurrent.locks.ReentrantLock;
     
    2524   * images to prevent concurrency problems.
    2625   */
    27   public static Lock LOCK = new ReentrantLock();
     26  public static final Lock LOCK = new ReentrantLock();
    2827
    2928  /** The time the image was captured, in Epoch format. */
     
    3534  /** Direction of the picture. */
    3635  public final double ca;
    37   /** If the image has been modified from its initial values. */
    38   public boolean isModified = false;
    3936  /** Temporal position of the picture until it is uploaded. */
    4037  public LatLon tempLatLon;
     
    5148   */
    5249  protected double movingCa;
     50  /** Whether the image must be drown in the map or not */
    5351  private boolean visible;
    5452
    5553  /**
    56    * Main constructor of the class.
     54   * Creates a new object in the given position and with the given direction.
    5755   *
    5856   * @param lat
     
    7472
    7573  /**
    76    * Returns whether the object has been modified or not.
    77    *
    78    * @return true if the object has been modified; false otherwise.
    79    */
    80   public boolean isModified() {
    81     return this.isModified;
    82   }
    83 
    84   /**
    85    * Returns a LatLon object containing the current coordinates of the object.
    86    * When you are dragging the image this changes.
    87    *
    88    * @return The LatLon object with the position of the object.
    89    */
    90   public LatLon getLatLon() {
    91     return this.movingLatLon;
    92   }
    93 
    94   /**
    95    * Returns whether the image is visible on the map or not.
    96    *
    97    * @return True if the image is visible; false otherwise.
    98    */
    99   public boolean isVisible() {
    100     return this.visible;
    101   }
    102 
    103   /**
    104    * Set's whether the image should be visible on the map or not.
    105    *
    106    * @param visible
    107    *          true if the image is set to be visible; false otherwise.
    108    */
    109   public void setVisible(boolean visible) {
    110     this.visible = visible;
    111   }
    112 
    113   /**
    114    * Returns the last fixed coordinates of the object.
    115    *
    116    * @return A LatLon object containing.
    117    */
    118   public LatLon getTempLatLon() {
    119     return this.tempLatLon;
    120   }
    121 
    122   /**
    123    * Moves the image temporally to another position
    124    *
    125    * @param x
    126    *          The movement of the image in longitude units.
    127    * @param y
    128    *          The movement of the image in latitude units.
    129    */
    130   public void move(double x, double y) {
    131     this.movingLatLon = new LatLon(this.tempLatLon.getY() + y,
    132         this.tempLatLon.getX() + x);
    133     this.isModified = true;
    134   }
    135 
    136   /**
    137    * Turns the image direction.
    138    *
    139    * @param ca
    140    *          The angle the image is moving.
    141    */
    142   public void turn(double ca) {
    143     this.movingCa = this.tempCa + ca;
    144     this.isModified = true;
    145   }
    146 
    147   /**
    148    * Called when the mouse button is released, meaning that the picture has
    149    * stopped being dragged.
    150    */
    151   public void stopMoving() {
    152     this.tempLatLon = this.movingLatLon;
    153     this.tempCa = this.movingCa;
    154   }
    155 
    156   /**
    15774   * Returns the direction towards the image has been taken.
    15875   *
     
    16481
    16582  /**
    166    * Returns the last fixed direction of the object.
    167    *
    168    * @return The last fixed direction of the object. 0 means north.
    169    */
    170   public double getTempCa() {
    171     return this.tempCa;
     83   * Returns the Epoch time when the image was captured.
     84   *
     85   * @return The long containing the Epoch time when the image was captured.
     86   */
     87  public long getCapturedAt() {
     88    return this.capturedAt;
    17289  }
    17390
     
    193110
    194111  /**
    195    * Sets the Epoch time when the picture was captured.
    196    *
    197    * @param capturedAt
    198    *          Epoch time when the image was captured.
    199    */
    200   public void setCapturedAt(long capturedAt) {
    201     this.capturedAt = capturedAt;
    202   }
    203 
    204   /**
    205    * Returns the Epoch time when the image was captured.
    206    *
    207    * @return The long containing the Epoch time when the image was captured.
    208    */
    209   public long getCapturedAt() {
    210     return this.capturedAt;
    211   }
    212 
    213   /**
    214112   * Returns the date the picture was taken in the given format.
    215113   *
     
    228126
    229127  /**
    230    * Parses a string with a given format and returns the Epoch time.
    231    *
    232    * @param date
    233    *          The string containing the date.
    234    * @param format
    235    *          The format of the date.
    236    * @return The date in Epoch format.
    237    * @throws ParseException
    238    */
    239   public static long getEpoch(String date, String format) throws ParseException {
    240 
    241     SimpleDateFormat formatter = new SimpleDateFormat(format);
    242     Date dateTime = formatter.parse(date);
    243     return dateTime.getTime();
    244 
    245   }
    246 
    247   /**
    248    * Returns current time in Epoch format
    249    *
    250    * @return The current date in Epoch format.
    251    */
    252   protected static long currentTime() {
    253     Calendar cal = Calendar.getInstance();
    254     return cal.getTimeInMillis();
    255   }
    256 
    257   /**
    258    * Sets the MapillarySequence object which contains the MapillaryImage.
    259    *
    260    * @param sequence
    261    *          The MapillarySequence that contains the MapillaryImage.
    262    */
    263   public void setSequence(MapillarySequence sequence) {
    264     this.sequence = sequence;
     128   * Returns a LatLon object containing the current coordinates of the object.
     129   * When you are dragging the image this changes.
     130   *
     131   * @return The LatLon object with the position of the object.
     132   */
     133  public LatLon getLatLon() {
     134    return this.movingLatLon;
    265135  }
    266136
     
    277147
    278148    return this.sequence;
     149  }
     150
     151  /**
     152   * Returns the last fixed direction of the object.
     153   *
     154   * @return The last fixed direction of the object. 0 means north.
     155   */
     156  public double getTempCa() {
     157    return this.tempCa;
     158  }
     159
     160  /**
     161   * Returns the last fixed coordinates of the object.
     162   *
     163   * @return A LatLon object containing.
     164   */
     165  public LatLon getTempLatLon() {
     166    return this.tempLatLon;
     167  }
     168
     169  /**
     170   * Returns whether the object has been modified or not.
     171   *
     172   * @return true if the object has been modified; false otherwise.
     173   */
     174  public boolean isModified() {
     175    return (this.getLatLon() != this.latLon || this.getCa() != this.ca);
     176  }
     177
     178  /**
     179   * Returns whether the image is visible on the map or not.
     180   *
     181   * @return True if the image is visible; false otherwise.
     182   */
     183  public boolean isVisible() {
     184    return this.visible;
     185  }
     186
     187  /**
     188   * Moves the image temporally to another position
     189   *
     190   * @param x
     191   *          The movement of the image in longitude units.
     192   * @param y
     193   *          The movement of the image in latitude units.
     194   */
     195  public void move(double x, double y) {
     196    this.movingLatLon = new LatLon(this.tempLatLon.getY() + y,
     197        this.tempLatLon.getX() + x);
    279198  }
    280199
     
    315234
    316235  }
     236
     237  /**
     238   * Sets the Epoch time when the picture was captured.
     239   *
     240   * @param capturedAt
     241   *          Epoch time when the image was captured.
     242   */
     243  public void setCapturedAt(long capturedAt) {
     244    this.capturedAt = capturedAt;
     245  }
     246
     247  /**
     248   * Sets the MapillarySequence object which contains the MapillaryImage.
     249   *
     250   * @param sequence
     251   *          The MapillarySequence that contains the MapillaryImage.
     252   */
     253  public void setSequence(MapillarySequence sequence) {
     254    this.sequence = sequence;
     255  }
     256
     257  /**
     258   * Set's whether the image should be visible on the map or not.
     259   *
     260   * @param visible
     261   *          true if the image is set to be visible; false otherwise.
     262   */
     263  public void setVisible(boolean visible) {
     264    this.visible = visible;
     265  }
     266
     267  /**
     268   * Called when the mouse button is released, meaning that the picture has
     269   * stopped being dragged, so the temporal values are saved.
     270   */
     271  public void stopMoving() {
     272    this.tempLatLon = this.movingLatLon;
     273    this.tempCa = this.movingCa;
     274  }
     275
     276  /**
     277   * Turns the image direction.
     278   *
     279   * @param ca
     280   *          The angle the image is moving.
     281   */
     282  public void turn(double ca) {
     283    this.movingCa = this.tempCa + ca;
     284  }
    317285}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31512 r31513  
    11package org.openstreetmap.josm.plugins.mapillary;
     2
     3import java.util.ArrayList;
     4import java.util.List;
     5import java.util.concurrent.CopyOnWriteArrayList;
    26
    37import org.openstreetmap.josm.Main;
     
    59import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
    610import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    7 
    8 import java.util.ArrayList;
    9 import java.util.List;
    10 import java.util.concurrent.CopyOnWriteArrayList;
    1111
    1212/**
     
    3333
    3434  /**
    35    * Main constructor.
     35   * Creates a new object and adds the initial set of listeners.
    3636   */
    3737  protected MapillaryData() {
     
    9393   *
    9494   * @param images
    95    *          A {@link List} of {@link MapillaryAbstractImage} objects that are going
    96    *          to be removed.
     95   *          A {@link List} of {@link MapillaryAbstractImage} objects that are
     96   *          going to be removed.
    9797   */
    9898  public synchronized void remove(List<MapillaryAbstractImage> images) {
     
    347347
    348348  /**
    349    * Adds a {@link MapillaryImage} object to the list of selected images, (when ctrl +
    350    * click)
     349   * Adds a {@link MapillaryImage} object to the list of selected images, (when
     350   * ctrl + click)
    351351   *
    352352   * @param image
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31501 r31513  
    5959    this.file = file;
    6060    try {
    61       this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
     61      this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
    6262    } catch (ParseException e) {
    6363      try {
    64         this.datetimeOriginal = getEpoch(datetimeOriginal,
     64        this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal,
    6565            "yyyy/MM/dd hh:mm:ss");
    6666      } catch (ParseException e1) {
    67         this.datetimeOriginal = currentTime();
     67        this.datetimeOriginal = MapillaryUtils.currentTime();
    6868      }
    6969    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31512 r31513  
    11package org.openstreetmap.josm.plugins.mapillary;
    22
     3import static org.openstreetmap.josm.tools.I18n.marktr;
    34import static org.openstreetmap.josm.tools.I18n.tr;
    4 import static org.openstreetmap.josm.tools.I18n.marktr;
    5 
    6 import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
    7 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    9 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    10 import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
    11 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
    12 import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode;
    13 import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
    14 import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
    15 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    16 import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.gui.layer.Layer;
    18 import org.openstreetmap.josm.data.Bounds;
    19 import org.openstreetmap.josm.gui.MapView;
    20 import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
    21 import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    22 import org.openstreetmap.josm.gui.NavigatableComponent;
    23 import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
    24 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    25 import org.openstreetmap.josm.data.coor.LatLon;
    26 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    27 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    28 import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    29 import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    30 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
    31 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
    32 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    33 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
    34 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    35 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
    36 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    37 import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
    38 import org.openstreetmap.josm.data.osm.event.DataSetListener;
    395
    406import java.awt.AlphaComposite;
     
    5117import java.awt.image.AffineTransformOp;
    5218import java.awt.image.BufferedImage;
     19import java.util.ArrayList;
     20import java.util.List;
     21import java.util.concurrent.CopyOnWriteArrayList;
    5322
    5423import javax.swing.AbstractAction;
    55 import javax.swing.ImageIcon;
    5624import javax.swing.Action;
    5725import javax.swing.Icon;
     26import javax.swing.ImageIcon;
    5827import javax.swing.JComponent;
    5928import javax.swing.KeyStroke;
    6029
    61 import java.util.List;
    62 import java.util.ArrayList;
    63 import java.util.concurrent.CopyOnWriteArrayList;
     30import org.openstreetmap.josm.Main;
     31import org.openstreetmap.josm.data.Bounds;
     32import org.openstreetmap.josm.data.coor.LatLon;
     33import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
     34import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
     35import org.openstreetmap.josm.data.osm.event.DataSetListener;
     36import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
     37import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
     38import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
     39import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
     40import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
     41import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     42import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     43import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
     44import org.openstreetmap.josm.gui.MapView;
     45import org.openstreetmap.josm.gui.MapView.EditLayerChangeListener;
     46import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     47import org.openstreetmap.josm.gui.NavigatableComponent;
     48import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
     49import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
     50import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
     51import org.openstreetmap.josm.gui.layer.Layer;
     52import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     53import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
     54import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
     55import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
     56import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     57import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord;
     58import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete;
     59import org.openstreetmap.josm.plugins.mapillary.mode.AbstractMode;
     60import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
     61import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
     62import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    6463
    6564/**
     
    515514    // When more data is downloaded, a delayed update is thrown, in order to
    516515    // wait for the data bounds to be set.
    517     Main.worker.submit(new delayedDownload());
     516    Main.worker.submit(new DelayedDownload());
     517  }
     518
     519  @Override
     520  public void primitivesAdded(PrimitivesAddedEvent event) {
     521  }
     522
     523  @Override
     524  public void primitivesRemoved(PrimitivesRemovedEvent event) {
     525  }
     526
     527  @Override
     528  public void tagsChanged(TagsChangedEvent event) {
     529  }
     530
     531  @Override
     532  public void nodeMoved(NodeMovedEvent event) {
     533  }
     534
     535  @Override
     536  public void wayNodesChanged(WayNodesChangedEvent event) {
     537  }
     538
     539  @Override
     540  public void relationMembersChanged(RelationMembersChangedEvent event) {
     541  }
     542
     543  @Override
     544  public void otherDatasetChange(AbstractDatasetChangedEvent event) {
     545  }
     546
     547  @Override
     548  public void visitBoundingBox(BoundingXYVisitor v) {
     549  }
     550
     551  @Override
     552  public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     553    if (newLayer == this) {
     554      MapillaryUtils.updateHelpText();
     555      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, true);
     556    } else
     557      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, false);
     558  }
     559
     560  @Override
     561  public void layerAdded(Layer newLayer) {
     562  }
     563
     564  @Override
     565  public void layerRemoved(Layer oldLayer) {
    518566  }
    519567
     
    524572   *
    525573   */
    526   private class delayedDownload extends Thread {
     574  private class DelayedDownload extends Thread {
    527575
    528576    @Override
     
    537585  }
    538586
    539   @Override
    540   public void primitivesAdded(PrimitivesAddedEvent event) {
    541   }
    542 
    543   @Override
    544   public void primitivesRemoved(PrimitivesRemovedEvent event) {
    545   }
    546 
    547   @Override
    548   public void tagsChanged(TagsChangedEvent event) {
    549   }
    550 
    551   @Override
    552   public void nodeMoved(NodeMovedEvent event) {
    553   }
    554 
    555   @Override
    556   public void wayNodesChanged(WayNodesChangedEvent event) {
    557   }
    558 
    559   @Override
    560   public void relationMembersChanged(RelationMembersChangedEvent event) {
    561   }
    562 
    563   @Override
    564   public void otherDatasetChange(AbstractDatasetChangedEvent event) {
    565   }
    566 
    567   @Override
    568   public void visitBoundingBox(BoundingXYVisitor v) {
    569   }
    570 
    571   @Override
    572   public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    573     if (newLayer == this) {
    574       MapillaryUtils.updateHelpText();
    575       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, true);
    576     } else
    577       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, false);
    578   }
    579 
    580   @Override
    581   public void layerAdded(Layer newLayer) {
    582   }
    583 
    584   @Override
    585   public void layerRemoved(Layer oldLayer) {
    586   }
    587 
    588587  /**
    589588   * Action used to delete images.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31501 r31513  
    88
    99import org.apache.commons.jcs.access.CacheAccess;
     10import org.openstreetmap.josm.Main;
    1011import org.openstreetmap.josm.data.cache.BufferedImageCacheEntry;
    1112import org.openstreetmap.josm.data.cache.JCSCacheManager;
    1213import org.openstreetmap.josm.gui.MainMenu;
    13 import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.gui.MapFrame;
    1515import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
    1616import org.openstreetmap.josm.plugins.Plugin;
    1717import org.openstreetmap.josm.plugins.PluginInformation;
     18import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadAction;
     19import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryDownloadViewAction;
     20import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryExportAction;
     21import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
     22import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportIntoSequenceAction;
     23import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryJoinAction;
     24import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryUploadAction;
     25import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryWalkAction;
     26import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryZoomAction;
    1827import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
    1928import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    2029import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryHistoryDialog;
     30import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    2131import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryPreferenceSetting;
    22 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
    2332import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    24 import org.openstreetmap.josm.plugins.mapillary.actions.*;
    2533import org.openstreetmap.josm.tools.ImageProvider;
    2634
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31459 r31513  
    33import java.io.BufferedReader;
    44import java.io.IOException;
     5import java.io.InputStreamReader;
    56import java.net.URL;
    6 import java.io.InputStreamReader;
    7 
    8 import javax.json.JsonArray;
    9 import javax.json.JsonObject;
    10 import javax.json.Json;
    11 
    127import java.util.ArrayList;
    138import java.util.List;
     
    1510import java.util.concurrent.locks.Lock;
    1611import java.util.concurrent.locks.ReentrantLock;
     12
     13import javax.json.Json;
     14import javax.json.JsonArray;
     15import javax.json.JsonObject;
    1716
    1817import org.openstreetmap.josm.Main;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31512 r31513  
    11package org.openstreetmap.josm.plugins.mapillary.downloads;
    22
    3 import java.util.concurrent.ThreadPoolExecutor;
    4 import java.util.concurrent.TimeUnit;
    53import java.io.UnsupportedEncodingException;
    64import java.net.URLEncoder;
     
    86import java.util.concurrent.ArrayBlockingQueue;
    97import java.util.concurrent.ConcurrentHashMap;
     8import java.util.concurrent.ThreadPoolExecutor;
     9import java.util.concurrent.TimeUnit;
    1010
    1111import org.openstreetmap.josm.Main;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31512 r31513  
    125125      add(this.copyTag);
    126126
    127       this.edit = new JMenuItem(tr("Edit on webpage"));
     127      this.edit = new JMenuItem(tr("Edit on website"));
    128128      this.edit.addActionListener(new editAction());
    129129      add(this.edit);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r31501 r31513  
    2323import javax.swing.event.TreeSelectionEvent;
    2424import javax.swing.event.TreeSelectionListener;
     25import javax.swing.tree.DefaultMutableTreeNode;
    2526import javax.swing.tree.DefaultTreeCellRenderer;
    2627import javax.swing.tree.DefaultTreeModel;
     
    3738import org.openstreetmap.josm.tools.ImageProvider;
    3839import org.openstreetmap.josm.tools.Shortcut;
    39 
    40 import javax.swing.tree.DefaultMutableTreeNode;
    4140
    4241/**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31457 r31513  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.event.ActionEvent;
    6 import java.awt.event.KeyEvent;
    7 import java.awt.image.BufferedImage;
    85import java.awt.BorderLayout;
    96import java.awt.Color;
     
    118import java.awt.FlowLayout;
    129import java.awt.GridLayout;
     10import java.awt.event.ActionEvent;
     11import java.awt.event.KeyEvent;
     12import java.awt.image.BufferedImage;
    1313import java.io.ByteArrayInputStream;
    1414import java.io.IOException;
     
    1616import java.util.List;
    1717
     18import javax.imageio.ImageIO;
     19import javax.swing.AbstractAction;
     20import javax.swing.JComponent;
     21import javax.swing.JPanel;
     22import javax.swing.KeyStroke;
     23import javax.swing.SwingUtilities;
     24
    1825import org.openstreetmap.josm.Main;
    1926import org.openstreetmap.josm.data.cache.CacheEntry;
    2027import org.openstreetmap.josm.data.cache.CacheEntryAttributes;
    2128import org.openstreetmap.josm.data.cache.ICachedLoaderListener;
     29import org.openstreetmap.josm.gui.SideButton;
    2230import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    23 import org.openstreetmap.josm.gui.SideButton;
    2431import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    2532import org.openstreetmap.josm.plugins.mapillary.MapillaryDataListener;
     
    3340import org.openstreetmap.josm.tools.ImageProvider;
    3441import org.openstreetmap.josm.tools.Shortcut;
    35 
    36 import javax.imageio.ImageIO;
    37 import javax.swing.JComponent;
    38 import javax.swing.KeyStroke;
    39 import javax.swing.SwingUtilities;
    40 import javax.swing.AbstractAction;
    41 import javax.swing.JPanel;
    4242
    4343/**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandMove.java

    r31490 r31513  
    4141      image.stopMoving();
    4242    }
    43     checkModified();
    4443    if (Main.main != null)
    4544      Main.map.repaint();
     
    5251      image.stopMoving();
    5352    }
    54     checkModified();
    5553    if (Main.main != null)
    5654      Main.map.repaint();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandTurn.java

    r31490 r31513  
    3636      image.stopMoving();
    3737    }
    38     checkModified();
    3938    if (Main.main != null)
    4039      Main.map.repaint();
     
    4746      image.stopMoving();
    4847    }
    49     checkModified();
    5048    if (Main.main != null)
    5149      Main.map.repaint();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/MapillaryCommand.java

    r31490 r31513  
    4545  public abstract void sum(MapillaryCommand command);
    4646
    47   /**
    48    * Checks if the image has been modified, comparing with its original values.
    49    */
    50   public void checkModified() {
    51     for (MapillaryAbstractImage image : this.images)
    52       image.isModified = (image.tempLatLon == image.latLon || image.tempCa == image.ca);
    53   }
    54 
    5547  @Override
    5648  public abstract String toString();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31512 r31513  
    5555public class UploadUtils {
    5656
    57   /** Required keys for POST */
    58   private static final String[] keys = { "key", "AWSAccessKeyId", "acl",
    59       "policy", "signature", "Content-Type" };
    60   /** Mapillary upload URL */
    61   private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
    62   /** Count to name temporal files. */
    63   private static int c = 0;
    64 
    65   /**
    66    * Uploads the given MapillaryImportedImage object.
    67    *
    68    * @param image
    69    *
    70    */
    71   public static void upload(MapillaryImportedImage image) {
    72     upload(image, UUID.randomUUID());
    73 
    74   }
    75 
    76   /**
    77    * @param image
    78    * @param uuid
    79    *          The UUID used to create the sequence.
    80    */
    81   public static void upload(MapillaryImportedImage image, UUID uuid) {
    82     String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/"
    83         + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_"
    84         + image.getCa() + "_" + image.datetimeOriginal + ".jpg";
    85 
    86     String policy = null;
    87     String signature = null;
    88     policy = MapillaryUser.getSecrets().get("images_policy");
    89     signature = MapillaryUser.getSecrets().get("images_hash");
    90 
    91     HashMap<String, String> hash = new HashMap<>();
    92     hash.put("key", key);
    93     hash.put("AWSAccessKeyId", "AKIAI2X3BJAT2W75HILA");
    94     hash.put("acl", "private");
    95     hash.put("policy", policy);
    96     hash.put("signature", signature);
    97     hash.put("Content-Type", "image/jpeg");
    98 
    99     try {
    100       uploadFile(updateFile(image), hash);
    101     } catch (ImageReadException | ImageWriteException | IOException e) {
    102       Main.error(e);
    103     }
    104   }
    105 
    106   /**
    107    * @param file
    108    * @param hash
    109    * @throws IOException
    110    * @throws IllegalArgumentException
    111    *           if the hash doesn't contain all the needed keys.
    112    */
    113   public static void uploadFile(File file, HashMap<String, String> hash)
    114       throws IOException {
    115     HttpClientBuilder builder = HttpClientBuilder.create();
    116     HttpClient httpClient = builder.build();
    117     HttpPost httpPost = new HttpPost(UPLOAD_URL);
    118 
    119     MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
    120     for (String key : keys) {
    121       if (hash.get(key) == null)
    122         throw new IllegalArgumentException();
    123       entityBuilder.addPart(key, new StringBody(hash.get(key),
    124           ContentType.TEXT_PLAIN));
    125     }
    126     entityBuilder.addPart("file", new FileBody(file));
    127 
    128     HttpEntity entity = entityBuilder.build();
    129     httpPost.setEntity(entity);
    130     HttpResponse response = httpClient.execute(httpPost);
    131     if (response.getStatusLine().toString().contains("204")) {
    132       PluginState.imageUploaded();
    133       Main.info(PluginState.getUploadString() + " (Mapillary)");
    134     } else
    135       Main.info("Upload error");
    136     file.delete();
    137     MapillaryUtils.updateHelpText();
    138   }
    139 
    140   /**
    141    * Uploads the given {@link MapillarySequence}.
    142    *
    143    * @param sequence
    144    *          The sequence to upload. It must contain only
    145    *          {@link MapillaryImportedImage} objects.
    146    * @param delete
    147    *          Whether the images must be deleted after upload or not.
    148    */
    149   public static void uploadSequence(MapillarySequence sequence, boolean delete) {
    150     Main.worker.submit(new SequenceUploadThread(sequence.getImages(), delete));
    151   }
    152 
    15357  private static class SequenceUploadThread extends Thread {
    15458    private List<MapillaryAbstractImage> images;
     
    19498    }
    19599  }
    196 
    197100  private static class SingleUploadThread extends Thread {
    198101
     
    210113    }
    211114  }
     115  /** Required keys for POST */
     116  private static final String[] keys = { "key", "AWSAccessKeyId", "acl",
     117      "policy", "signature", "Content-Type" };
     118
     119  /** Mapillary upload URL */
     120  private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
     121
     122  /** Count to name temporal files. */
     123  private static int c = 0;
    212124
    213125  /**
     
    282194    return tempFile;
    283195  }
     196
     197  /**
     198   * Uploads the given MapillaryImportedImage object.
     199   *
     200   * @param image
     201   *
     202   */
     203  public static void upload(MapillaryImportedImage image) {
     204    upload(image, UUID.randomUUID());
     205
     206  }
     207
     208  /**
     209   * @param image
     210   * @param uuid
     211   *          The UUID used to create the sequence.
     212   */
     213  public static void upload(MapillaryImportedImage image, UUID uuid) {
     214    String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/"
     215        + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_"
     216        + image.getCa() + "_" + image.datetimeOriginal + ".jpg";
     217
     218    String policy = null;
     219    String signature = null;
     220    policy = MapillaryUser.getSecrets().get("images_policy");
     221    signature = MapillaryUser.getSecrets().get("images_hash");
     222
     223    HashMap<String, String> hash = new HashMap<>();
     224    hash.put("key", key);
     225    hash.put("AWSAccessKeyId", "AKIAI2X3BJAT2W75HILA");
     226    hash.put("acl", "private");
     227    hash.put("policy", policy);
     228    hash.put("signature", signature);
     229    hash.put("Content-Type", "image/jpeg");
     230
     231    try {
     232      uploadFile(updateFile(image), hash);
     233    } catch (ImageReadException | ImageWriteException | IOException e) {
     234      Main.error(e);
     235    }
     236  }
     237
     238  /**
     239   * @param file
     240   * @param hash
     241   * @throws IOException
     242   * @throws IllegalArgumentException
     243   *           if the hash doesn't contain all the needed keys.
     244   */
     245  public static void uploadFile(File file, HashMap<String, String> hash)
     246      throws IOException {
     247    HttpClientBuilder builder = HttpClientBuilder.create();
     248    HttpClient httpClient = builder.build();
     249    HttpPost httpPost = new HttpPost(UPLOAD_URL);
     250
     251    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
     252    for (String key : keys) {
     253      if (hash.get(key) == null)
     254        throw new IllegalArgumentException();
     255      entityBuilder.addPart(key, new StringBody(hash.get(key),
     256          ContentType.TEXT_PLAIN));
     257    }
     258    entityBuilder.addPart("file", new FileBody(file));
     259
     260    HttpEntity entity = entityBuilder.build();
     261    httpPost.setEntity(entity);
     262    HttpResponse response = httpClient.execute(httpPost);
     263    if (response.getStatusLine().toString().contains("204")) {
     264      PluginState.imageUploaded();
     265      Main.info(PluginState.getUploadString() + " (Mapillary)");
     266    } else
     267      Main.info("Upload error");
     268    file.delete();
     269    MapillaryUtils.updateHelpText();
     270  }
     271
     272  /**
     273   * Uploads the given {@link MapillarySequence}.
     274   *
     275   * @param sequence
     276   *          The sequence to upload. It must contain only
     277   *          {@link MapillaryImportedImage} objects.
     278   * @param delete
     279   *          Whether the images must be deleted after upload or not.
     280   */
     281  public static void uploadSequence(MapillarySequence sequence, boolean delete) {
     282    Main.worker.submit(new SequenceUploadThread(sequence.getImages(), delete));
     283  }
    284284}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31512 r31513  
    88import java.net.URISyntaxException;
    99import java.net.URL;
     10import java.text.ParseException;
    1011import java.text.SimpleDateFormat;
    1112import java.util.ArrayList;
    1213import java.util.Calendar;
     14import java.util.Date;
    1315import java.util.List;
    1416
     
    4547
    4648  /**
    47    * Updates the help text at the bottom of the window.
    48    */
    49   public static void updateHelpText() {
    50     String ret = "";
    51     if (PluginState.isDownloading())
    52       ret += tr("Downloading Mapillary images");
    53     else if (MapillaryLayer.getInstance().getData().size() > 0)
    54       ret += tr("Total Mapillary images: {0}", MapillaryLayer.getInstance()
    55           .getData().size());
    56     else
    57       ret += tr("No images found");
    58     if (MapillaryLayer.getInstance().mode != null)
    59       ret += " -- " + tr(MapillaryLayer.getInstance().mode.toString());
    60     if (PluginState.isUploading())
    61       ret += " -- " + PluginState.getUploadString();
    62     Main.map.statusLine.setHelpText(ret);
     49   * Open the default browser in the given URL.
     50   *
     51   * @param url
     52   *          The URL that is going to be opened.
     53   */
     54  public static void browse(URL url) {
     55    Desktop desktop = Desktop.getDesktop();
     56    if (desktop.isSupported(Desktop.Action.BROWSE)) {
     57      try {
     58        desktop.browse(url.toURI());
     59      } catch (IOException | URISyntaxException e1) {
     60        Main.error(e1);
     61      }
     62    } else {
     63      Runtime runtime = Runtime.getRuntime();
     64      try {
     65        runtime.exec("xdg-open " + url);
     66      } catch (IOException exc) {
     67        exc.printStackTrace();
     68      }
     69    }
     70  }
     71
     72  /**
     73   * Returns the current date.
     74   *
     75   * @return A {@code String} object containing the current date.
     76   */
     77  public static String currentDate() {
     78    Calendar cal = Calendar.getInstance();
     79    SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
     80    return formatter.format(cal.getTime());
     81  }
     82
     83  /**
     84   * Returns current time in Epoch format
     85   *
     86   * @return The current date in Epoch format.
     87   */
     88  public static long currentTime() {
     89    Calendar cal = Calendar.getInstance();
     90    return cal.getTimeInMillis();
    6391  }
    6492
     
    122150
    123151  /**
    124    * Open the default browser in the given URL.
    125    *
    126    * @param url
    127    *          The URL that is going to be opened.
    128    */
    129   public static void browse(URL url) {
    130     Desktop desktop = Desktop.getDesktop();
    131     if (desktop.isSupported(Desktop.Action.BROWSE)) {
    132       try {
    133         desktop.browse(url.toURI());
    134       } catch (IOException | URISyntaxException e1) {
    135         Main.error(e1);
    136       }
    137     } else {
    138       Runtime runtime = Runtime.getRuntime();
    139       try {
    140         runtime.exec("xdg-open " + url);
    141       } catch (IOException exc) {
    142         exc.printStackTrace();
    143       }
    144     }
     152   * Parses a string with a given format and returns the Epoch time.
     153   *
     154   * @param date
     155   *          The string containing the date.
     156   * @param format
     157   *          The format of the date.
     158   * @return The date in Epoch format.
     159   * @throws ParseException
     160   */
     161  public static long getEpoch(String date, String format) throws ParseException {
     162    SimpleDateFormat formatter = new SimpleDateFormat(format);
     163    Date dateTime = formatter.parse(date);
     164    return dateTime.getTime();
     165  }
     166
     167  /**
     168   * Returns the extension of a {@link File} object.
     169   *
     170   * @param file
     171   *          The {@link File} object whose extension is going to be returned.
     172   * @return A {@code String} object containing the extension in lowercase.
     173   */
     174  public static String getExtension(File file) {
     175    if (file.isDirectory())
     176      throw new IllegalArgumentException("The file is a directory");
     177    int k = file.getName().lastIndexOf('.');
     178    if (k > 0) {
     179      return file.getName().substring(k + 1).toLowerCase();
     180    }
     181    throw new IllegalArgumentException("Error parsing the extension");
    145182  }
    146183
     
    178215    if (Main.main != null)
    179216      MapillaryData.dataUpdated();
    180   }
    181 
    182   /**
    183    * Separates two images belonging to the same sequence.
    184    *
    185    * @param mapillaryAbstractImage
    186    * @param mapillaryAbstractImage2
    187    */
    188   public synchronized static void unjoin(
    189       MapillaryAbstractImage mapillaryAbstractImage,
    190       MapillaryAbstractImage mapillaryAbstractImage2) {
    191     MapillaryAbstractImage firstImage = mapillaryAbstractImage;
    192     MapillaryAbstractImage secondImage = mapillaryAbstractImage2;
    193 
    194     if (mapillaryAbstractImage.next() != mapillaryAbstractImage2) {
    195       firstImage = mapillaryAbstractImage2;
    196       secondImage = mapillaryAbstractImage;
    197     }
    198 
    199     ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
    200         .getSequence().getImages()
    201         .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
    202     ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
    203         .getSequence()
    204         .getImages()
    205         .subList(firstImage.getSequence().getImages().indexOf(secondImage),
    206             firstImage.getSequence().getImages().size()));
    207 
    208     MapillarySequence seq1 = new MapillarySequence();
    209     MapillarySequence seq2 = new MapillarySequence();
    210 
    211     for (MapillaryAbstractImage img : firstHalf) {
    212       img.setSequence(seq1);
    213       seq1.add(img);
    214     }
    215     for (MapillaryAbstractImage img : secondHalf) {
    216       img.setSequence(seq2);
    217       seq2.add(img);
    218     }
    219     if (Main.main != null)
    220       MapillaryData.dataUpdated();
    221   }
    222 
    223   /**
    224    * Zooms to fit all the given {@link MapillaryAbstractImage} objects.
    225    *
    226    * @param images
    227    *          The images your are zooming to.
    228    * @param select
    229    *          Whether the added images must be selected or not.
    230    */
    231   public static void showPictures(final List<MapillaryAbstractImage> images,
    232       final boolean select) {
    233     if (!SwingUtilities.isEventDispatchThread()) {
    234       SwingUtilities.invokeLater(new Runnable() {
    235         @Override
    236         public void run() {
    237           showPictures(images, select);
    238         }
    239       });
    240     } else {
    241       double minLat = 90;
    242       double minLon = 180;
    243       double maxLat = -90;
    244       double maxLon = -180;
    245       for (MapillaryAbstractImage img : images) {
    246         if (img.getLatLon().lat() < minLat)
    247           minLat = img.getLatLon().lat();
    248         if (img.getLatLon().lon() < minLon)
    249           minLon = img.getLatLon().lon();
    250         if (img.getLatLon().lat() > maxLat)
    251           maxLat = img.getLatLon().lat();
    252         if (img.getLatLon().lon() > maxLon)
    253           maxLon = img.getLatLon().lon();
    254       }
    255       Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon), new LatLon(
    256           maxLat, maxLon));
    257       // The zoom rectangle must have a minimum size.
    258       double latExtent = zoomBounds.getMaxLat() - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
    259           .getMaxLat() - zoomBounds.getMinLat()
    260           : MIN_ZOOM_SQUARE_SIDE;
    261       double lonExtent = zoomBounds.getMaxLon() - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
    262           .getMaxLon() - zoomBounds.getMinLon()
    263           : MIN_ZOOM_SQUARE_SIDE;
    264       zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
    265 
    266       Main.map.mapView.zoomTo(zoomBounds);
    267       MapillaryLayer.getInstance().getData().setSelectedImage(null);
    268       if (select)
    269         MapillaryLayer.getInstance().getData().addMultiSelectedImage(images);
    270       if (Main.main != null)
    271         MapillaryData.dataUpdated();
    272     }
    273   }
    274 
    275   /**
    276    * Zooms to fit all the {@link MapillaryAbstractImage} objects stored in the
    277    * database.
    278    */
    279   public static void showAllPictures() {
    280     showPictures(MapillaryLayer.getInstance().getData().getImages(), false);
    281   }
    282 
    283   /**
    284    * Returns the current date.
    285    *
    286    * @return A {@code String} object containing the current date.
    287    */
    288   public static String currentDate() {
    289     Calendar cal = Calendar.getInstance();
    290     SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
    291     return formatter.format(cal.getTime());
    292217  }
    293218
     
    319244   *          have all the needed EXIF tags; {@code false} returns an image in
    320245   *          the center of the screen.
    321    * @return The imported image.
     246   * @return The imported image, whose data has been extracted from the
     247   *         picture's metadata.
    322248   * @throws ImageReadException
    323249   *           If the {@link File} isn't an image.
     
    378304   * @param file
    379305   *          The file where the image is located.
     306   * @return The imported image.
     307   */
     308  public static MapillaryImportedImage readNoTags(File file) {
     309    return readNoTags(
     310        file,
     311        Main.map.mapView.getProjection().eastNorth2latlon(
     312            Main.map.mapView.getCenter()));
     313  }
     314
     315  /**
     316   * Reads a image file that doesn't contain the needed GPS information. And
     317   * creates a new icon in the middle of the map.
     318   *
     319   * @param file
     320   *          The file where the image is located.
    380321   * @param pos
    381322   *          A {@link LatLon} object indicating the position in the map where
     
    406347
    407348  /**
    408    * Reads a image file that doesn't contain the needed GPS information. And
    409    * creates a new icon in the middle of the map.
    410    *
    411    * @param file
    412    *          The file where the image is located.
    413    * @return The imported image.
    414    */
    415   public static MapillaryImportedImage readNoTags(File file) {
    416     return readNoTags(
    417         file,
    418         Main.map.mapView.getProjection().eastNorth2latlon(
    419             Main.map.mapView.getCenter()));
    420   }
    421 
    422   /**
    423    * Returns the extension of a {@link File} object.
    424    *
    425    * @param file
    426    *          The {@link File} object whose extension is going to be returned.
    427    * @return A {@code String} object containing the extension.
    428    */
    429   public static String getExtension(File file) {
    430     if (file.isDirectory())
    431       throw new IllegalArgumentException("The file is a directory");
    432     int k = file.getName().lastIndexOf('.');
    433     if (k > 0) {
    434       return file.getName().substring(k + 1).toLowerCase();
    435     }
    436     throw new IllegalArgumentException("Error parsing the extension");
     349   * Zooms to fit all the {@link MapillaryAbstractImage} objects stored in the
     350   * database.
     351   */
     352  public static void showAllPictures() {
     353    showPictures(MapillaryLayer.getInstance().getData().getImages(), false);
     354  }
     355
     356  /**
     357   * Zooms to fit all the given {@link MapillaryAbstractImage} objects.
     358   *
     359   * @param images
     360   *          The images your are zooming to.
     361   * @param select
     362   *          Whether the added images must be selected or not.
     363   */
     364  public static void showPictures(final List<MapillaryAbstractImage> images,
     365      final boolean select) {
     366    if (!SwingUtilities.isEventDispatchThread()) {
     367      SwingUtilities.invokeLater(new Runnable() {
     368        @Override
     369        public void run() {
     370          showPictures(images, select);
     371        }
     372      });
     373    } else {
     374      double minLat = 90;
     375      double minLon = 180;
     376      double maxLat = -90;
     377      double maxLon = -180;
     378      for (MapillaryAbstractImage img : images) {
     379        if (img.getLatLon().lat() < minLat)
     380          minLat = img.getLatLon().lat();
     381        if (img.getLatLon().lon() < minLon)
     382          minLon = img.getLatLon().lon();
     383        if (img.getLatLon().lat() > maxLat)
     384          maxLat = img.getLatLon().lat();
     385        if (img.getLatLon().lon() > maxLon)
     386          maxLon = img.getLatLon().lon();
     387      }
     388      Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon), new LatLon(
     389          maxLat, maxLon));
     390      // The zoom rectangle must have a minimum size.
     391      double latExtent = zoomBounds.getMaxLat() - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
     392          .getMaxLat() - zoomBounds.getMinLat()
     393          : MIN_ZOOM_SQUARE_SIDE;
     394      double lonExtent = zoomBounds.getMaxLon() - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
     395          .getMaxLon() - zoomBounds.getMinLon()
     396          : MIN_ZOOM_SQUARE_SIDE;
     397      zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
     398
     399      Main.map.mapView.zoomTo(zoomBounds);
     400      MapillaryLayer.getInstance().getData().setSelectedImage(null);
     401      if (select)
     402        MapillaryLayer.getInstance().getData().addMultiSelectedImage(images);
     403      if (Main.main != null)
     404        MapillaryData.dataUpdated();
     405    }
     406  }
     407
     408  /**
     409   * Separates two images belonging to the same sequence.
     410   *
     411   * @param mapillaryAbstractImage
     412   * @param mapillaryAbstractImage2
     413   */
     414  public synchronized static void unjoin(
     415      MapillaryAbstractImage mapillaryAbstractImage,
     416      MapillaryAbstractImage mapillaryAbstractImage2) {
     417    MapillaryAbstractImage firstImage = mapillaryAbstractImage;
     418    MapillaryAbstractImage secondImage = mapillaryAbstractImage2;
     419
     420    if (mapillaryAbstractImage.next() != mapillaryAbstractImage2) {
     421      firstImage = mapillaryAbstractImage2;
     422      secondImage = mapillaryAbstractImage;
     423    }
     424
     425    ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
     426        .getSequence().getImages()
     427        .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
     428    ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
     429        .getSequence()
     430        .getImages()
     431        .subList(firstImage.getSequence().getImages().indexOf(secondImage),
     432            firstImage.getSequence().getImages().size()));
     433
     434    MapillarySequence seq1 = new MapillarySequence();
     435    MapillarySequence seq2 = new MapillarySequence();
     436
     437    for (MapillaryAbstractImage img : firstHalf) {
     438      img.setSequence(seq1);
     439      seq1.add(img);
     440    }
     441    for (MapillaryAbstractImage img : secondHalf) {
     442      img.setSequence(seq2);
     443      seq2.add(img);
     444    }
     445    if (Main.main != null)
     446      MapillaryData.dataUpdated();
     447  }
     448
     449  /**
     450   * Updates the help text at the bottom of the window.
     451   */
     452  public static void updateHelpText() {
     453    String ret = "";
     454    if (PluginState.isDownloading())
     455      ret += tr("Downloading Mapillary images");
     456    else if (MapillaryLayer.getInstance().getData().size() > 0)
     457      ret += tr("Total Mapillary images: {0}", MapillaryLayer.getInstance()
     458          .getData().size());
     459    else
     460      ret += tr("No images found");
     461    if (MapillaryLayer.getInstance().mode != null)
     462      ret += " -- " + tr(MapillaryLayer.getInstance().mode.toString());
     463    if (PluginState.isUploading())
     464      ret += " -- " + PluginState.getUploadString();
     465    synchronized (MapillaryUtils.class) {
     466      Main.map.statusLine.setHelpText(ret);
     467    }
    437468  }
    438469}
Note: See TracChangeset for help on using the changeset viewer.