Ignore:
Timestamp:
2015-08-04T11:35:15+02:00 (9 years ago)
Author:
nokutu
Message:

Several changes:

  • Fixed #17730 and #11742
  • Created upload system. New action in file menu.
  • Added new dependency: org.apache.httpcomponents:httpmime:4.5
Location:
applications/editors/josm/plugins/mapillary
Files:
3 added
43 edited

Legend:

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

    r31415 r31445  
    8888   */
    8989  public LatLon getLatLon() {
    90     return movingLatLon;
     90    return this.movingLatLon;
    9191  }
    9292
     
    9797   */
    9898  public boolean isVisible() {
    99     return visible;
     99    return this.visible;
    100100  }
    101101
     
    116116   */
    117117  public LatLon getTempLatLon() {
    118     return tempLatLon;
     118    return this.tempLatLon;
    119119  }
    120120
     
    159159   */
    160160  public double getCa() {
    161     return movingCa;
     161    return this.movingCa;
    162162  }
    163163
     
    168168   */
    169169  public double getTempCa() {
    170     return tempCa;
     170    return this.tempCa;
    171171  }
    172172
     
    195195   *
    196196   * @param capturedAt
     197   *          Epoch time when the image was captured.
    197198   */
    198199  public void setCapturedAt(long capturedAt) {
     
    206207   */
    207208  public long getCapturedAt() {
    208     return capturedAt;
     209    return this.capturedAt;
    209210  }
    210211
     
    212213   * Returns the date the picture was taken in the given format.
    213214   *
    214    * @param format
     215   * @param format Format of the date. See {@link SimpleDateFormat}.
    215216   * @return A String containing the date the picture was taken using the given
    216217   *         format.
     
    233234   * @return The date in Epoch format.
    234235   */
    235   public long getEpoch(String date, String format) {
     236  public static long getEpoch(String date, String format) {
    236237
    237238    SimpleDateFormat formatter = new SimpleDateFormat(format);
     
    250251   * @return The current date in Epoch format.
    251252   */
    252   private long currentTime() {
     253  private static long currentTime() {
    253254    Calendar cal = Calendar.getInstance();
    254255    return cal.getTimeInMillis();
     
    271272   */
    272273  public MapillarySequence getSequence() {
     274    if (this.sequence == null) {
     275      this.sequence = new MapillarySequence();
     276      this.sequence.add(this);
     277    }
     278
    273279    return this.sequence;
    274280  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31418 r31445  
    2020  /** Unique instance of the class */
    2121  public volatile static MapillaryData INSTANCE;
    22   /** Enable this if you are using in Unit Tests */
    23   public static boolean TEST_MODE = false;
    2422
    2523  private final List<MapillaryAbstractImage> images;
     
    3533   */
    3634  private MapillaryData() {
    37     images = new CopyOnWriteArrayList<>();
    38     multiSelectedImages = new ArrayList<>();
    39     selectedImage = null;
     35    this.images = new CopyOnWriteArrayList<>();
     36    this.multiSelectedImages = new ArrayList<>();
     37    this.selectedImage = null;
    4038
    4139    addListener(MapillaryPlugin.walkAction);
     
    8886   */
    8987  public void addListener(MapillaryDataListener lis) {
    90     listeners.add(lis);
     88    this.listeners.add(lis);
    9189  }
    9290
     
    9896   */
    9997  public void removeListener(MapillaryDataListener lis) {
    100     listeners.remove(lis);
     98    this.listeners.remove(lis);
    10199  }
    102100
     
    124122   */
    125123  public void setHighlightedImage(MapillaryAbstractImage image) {
    126     highlightedImage = image;
     124    this.highlightedImage = image;
    127125  }
    128126
     
    133131   */
    134132  public MapillaryAbstractImage getHighlighted() {
    135     return highlightedImage;
     133    return this.highlightedImage;
    136134  }
    137135
     
    146144   */
    147145  public synchronized void add(MapillaryAbstractImage image, boolean update) {
    148     if (!images.contains(image)) {
     146    if (!this.images.contains(image)) {
    149147      this.images.add(image);
    150148    }
     
    157155   * Repaints mapView object.
    158156   */
    159   public synchronized void dataUpdated() {
    160     if (!TEST_MODE)
     157  public synchronized static void dataUpdated() {
     158    if (Main.main != null)
    161159      Main.map.mapView.repaint();
    162160  }
     
    168166   */
    169167  public List<MapillaryAbstractImage> getImages() {
    170     return images;
     168    return this.images;
    171169  }
    172170
     
    177175   */
    178176  public MapillaryAbstractImage getSelectedImage() {
    179     return selectedImage;
     177    return this.selectedImage;
    180178  }
    181179
    182180  private void fireImagesAdded() {
    183     if (listeners.isEmpty())
    184       return;
    185     for (MapillaryDataListener lis : listeners)
    186       lis.imagesAdded();
     181    if (this.listeners.isEmpty())
     182      return;
     183    for (MapillaryDataListener lis : this.listeners)
     184      if (lis != null)
     185        lis.imagesAdded();
    187186  }
    188187
     
    197196    if (getSelectedImage().getSequence() == null)
    198197      return;
    199     MapillaryAbstractImage tempImage = selectedImage;
     198    MapillaryAbstractImage tempImage = this.selectedImage;
    200199    while (tempImage.next() != null) {
    201200      tempImage = tempImage.next();
     
    221220    if (getSelectedImage().getSequence() == null)
    222221      return;
    223     MapillaryAbstractImage tempImage = selectedImage;
     222    MapillaryAbstractImage tempImage = this.selectedImage;
    224223    while (tempImage.next() != null) {
    225224      tempImage = tempImage.next();
     
    241240    if (getSelectedImage().getSequence() == null)
    242241      throw new IllegalStateException();
    243     MapillaryAbstractImage tempImage = selectedImage;
     242    MapillaryAbstractImage tempImage = this.selectedImage;
    244243    while (tempImage.previous() != null) {
    245244      tempImage = tempImage.previous();
     
    265264    if (getSelectedImage().getSequence() == null)
    266265      throw new IllegalStateException();
    267     MapillaryAbstractImage tempImage = selectedImage;
     266    MapillaryAbstractImage tempImage = this.selectedImage;
    268267    while (tempImage.previous() != null) {
    269268      tempImage = tempImage.previous();
     
    295294   */
    296295  public void setSelectedImage(MapillaryAbstractImage image, boolean zoom) {
    297     MapillaryAbstractImage oldImage = selectedImage;
    298     selectedImage = image;
    299     multiSelectedImages.clear();
    300     multiSelectedImages.add(image);
     296    MapillaryAbstractImage oldImage = this.selectedImage;
     297    this.selectedImage = image;
     298    this.multiSelectedImages.clear();
     299    this.multiSelectedImages.add(image);
    301300    if (image != null) {
    302301      if (image instanceof MapillaryImage) {
     
    320319      Main.map.mapView.zoomTo(MapillaryData.getInstance().getSelectedImage()
    321320          .getLatLon());
    322     if (Main.map != null)
     321    if (Main.main != null)
    323322      Main.map.mapView.repaint();
    324     fireSelectedImageChanged(oldImage, selectedImage);
     323    fireSelectedImageChanged(oldImage, this.selectedImage);
    325324  }
    326325
    327326  private void fireSelectedImageChanged(MapillaryAbstractImage oldImage,
    328327      MapillaryAbstractImage newImage) {
    329     if (listeners.isEmpty())
    330       return;
    331     for (MapillaryDataListener lis : listeners)
    332       lis.selectedImageChanged(oldImage, newImage);
     328    if (this.listeners.isEmpty())
     329      return;
     330    for (MapillaryDataListener lis : this.listeners)
     331      if (lis != null)
     332        lis.selectedImageChanged(oldImage, newImage);
    333333  }
    334334
     
    375375   */
    376376  public List<MapillaryAbstractImage> getMultiSelectedImages() {
    377     return multiSelectedImages;
     377    return this.multiSelectedImages;
    378378  }
    379379
     
    384384   */
    385385  public int size() {
    386     return images.size();
     386    return this.images.size();
    387387  }
    388388}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31409 r31445  
    2727   */
    2828  public String getLocation() {
    29     return location;
     29    return this.location;
    3030  }
    3131
     
    3434   *
    3535   * @param location
     36   *          A String object containing the place where the image was taken.
    3637   */
    3738  public void setLocation(String location) {
     
    7374   */
    7475  public void addSign(String sign) {
    75     signs.add(sign);
     76    this.signs.add(sign);
    7677  }
    7778
     
    8283   */
    8384  public List<String> getSigns() {
    84     return signs;
     85    return this.signs;
    8586  }
    8687
     
    102103   */
    103104  public String getUser() {
    104     return user;
     105    return this.user;
    105106  }
    106107
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31410 r31445  
    6363   * Returns the pictures of the file.
    6464   *
    65    * @return A BufferedImage object containing the picture,
    66    *           or null if the {@link File} given in the constructor was null.
     65   * @return A BufferedImage object containing the picture, or null if the
     66   *         {@link File} given in the constructor was null.
    6767   * @throws IOException
     68   *           If the file parameter of the object isn't an image.
    6869   */
    6970  public BufferedImage getImage() throws IOException {
    70     return file == null ? null : ImageIO.read(file);
     71    return this.file == null ? null : ImageIO.read(this.file);
    7172  }
    7273
     
    7778   */
    7879  public File getFile() {
    79     return file;
     80    return this.file;
    8081  }
    8182
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31422 r31445  
    9898  private MapillaryLayer() {
    9999    super(tr("Mapillary Images"));
    100     data = MapillaryData.getInstance();
    101     bounds = new CopyOnWriteArrayList<>();
     100    this.data = MapillaryData.getInstance();
     101    this.bounds = new CopyOnWriteArrayList<>();
    102102    init();
    103103  }
     
    109109    if (INSTANCE == null)
    110110      INSTANCE = this;
    111     if (Main.map != null && Main.map.mapView != null) {
     111    if (Main.main != null && Main.map.mapView != null) {
    112112      setMode(new SelectMode());
    113113      Main.map.mapView.addLayer(this);
     
    119119        MapillaryDownloader.automaticDownload();
    120120      if (MapillaryDownloader.getMode() == MapillaryDownloader.SEMIAUTOMATIC)
    121         mode.zoomChanged();
     121        this.mode.zoomChanged();
    122122    }
    123123    if (MapillaryPlugin.EXPORT_MENU != null) { // Does not execute when in
     
    128128    }
    129129    createHatchTexture();
    130     data.dataUpdated();
     130    if (Main.main != null)
     131      MapillaryData.dataUpdated();
    131132  }
    132133
     
    171172   */
    172173  public MapillaryData getMapillaryData() {
    173     return data;
     174    return this.data;
    174175  }
    175176
     
    183184    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false);
    184185    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false);
    185     Main.map.mapView.removeMouseListener(mode);
    186     Main.map.mapView.removeMouseMotionListener(mode);
     186    Main.map.mapView.removeMouseListener(this.mode);
     187    Main.map.mapView.removeMouseMotionListener(this.mode);
    187188    MapView.removeEditLayerChangeListener(this);
    188189    if (Main.map.mapView.getEditLayer() != null)
     
    209210    double maxLat = -90;
    210211    double maxLon = -180;
    211     for (MapillaryAbstractImage img : data.getImages()) {
     212    for (MapillaryAbstractImage img : this.data.getImages()) {
    212213      if (img.getLatLon().lat() < minLat)
    213214        minLat = img.getLatLon().lat();
     
    225226  @Override
    226227  public boolean isModified() {
    227     for (MapillaryAbstractImage image : data.getImages())
     228    for (MapillaryAbstractImage image : this.data.getImages())
    228229      if (image.isModified())
    229230        return true;
     
    234235  public void setVisible(boolean visible) {
    235236    super.setVisible(visible);
    236     for (MapillaryAbstractImage img : data.getImages())
     237    for (MapillaryAbstractImage img : this.data.getImages())
    237238      img.setVisible(visible);
    238239    MapillaryFilterDialog.getInstance().refresh();
     
    244245   * @return background color for downloaded areas. Black by default
    245246   */
    246   private Color getBackgroundColor() {
     247  private static Color getBackgroundColor() {
    247248    return Main.pref.getColor(marktr("background"), Color.BLACK);
    248249  }
     
    253254   * @return background color for non-downloaded areas. Yellow by default
    254255   */
    255   private Color getOutsideColor() {
     256  private static Color getOutsideColor() {
    256257    return Main.pref.getColor(marktr("outside downloaded area"), Color.YELLOW);
    257258  }
     
    270271    big.drawLine(0, 15, 15, 0);
    271272    Rectangle r = new Rectangle(0, 0, 15, 15);
    272     hatched = new TexturePaint(bi, r);
     273    this.hatched = new TexturePaint(bi, r);
    273274  }
    274275
     
    291292      }
    292293      // paint remainder
    293       g.setPaint(hatched);
     294      g.setPaint(this.hatched);
    294295      g.fill(a);
    295296    }
     
    302303
    303304    // Sets blue and red lines and enables/disables the buttons
    304     if (data.getSelectedImage() != null) {
     305    if (this.data.getSelectedImage() != null) {
    305306      MapillaryImage[] closestImages = getClosestImagesFromDifferentSequences();
    306       Point selected = mv.getPoint(data.getSelectedImage().getLatLon());
     307      Point selected = mv.getPoint(this.data.getSelectedImage().getLatLon());
    307308      if (closestImages[0] != null) {
    308309        MapillaryLayer.BLUE = closestImages[0];
     
    321322    }
    322323    g.setColor(Color.WHITE);
    323     for (MapillaryAbstractImage imageAbs : data.getImages()) {
     324    for (MapillaryAbstractImage imageAbs : this.data.getImages()) {
    324325      if (!imageAbs.isVisible())
    325326        continue;
     
    344345        MapillaryImage image = (MapillaryImage) imageAbs;
    345346        ImageIcon icon;
    346         if (!data.getMultiSelectedImages().contains(image))
     347        if (!this.data.getMultiSelectedImages().contains(image))
    347348          icon = MapillaryPlugin.MAP_ICON;
    348349        else
     
    357358        MapillaryImportedImage image = (MapillaryImportedImage) imageAbs;
    358359        ImageIcon icon;
    359         if (!data.getMultiSelectedImages().contains(image))
     360        if (!this.data.getMultiSelectedImages().contains(image))
    360361          icon = MapillaryPlugin.MAP_ICON_IMPORTED;
    361362        else
     
    364365      }
    365366    }
    366     if (mode instanceof JoinMode) {
    367       mode.paint(g, mv, box);
     367    if (this.mode instanceof JoinMode) {
     368      this.mode.paint(g, mv, box);
    368369    }
    369370  }
     
    382383        highlightColor.getGreen(), highlightColor.getBlue(), 100);
    383384    g.setColor(highlightColorTransparent);
    384     int s = size + highlightPointRadius;
     385    int s = size + this.highlightPointRadius;
    385386    while (s >= size) {
    386387      int r = (int) Math.floor(s / 2d);
    387388      g.fillRoundRect(p.x - r, p.y - r, s, s, r, r);
    388       s -= highlightStep;
     389      s -= this.highlightStep;
    389390    }
    390391    g.setColor(oldColor);
     
    418419    g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2),
    419420        Main.map.mapView);
    420     if (data.getHighlighted() == image) {
     421    if (this.data.getHighlighted() == image) {
    421422      drawPointHighlight(g, p, 16);
    422423    }
     
    455456   */
    456457  private MapillaryImage[] getClosestImagesFromDifferentSequences() {
    457     if (!(data.getSelectedImage() instanceof MapillaryImage))
     458    if (!(this.data.getSelectedImage() instanceof MapillaryImage))
    458459      return new MapillaryImage[2];
    459     MapillaryImage selected = (MapillaryImage) data.getSelectedImage();
     460    MapillaryImage selected = (MapillaryImage) this.data.getSelectedImage();
    460461    MapillaryImage[] ret = new MapillaryImage[2];
    461462    double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE,
    462463        SEQUENCE_MAX_JUMP_DISTANCE };
    463     LatLon selectedCoords = data.getSelectedImage().getLatLon();
    464     for (MapillaryAbstractImage imagePrev : data.getImages()) {
     464    LatLon selectedCoords = this.data.getSelectedImage().getLatLon();
     465    for (MapillaryAbstractImage imagePrev : this.data.getImages()) {
    465466      if (!(imagePrev instanceof MapillaryImage))
    466467        continue;
     
    498499    sb.append(tr("Total images:"));
    499500    sb.append(" ");
    500     sb.append(data.size());
     501    sb.append(this.data.size());
    501502    sb.append("\n");
    502503    return sb.toString();
     
    505506  @Override
    506507  public String getToolTipText() {
    507     return data.size() + " " + tr("images");
     508    return this.data.size() + " " + tr("images");
    508509  }
    509510
     
    519520  }
    520521
    521   /**
    522    * When more data is downloaded, a delayed update is thrown, in order to wait
    523    * for the data bounds to be set.
    524    *
    525    * @param event
    526    */
    527522  @Override
    528523  public void dataChanged(DataChangedEvent event) {
     524    // When more data is downloaded, a delayed update is thrown, in order to
     525    // wait for the data bounds to be set.
    529526    Main.worker.submit(new delayedDownload());
    530527  }
     
    607604  public void updateHelpText() {
    608605    String ret = "";
    609     if (data.size() > 0)
    610       ret += tr("Total images: {0}", data.size());
     606    if (this.data.size() > 0)
     607      ret += tr("Total images: {0}", this.data.size());
    611608    else
    612609      ret += tr("No images found");
    613     if (mode != null)
    614       ret += " -- " + tr(mode.toString());
     610    if (this.mode != null)
     611      ret += " -- " + tr(this.mode.toString());
    615612    Main.map.statusLine.setHelpText(ret);
    616613  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31425 r31445  
    5959  /** Walk action */
    6060  public static MapillaryWalkAction walkAction;
     61  private final MapillaryUploadAction uploadAction;
    6162
    6263  /** Menu button for the {@link MapillaryDownloadAction} action. */
     
    7677  /** Menu button for the {@link MapillaryWalkAction} action. */
    7778  public static JMenuItem WALK_MENU;
     79  /** Menu button for the {@link MapillaryUploadAction} action. */
     80  public static JMenuItem UPLOAD_MENU;
    7881
    7982  /**
     
    8184   *
    8285   * @param info
     86   *          Required information of the plugin. Obtained from the jar file.
    8387   */
    8488  public MapillaryPlugin(PluginInformation info) {
     
    9296    MAP_SIGN = new ImageProvider("sign.png").get();
    9397
    94     downloadAction = new MapillaryDownloadAction();
     98    this.downloadAction = new MapillaryDownloadAction();
    9599    walkAction = new MapillaryWalkAction();
    96     exportAction = new MapillaryExportAction();
     100    this.exportAction = new MapillaryExportAction();
    97101    importAction = new MapillaryImportAction();
    98     zoomAction = new MapillaryZoomAction();
    99     downloadViewAction = new MapillaryDownloadViewAction();
    100     importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
    101     joinAction = new MapillaryJoinAction();
     102    this.zoomAction = new MapillaryZoomAction();
     103    this.downloadViewAction = new MapillaryDownloadViewAction();
     104    this.importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
     105    this.joinAction = new MapillaryJoinAction();
     106    this.uploadAction = new MapillaryUploadAction();
    102107
    103108    if (Main.main != null) { // important for headless mode
    104       DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu, downloadAction,
    105           false);
    106       EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, exportAction, false,
    107           14);
     109      DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu,
     110          this.downloadAction, false);
     111      EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, this.exportAction,
     112          false, 14);
    108113      IMPORT_INTO_SEQUENCE_MENU = MainMenu.add(Main.main.menu.fileMenu,
    109           importIntoSequenceAction, false, 14);
     114          this.importIntoSequenceAction, false, 14);
    110115      IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, false,
    111116          14);
    112       ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
     117      UPLOAD_MENU = MainMenu.add(Main.main.menu.fileMenu, this.uploadAction,
     118          false, 14);
     119      ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, this.zoomAction, false,
     120          15);
    113121      DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,
    114           downloadViewAction, false, 14);
    115       JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, joinAction, false);
     122          this.downloadViewAction, false, 14);
     123      JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, this.joinAction, false);
    116124      WALK_MENU = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false);
    117125
     
    182190   *
    183191   * @param s
    184    * @return A ImageProvider object for the given string or null if in headless mode.
     192   *          The name of the file where the picture is.
     193   * @return A ImageProvider object for the given string or null if in headless
     194   *         mode.
    185195   */
    186196  public static ImageProvider getProvider(String s) {
    187     if (Main.map == null)
     197    if (Main.main == null)
    188198      return null;
    189199    else
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31387 r31445  
    5555   */
    5656  public long getCreatedAt() {
    57     return created_at;
     57    return this.created_at;
    5858  }
    5959
    6060  /**
    61    * Adds a new MapillaryImage object to this object.
     61   * Adds a new {@link MapillaryAbstractImage} object to the database.
    6262   *
    6363   * @param image
     64   *          The {@link MapillaryAbstractImage} object to be added
    6465   */
    6566  public synchronized void add(MapillaryAbstractImage image) {
     
    7980
    8081  /**
    81    * Adds a set of MapillaryImage objects to this object.
     82   * Adds a set of {@link MapillaryAbstractImage} objects to the database.
    8283   *
    8384   * @param images
     85   *          The set of {@link MapillaryAbstractImage} objects to be added.
    8486   */
    8587  public synchronized void add(List<MapillaryAbstractImage> images) {
     
    8991
    9092  /**
    91    * Removes a MapillaryImage object from this object.
     93   * Removes a {@link MapillaryAbstractImage} object from the database.
    9294   *
    9395   * @param image
     96   *          The {@link MapillaryAbstractImage} object to be removed.
    9497   */
    9598  public void remove(MapillaryAbstractImage image) {
     
    106109   */
    107110  public MapillaryAbstractImage next(MapillaryAbstractImage image) {
    108     if (!images.contains(image))
     111    if (!this.images.contains(image))
    109112      throw new IllegalArgumentException();
    110     int i = images.indexOf(image);
    111     if (i == images.size() - 1)
     113    int i = this.images.indexOf(image);
     114    if (i == this.images.size() - 1)
    112115      return null;
    113     return images.get(i + 1);
     116    return this.images.get(i + 1);
    114117  }
    115118
     
    123126   */
    124127  public MapillaryAbstractImage previous(MapillaryAbstractImage image) {
    125     if (!images.contains(image))
     128    if (!this.images.contains(image))
    126129      throw new IllegalArgumentException();
    127     int i = images.indexOf(image);
     130    int i = this.images.indexOf(image);
    128131    if (i == 0)
    129132      return null;
    130     return images.get(i - 1);
     133    return this.images.get(i - 1);
    131134  }
    132135
     
    136139   *
    137140   * @param image1
     141   *          The first image.
    138142   * @param image2
     143   *          The second image.
    139144   * @return The distance between two {@link MapillaryAbstractImage} objects
    140145   *         belonging to the same {@link MapillarySequence}.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryExportAction.java

    r31425 r31445  
    5858    cancel.addActionListener(new CancelAction(pane));
    5959
    60     dialog = new MapillaryExportDialog(ok);
    61     pane.setMessage(dialog);
     60    this.dialog = new MapillaryExportDialog(ok);
     61    pane.setMessage(this.dialog);
    6262    pane.setOptions(new JButton[] { ok, cancel });
    6363
     
    6969    if (pane.getValue() != null
    7070        && (int) pane.getValue() == JOptionPane.OK_OPTION
    71         && dialog.chooser != null) {
    72       if (dialog.group.isSelected(dialog.all.getModel())) {
     71        && this.dialog.chooser != null) {
     72      if (this.dialog.group.isSelected(this.dialog.all.getModel())) {
    7373        export(MapillaryData.getInstance().getImages());
    74       } else if (dialog.group.isSelected(dialog.sequence.getModel())) {
     74      } else if (this.dialog.group.isSelected(this.dialog.sequence.getModel())) {
    7575        ArrayList<MapillaryAbstractImage> images = new ArrayList<>();
    7676        for (MapillaryAbstractImage image : MapillaryData.getInstance()
     
    8282            images.add(image);
    8383        export(images);
    84       } else if (dialog.group.isSelected(dialog.selected.getModel())) {
     84      } else if (this.dialog.group.isSelected(this.dialog.selected.getModel())) {
    8585        export(MapillaryData.getInstance().getMultiSelectedImages());
    8686      }
    8787      // This option ignores the selected directory.
    88     } else if (dialog.group.isSelected(dialog.rewrite.getModel())) {
     88    } else if (this.dialog.group.isSelected(this.dialog.rewrite.getModel())) {
    8989      ArrayList<MapillaryImportedImage> images = new ArrayList<>();
    9090      for (MapillaryAbstractImage image : MapillaryData.getInstance()
     
    110110  public void export(List<MapillaryAbstractImage> images) {
    111111    Main.worker.submit(new Thread(new MapillaryExportManager(images,
    112         dialog.chooser.getSelectedFile().toString())));
     112        this.dialog.chooser.getSelectedFile().toString())));
    113113  }
    114114
     
    122122    @Override
    123123    public void actionPerformed(ActionEvent e) {
    124       pane.setValue(JOptionPane.OK_OPTION);
     124      this.pane.setValue(JOptionPane.OK_OPTION);
    125125    }
    126126  }
     
    135135    @Override
    136136    public void actionPerformed(ActionEvent e) {
    137       pane.setValue(JOptionPane.CANCEL_OPTION);
     137      this.pane.setValue(JOptionPane.CANCEL_OPTION);
    138138    }
    139139  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31425 r31445  
    5959  @Override
    6060  public void actionPerformed(ActionEvent e) {
    61     chooser = new JFileChooser();
     61    this.chooser = new JFileChooser();
    6262    File startDirectory = new File(Main.pref.get("mapillary.start-directory",
    6363        System.getProperty("user.home")));
    64     chooser.setCurrentDirectory(startDirectory);
    65     chooser.setDialogTitle(tr("Select pictures"));
    66     chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    67     chooser.setAcceptAllFileFilterUsed(false);
    68     chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",
    69         "jpeg", "png"));
    70     chooser.setMultiSelectionEnabled(true);
    71     if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    72       for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    73         File file = chooser.getSelectedFiles()[i];
     64    this.chooser.setCurrentDirectory(startDirectory);
     65    this.chooser.setDialogTitle(tr("Select pictures"));
     66    this.chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
     67    this.chooser.setAcceptAllFileFilterUsed(false);
     68    this.chooser.addChoosableFileFilter(new FileNameExtensionFilter("images",
     69        "jpg", "jpeg", "png"));
     70    this.chooser.setMultiSelectionEnabled(true);
     71    if (this.chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
     72      for (int i = 0; i < this.chooser.getSelectedFiles().length; i++) {
     73        File file = this.chooser.getSelectedFiles()[i];
    7474        Main.pref.put("mapillary.start-directory", file.getParent());
    7575        MapillaryLayer.getInstance();
     
    121121   *
    122122   * @param file
     123   *          The file where the picture is located.
    123124   * @return The imported image.
    124125   * @throws ImageReadException
     126   *           If the file isn't an image.
    125127   * @throws IOException
    126    */
    127   public MapillaryImportedImage readJPG(File file) throws ImageReadException,
    128       IOException {
     128   *           If the file doesn't have the valid metadata.
     129   */
     130  public MapillaryImportedImage readJPG(File file) throws IOException,
     131      ImageReadException {
    129132    final ImageMetadata metadata = Imaging.getMetadata(file);
    130133    if (metadata instanceof JpegImageMetadata) {
     
    170173   *
    171174   * @param file
     175   *          The file where the image is located.
    172176   * @return The imported image.
    173177   */
     
    184188   *
    185189   * @param file
     190   *          The file where the image is located.
    186191   * @param pos
    187192   *          A {@link LatLon} object indicating the position in the map where
     
    192197    double HORIZONTAL_DISTANCE = 0.0001;
    193198    double horDev;
    194     if (noTagsPics % 2 == 0)
    195       horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;
     199    if (this.noTagsPics % 2 == 0)
     200      horDev = HORIZONTAL_DISTANCE * this.noTagsPics / 2;
    196201    else
    197       horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
    198     noTagsPics++;
     202      horDev = -HORIZONTAL_DISTANCE * ((this.noTagsPics + 1) / 2);
     203    this.noTagsPics++;
    199204    return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
    200205  }
     
    204209   *
    205210   * @param file
     211   *          The file where the image is located.
    206212   * @return The imported image.
    207213   */
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31425 r31445  
    5050   */
    5151  public MapillaryImportIntoSequenceAction() {
    52     super(tr("Import pictures into sequence"), MapillaryPlugin.getProvider("icon24.png"),
    53         tr("Import local pictures"), Shortcut.registerShortcut(
    54             "Import Mapillary Sequence",
     52    super(tr("Import pictures into sequence"), MapillaryPlugin
     53        .getProvider("icon24.png"), tr("Import local pictures"), Shortcut
     54        .registerShortcut("Import Mapillary Sequence",
    5555            tr("Import pictures into Mapillary layer in a sequence"),
    5656            KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false,
     
    6161  @Override
    6262  public void actionPerformed(ActionEvent arg0) {
    63     images = new LinkedList<>();
    64 
    65     chooser = new JFileChooser();
     63    this.images = new LinkedList<>();
     64
     65    this.chooser = new JFileChooser();
    6666    File startDirectory = new File(Main.pref.get("mapillary.start-directory",
    6767        System.getProperty("user.home")));
    68     chooser.setCurrentDirectory(startDirectory);
    69     chooser.setDialogTitle(tr("Select pictures"));
    70     chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    71     chooser.setAcceptAllFileFilterUsed(false);
    72     chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",
    73         "jpeg"));
    74     chooser.setMultiSelectionEnabled(true);
    75 
    76     if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    77       for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    78         File file = chooser.getSelectedFiles()[i];
     68    this.chooser.setCurrentDirectory(startDirectory);
     69    this.chooser.setDialogTitle(tr("Select pictures"));
     70    this.chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
     71    this.chooser.setAcceptAllFileFilterUsed(false);
     72    this.chooser.addChoosableFileFilter(new FileNameExtensionFilter("images",
     73        "jpg", "jpeg"));
     74    this.chooser.setMultiSelectionEnabled(true);
     75
     76    if (this.chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
     77      for (int i = 0; i < this.chooser.getSelectedFiles().length; i++) {
     78        File file = this.chooser.getSelectedFiles()[i];
    7979        if (file == null)
    8080          break;
     
    117117
    118118  /**
    119    * Reads a jpg pictures that contains the needed GPS information (position and
     119   * Reads a JPG pictures that contains the needed GPS information (position and
    120120   * direction) and creates a new icon in that position.
    121121   *
    122122   * @param file
     123   *          The file where the image is located.
    123124   * @throws ImageReadException
     125   *           If the file doesn't contain an image.
    124126   * @throws IOException
     127   *           If the file doesn't contain valid metadata.
    125128   */
    126129  public void readJPG(File file) throws ImageReadException, IOException {
     
    162165      image.getCapturedAt();
    163166
    164       images.add(image);
     167      this.images.add(image);
    165168    }
    166169  }
     
    170173   */
    171174  public void joinImages() {
    172     Collections.sort(images, new MapillaryEpochComparator());
     175    Collections.sort(this.images, new MapillaryEpochComparator());
    173176    MapillarySequence seq = new MapillarySequence();
    174     for (MapillaryImportedImage img : images) {
     177    for (MapillaryImportedImage img : this.images) {
    175178      seq.add(img);
    176179      img.setSequence(seq);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java

    r31425 r31445  
    3838   */
    3939  public MapillaryWalkAction() {
    40     super(tr("Walk mode"), MapillaryPlugin.getProvider("icon24.png"), tr("Walk mode"),
    41         Shortcut.registerShortcut("Mapillary walk", tr("Start walk mode"),
    42             KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryWalk",
    43         false);
     40    super(tr("Walk mode"), MapillaryPlugin.getProvider("icon24.png"),
     41        tr("Walk mode"), Shortcut.registerShortcut("Mapillary walk",
     42            tr("Start walk mode"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
     43        false, "mapillaryWalk", false);
    4444    this.setEnabled(false);
    4545  }
     
    5555    if (pane.getValue() != null
    5656        && (int) pane.getValue() == JOptionPane.OK_OPTION) {
    57       thread = new WalkThread((int) dialog.spin.getValue(),
     57      this.thread = new WalkThread((int) dialog.spin.getValue(),
    5858          dialog.waitForPicture.isSelected(),
    5959          dialog.followSelection.isSelected(), dialog.goForward.isSelected());
    6060      fireWalkStarted();
    61       thread.start();
     61      this.thread.start();
    6262      MapillaryMainDialog.getInstance().setMode(MapillaryMainDialog.Mode.WALK);
    6363    }
     
    7373   *
    7474   * @param lis
     75   *          The listener to be added.
    7576   */
    7677  public void addListener(WalkListener lis) {
    77     listeners.add(lis);
     78    this.listeners.add(lis);
    7879  }
    7980
     
    8283   *
    8384   * @param lis
     85   *          The listener to be added.
    8486   */
    8587  public void removeListener(WalkListener lis) {
    86     listeners.remove(lis);
     88    this.listeners.remove(lis);
    8789  }
    8890
    8991  private void fireWalkStarted() {
    90     if (listeners.isEmpty())
     92    if (this.listeners.isEmpty())
    9193      return;
    92     for (WalkListener lis : listeners)
    93       lis.walkStarted(thread);
     94    for (WalkListener lis : this.listeners)
     95      lis.walkStarted(this.thread);
    9496  }
    9597
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkListener.java

    r31401 r31445  
    1313   * Called when a new walk thread is started.
    1414   *
    15    * @param thread
     15   * @param thread The thread executing the walk.
    1616   */
    1717  public void walkStarted(WalkThread thread);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java

    r31416 r31445  
    3636   *
    3737   * @param interval
     38   *          How often the images switch.
    3839   * @param waitForPicture
     40   *          If it must wait for the full resolution picture or just the
     41   *          thumbnail.
    3942   * @param followSelected
     43   *          Zoom to each image that is selected.
    4044   * @param goForward
     45   *          true to go forward; false to go backwards.
    4146   */
    4247  public WalkThread(int interval, boolean waitForPicture,
     
    4651    this.followSelected = followSelected;
    4752    this.goForward = goForward;
    48     data = MapillaryLayer.getInstance().getMapillaryData();
    49     data.addListener(this);
     53    this.data = MapillaryLayer.getInstance().getMapillaryData();
     54    this.data.addListener(this);
    5055  }
    5156
     
    5358  public void run() {
    5459    try {
    55       while (!end && data.getSelectedImage().next() != null) {
    56         MapillaryAbstractImage image = data.getSelectedImage();
     60      while (!this.end && this.data.getSelectedImage().next() != null) {
     61        MapillaryAbstractImage image = this.data.getSelectedImage();
    5762        if (image instanceof MapillaryImage) {
    5863          // Predownload next 10 thumbnails.
     
    6469                Utils.PICTURE.THUMBNAIL);
    6570          }
    66         }
    67         if (waitForFullQuality)
    68           // Start downloading 3 next full images.
    69           for (int i = 0; i < 3; i++) {
    70             if (image.next() == null)
    71               break;
    72             image = image.next();
    73             Utils.downloadPicture((MapillaryImage) image, Utils.PICTURE.FULL_IMAGE);
    74           }
     71          if (this.waitForFullQuality)
     72            // Start downloading 3 next full images.
     73            for (int i = 0; i < 3; i++) {
     74              if (image.next() == null)
     75                break;
     76              image = image.next();
     77              Utils.downloadPicture((MapillaryImage) image,
     78                  Utils.PICTURE.FULL_IMAGE);
     79            }
     80        }
    7581        try {
    7682          synchronized (this) {
    77             if (waitForFullQuality
    78                 && data.getSelectedImage() instanceof MapillaryImage) {
     83            if (this.waitForFullQuality && image instanceof MapillaryImage) {
    7984              while (MapillaryMainDialog.getInstance().mapillaryImageDisplay
    80                   .getImage() == lastImage
     85                  .getImage() == this.lastImage
    8186                  || MapillaryMainDialog.getInstance().mapillaryImageDisplay
    8287                      .getImage() == null
     
    8691            } else {
    8792              while (MapillaryMainDialog.getInstance().mapillaryImageDisplay
    88                   .getImage() == lastImage
     93                  .getImage() == this.lastImage
    8994                  || MapillaryMainDialog.getInstance().mapillaryImageDisplay
    9095                      .getImage() == null
     
    9398                wait(100);
    9499            }
    95             while (paused)
     100            while (this.paused)
    96101              wait(100);
    97             wait(interval);
    98             while (paused)
     102            wait(this.interval);
     103            while (this.paused)
    99104              wait(100);
    100105          }
    101           lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay
     106          this.lastImage = MapillaryMainDialog.getInstance().mapillaryImageDisplay
    102107              .getImage();
    103           lock.lock();
    104           if (goForward)
    105             data.selectNext(followSelected);
    106           else
    107             data.selectPrevious(followSelected);
    108           lock.unlock();
     108          this.lock.lock();
     109          try {
     110            if (this.goForward)
     111              this.data.selectNext(this.followSelected);
     112            else
     113              this.data.selectPrevious(this.followSelected);
     114          } finally {
     115            this.lock.unlock();
     116          }
    109117        } catch (InterruptedException e) {
    110118          return;
    111         } finally {
    112           lock.unlock();
    113119        }
    114120      }
     
    121127  @Override
    122128  public void interrupt() {
    123     lock.lock();
     129    this.lock.lock();
    124130    try {
    125131      super.interrupt();
    126132    } catch (Exception e) {
    127133    } finally {
    128       lock.unlock();
     134      this.lock.unlock();
    129135    }
    130136
     
    148154   */
    149155  public void play() {
    150     paused = false;
     156    this.paused = false;
    151157  }
    152158
     
    155161   */
    156162  public void pause() {
    157     paused = true;
     163    this.paused = true;
    158164  }
    159165
     
    187193      });
    188194    } else {
    189       end = true;
    190       data.removeListener(this);
     195      this.end = true;
     196      this.data.removeListener(this);
    191197      MapillaryMainDialog.getInstance()
    192198          .setMode(MapillaryMainDialog.Mode.NORMAL);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java

    r31416 r31445  
    3939   *
    4040   * @param key
     41   *          The key of the image.
    4142   * @param type
     43   *          The type of image that must be downloaded (THUMNAIL or
     44   *          FULL_IMAGE).
    4245   */
    4346  public MapillaryCache(String key, Type type) {
     
    4750      switch (type) {
    4851        case FULL_IMAGE:
    49           url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key
     52          this.url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key
    5053              + "/thumb-2048.jpg");
    5154          this.key += ".FULL_IMAGE";
    5255          break;
    5356        case THUMBNAIL:
    54           url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key
     57          this.url = new URL("https://d1cuyjsrcm0gby.cloudfront.net/" + key
    5558              + "/thumb-320.jpg");
    5659          this.key += ".THUMBNAIL";
     
    6467  @Override
    6568  public String getCacheKey() {
    66     return key;
     69    return this.key;
    6770  }
    6871
    6972  @Override
    7073  public URL getUrl() {
    71     return url;
     74    return this.url;
    7275  }
    7376
     
    7982  @Override
    8083  protected boolean isObjectLoadable() {
    81     if (cacheData == null)
     84    if (this.cacheData == null)
    8285      return false;
    83     byte[] content = cacheData.getContent();
     86    byte[] content = this.cacheData.getContent();
    8487    return content != null && content.length > 0;
    8588  }
    86 
    87   // @Override
    88   protected boolean handleNotFound() {
    89     return false;
    90   }
    9189}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/Utils.java

    r31416 r31445  
    4141   * in cache.
    4242   *
    43    * @param img
     43   * @param img The image to be downloaded.
    4444   * @param pic
    4545   *          The picture type to be downloaded (full quality, thumbnail or
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java

    r31401 r31445  
    2121  /**
    2222   * Main constructor.
    23    * 
     23   *
    2424   * @param images
    2525   *          Set of images that are going to be moved.
     
    3838  @Override
    3939  public void undo() {
    40     for (MapillaryAbstractImage image : images) {
    41       image.move(-x, -y);
     40    for (MapillaryAbstractImage image : this.images) {
     41      image.move(-this.x, -this.y);
    4242      image.stopMoving();
    4343    }
     
    4848  @Override
    4949  public void redo() {
    50     for (MapillaryAbstractImage image : images) {
    51       image.move(x, y);
     50    for (MapillaryAbstractImage image : this.images) {
     51      image.move(this.x, this.y);
    5252      image.stopMoving();
    5353    }
     
    5858  @Override
    5959  public String toString() {
    60     return trn("Moved {0} image", "Moved {0} images", images.size(),
    61         images.size());
     60    return trn("Moved {0} image", "Moved {0} images", this.images.size(),
     61        this.images.size());
    6262  }
    6363
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java

    r31401 r31445  
    2020  /**
    2121   * Main constructor.
    22    * 
     22   *
    2323   * @param images
    2424   *          Set of images that is turned.
     
    3333  @Override
    3434  public void undo() {
    35     for (MapillaryAbstractImage image : images) {
    36       image.turn(-ca);
     35    for (MapillaryAbstractImage image : this.images) {
     36      image.turn(-this.ca);
    3737      image.stopMoving();
    3838    }
     
    4343  @Override
    4444  public void redo() {
    45     for (MapillaryAbstractImage image : images) {
    46       image.turn(ca);
     45    for (MapillaryAbstractImage image : this.images) {
     46      image.turn(this.ca);
    4747      image.stopMoving();
    4848    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryCommand.java

    r31387 r31445  
    77/**
    88 * Abstract class for any Mapillary command.
    9  * 
     9 *
    1010 * @author nokutu
    1111 *
     
    2727   * If two equal commands are applied consecutively to the same set of images,
    2828   * they are summed in order to reduce them to just one command.
    29    * 
    30    * @param command
     29   *
     30   * @param command The command to be summed to last command.
    3131   */
    3232  public abstract void sum(MapillaryCommand command);
     
    3636   */
    3737  public void checkModified() {
    38     for (MapillaryAbstractImage image : images)
     38    for (MapillaryAbstractImage image : this.images)
    3939      image.isModified = (image.tempLatLon == image.latLon || image.tempCa == image.ca);
    4040  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java

    r31401 r31445  
    77/**
    88 * History record system in order to let the user undo and redo commands
    9  * 
     9 *
    1010 * @author nokutu
    1111 *
     
    2626   */
    2727  public MapillaryRecord() {
    28     commandList = new ArrayList<>();
    29     position = -1;
    30     listeners = new ArrayList<>();
     28    this.commandList = new ArrayList<>();
     29    this.position = -1;
     30    this.listeners = new ArrayList<>();
    3131  }
    3232
    3333  /**
    3434   * Returns the unique instance of the class.
    35    * 
     35   *
    3636   * @return The unique instance of the class.
    3737   */
     
    4444  /**
    4545   * Adds a listener.
    46    * 
     46   *
    4747   * @param lis
     48   *          The listener to be added.
    4849   */
    4950  public void addListener(MapillaryRecordListener lis) {
     
    5354  /**
    5455   * Removes the given listener.
    55    * 
     56   *
    5657   * @param lis
     58   *          The listener to be removed.
    5759   */
    5860  public void removeListener(MapillaryRecordListener lis) {
     
    6264  /**
    6365   * Adds a new command to the list.
    64    * 
     66   *
    6567   * @param command
     68   *          The command to be added.
    6669   */
    6770  public void addCommand(MapillaryCommand command) {
    6871    // Checks if it is a continuation of last command
    69     if (position != -1) {
     72    if (this.position != -1) {
    7073      boolean equalSets = true;
    71       for (MapillaryAbstractImage img : commandList.get(position).images)
     74      for (MapillaryAbstractImage img : this.commandList.get(this.position).images)
    7275        if (!command.images.contains(img))
    7376          equalSets = false;
    7477      if (equalSets
    75           && commandList.get(position).getClass() == command.getClass()) {
    76         commandList.get(position).sum(command);
     78          && this.commandList.get(this.position).getClass() == command
     79              .getClass()) {
     80        this.commandList.get(this.position).sum(command);
    7781        fireRecordChanged();
    7882        return;
     
    8084    }
    8185    // Adds the command to the last position of the list.
    82     commandList.add(position + 1, command);
    83     position++;
    84     while (commandList.size() > position + 1) {
    85       commandList.remove(position + 1);
     86    this.commandList.add(this.position + 1, command);
     87    this.position++;
     88    while (this.commandList.size() > this.position + 1) {
     89      this.commandList.remove(this.position + 1);
    8690    }
    8791    fireRecordChanged();
     
    9296   */
    9397  public void undo() {
    94     if (position == -1)
     98    if (this.position == -1)
    9599      return;
    96     commandList.get(position).undo();
    97     position--;
     100    this.commandList.get(this.position).undo();
     101    this.position--;
    98102    fireRecordChanged();
    99103  }
     
    103107   */
    104108  public void redo() {
    105     if (position + 1 >= commandList.size())
     109    if (this.position + 1 >= this.commandList.size())
    106110      return;
    107     position++;
    108     commandList.get(position).redo();
     111    this.position++;
     112    this.commandList.get(this.position).redo();
    109113    fireRecordChanged();
    110114  }
    111115
    112116  private void fireRecordChanged() {
    113     for (MapillaryRecordListener lis : listeners)
     117    for (MapillaryRecordListener lis : this.listeners)
    114118      if (lis != null)
    115119        lis.recordChanged();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31422 r31445  
    1414import org.openstreetmap.josm.data.Bounds;
    1515import org.openstreetmap.josm.data.coor.LatLon;
     16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1617import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1718import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     
    121122   *
    122123   * @param bounds
     124   *          A {@link Bounds} object containing the area to be downloaded.
    123125   */
    124126  public static void getImages(Bounds bounds) {
     
    156158  private static boolean isAreaTooBig() {
    157159    double area = 0;
     160    System.out.println(Main.map.mapView.getLayersOfType(OsmDataLayer.class));
    158161    for (Bounds bounds : Main.map.mapView.getEditLayer().data
    159162        .getDataSourceBounds()) {
     
    172175  public static int getMode() {
    173176    if (Main.pref.get("mapillary.download-mode").equals(MODES[0])
    174         && !MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)
     177        && (MapillaryLayer.INSTANCE == null || !MapillaryLayer.INSTANCE.TEMP_SEMIAUTOMATIC))
    175178      return 0;
    176179    else if (Main.pref.get("mapillary.download-mode").equals(MODES[1])
    177         || MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC)
     180        || (MapillaryLayer.INSTANCE != null && MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC))
    178181      return 1;
    179182    else if (Main.pref.get("mapillary.download-mode").equals(MODES[2]))
    180183      return 2;
     184    else if (Main.pref.get("mapillary.download-mode").equals(""))
     185      return 0;
    181186    else
    182187      throw new IllegalStateException();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportDownloadThread.java

    r31401 r31445  
    2020 * This is the thread that downloads one of the images that are going to be
    2121 * exported and writes them in a {@link ArrayBlockingQueue}.
    22  * 
     22 *
    2323 * @author nokutu
    2424 * @see MapillaryExportManager
     
    3737  /**
    3838   * Main constructor.
    39    * 
     39   *
    4040   * @param image
    4141   *          Image to be downloaded.
     
    5050      ArrayBlockingQueue<BufferedImage> queue,
    5151      ArrayBlockingQueue<MapillaryAbstractImage> queueImages) {
    52     url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey()
     52    this.url = "https://d1cuyjsrcm0gby.cloudfront.net/" + image.getKey()
    5353        + "/thumb-2048.jpg";
    5454    this.queue = queue;
     
    5959  @Override
    6060  public void run() {
    61     new MapillaryCache(image.getKey(), MapillaryCache.Type.FULL_IMAGE).submit(
     61    new MapillaryCache(this.image.getKey(), MapillaryCache.Type.FULL_IMAGE).submit(
    6262        this, false);
    6363  }
     
    6767      LoadResult result) {
    6868    try {
    69       queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent())));
    70       queueImages.put(image);
     69      this.queue.put(ImageIO.read(new ByteArrayInputStream(data.getContent())));
     70      this.queueImages.put(this.image);
    7171    } catch (InterruptedException e) {
    7272      Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java

    r31401 r31445  
    4444  /**
    4545   * Main constructor.
    46    * 
     46   *
    4747   * @param images
    4848   *          Set of {@link MapillaryAbstractImage} objects to be exported.
     
    5353    super(tr("Downloading") + "...", new PleaseWaitProgressMonitor(
    5454        "Exporting Mapillary Images"), true);
    55     queue = new ArrayBlockingQueue<>(10);
    56     queueImages = new ArrayBlockingQueue<>(10);
     55    this.queue = new ArrayBlockingQueue<>(10);
     56    this.queueImages = new ArrayBlockingQueue<>(10);
    5757
    5858    this.images = images;
    59     amount = images.size();
     59    this.amount = images.size();
    6060    this.path = path;
    6161  }
     
    6565   *
    6666   * @param images
     67   *          The set of {@link MapillaryImportedImage} object that is going to
     68   *          be rewritten.
    6769   * @throws IOException
     70   *           If the file of one of the {@link MapillaryImportedImage} objects
     71   *           doesn't contain a picture.
    6872   */
    6973  public MapillaryExportManager(List<MapillaryImportedImage> images)
     
    7175    super(tr("Downloading") + "...", new PleaseWaitProgressMonitor(
    7276        "Exporting Mapillary Images"), true);
    73     queue = new ArrayBlockingQueue<>(10);
    74     queueImages = new ArrayBlockingQueue<>(10);
     77    this.queue = new ArrayBlockingQueue<>(10);
     78    this.queueImages = new ArrayBlockingQueue<>(10);
    7579    for (MapillaryImportedImage image : images) {
    76       queue.add(image.getImage());
    77       queueImages.add(image);
     80      this.queue.add(image.getImage());
     81      this.queueImages.add(image);
    7882    }
    79     amount = images.size();
     83    this.amount = images.size();
    8084  }
    8185
    8286  @Override
    8387  protected void cancel() {
    84     writer.interrupt();
    85     ex.shutdown();
     88    this.writer.interrupt();
     89    this.ex.shutdown();
    8690  }
    8791
     
    9094      OsmTransferException {
    9195    // Starts a writer thread in order to write the pictures on the disk.
    92     writer = new MapillaryExportWriterThread(path, queue, queueImages, amount,
    93         this.getProgressMonitor());
    94     writer.start();
    95     if (path == null) {
     96    this.writer = new MapillaryExportWriterThread(this.path, this.queue,
     97        this.queueImages, this.amount, this.getProgressMonitor());
     98    this.writer.start();
     99    if (this.path == null) {
    96100      try {
    97         writer.join();
     101        this.writer.join();
    98102      } catch (InterruptedException e) {
    99103        Main.error(e);
     
    101105      return;
    102106    }
    103     ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS,
     107    this.ex = new ThreadPoolExecutor(20, 35, 25, TimeUnit.SECONDS,
    104108        new ArrayBlockingQueue<Runnable>(10));
    105     for (MapillaryAbstractImage image : images) {
     109    for (MapillaryAbstractImage image : this.images) {
    106110      if (image instanceof MapillaryImage) {
    107111        try {
    108           ex.execute(new MapillaryExportDownloadThread((MapillaryImage) image,
    109               queue, queueImages));
     112          this.ex.execute(new MapillaryExportDownloadThread(
     113              (MapillaryImage) image, this.queue, this.queueImages));
    110114        } catch (Exception e) {
    111115          Main.error(e);
     
    113117      } else if (image instanceof MapillaryImportedImage) {
    114118        try {
    115           queue.put(((MapillaryImportedImage) image).getImage());
    116           queueImages.put(image);
     119          this.queue.put(((MapillaryImportedImage) image).getImage());
     120          this.queueImages.put(image);
    117121        } catch (InterruptedException e) {
    118122          Main.error(e);
     
    122126        // If the queue is full, waits for it to have more space
    123127        // available before executing anything else.
    124         while (ex.getQueue().remainingCapacity() == 0)
     128        while (this.ex.getQueue().remainingCapacity() == 0)
    125129          Thread.sleep(100);
    126130      } catch (Exception e) {
     
    129133    }
    130134    try {
    131       writer.join();
     135      this.writer.join();
    132136    } catch (InterruptedException e) {
    133137      Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportWriterThread.java

    r31401 r31445  
    33import java.awt.image.BufferedImage;
    44import java.io.BufferedOutputStream;
    5 import java.io.File;
     5import java.io.ByteArrayOutputStream;
    66import java.io.FileOutputStream;
    77import java.io.IOException;
     
    3232/**
    3333 * Writes the images from the queue in the file system.
    34  * 
     34 *
    3535 * @author nokutu
    3636 * @see MapillaryExportManager
     
    4646  /**
    4747   * Main constructor.
    48    * 
     48   *
    4949   * @param path
    5050   *          Path to write the pictures.
     
    7171  @Override
    7272  public void run() {
    73     monitor.setCustomText("Downloaded 0/" + amount);
    74     File tempFile = null;
     73    this.monitor.setCustomText("Downloaded 0/" + this.amount);
     74    //File tempFile = null;
    7575    BufferedImage img;
    7676    MapillaryAbstractImage mimg = null;
    7777    String finalPath = "";
    78     for (int i = 0; i < amount; i++) {
     78    for (int i = 0; i < this.amount; i++) {
    7979      try {
    80         img = queue.take();
    81         mimg = queueImages.take();
     80        img = this.queue.take();
     81        mimg = this.queueImages.take();
    8282        if (img == null || mimg == null)
    8383          throw new IllegalStateException("Null image");
    84         if (path == null && mimg instanceof MapillaryImportedImage) {
     84        if (this.path == null && mimg instanceof MapillaryImportedImage) {
    8585          String path = ((MapillaryImportedImage) mimg).getFile().getPath();
    8686          finalPath = path.substring(0, path.lastIndexOf('.'));
    8787        } else if (mimg instanceof MapillaryImage)
    88           finalPath = path + "/" + ((MapillaryImage) mimg).getKey();
     88          finalPath = this.path + "/" + ((MapillaryImage) mimg).getKey();
    8989        else if (mimg instanceof MapillaryImportedImage)
    90           finalPath = path + "/"
     90          finalPath = this.path + "/"
    9191              + ((MapillaryImportedImage) mimg).getFile().getName();
    9292        ;
    93         // Creates a temporal file that is going to be deleted after
    94         // writing the EXIF tags.
    95         tempFile = new File(finalPath + ".tmp");
    96         ImageIO.write(img, "jpg", tempFile);
     93
     94        // Transforms the image into a byte array.
     95        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     96        ImageIO.write(img, "jpg", outputStream);
     97        byte[] imageBytes = outputStream.toByteArray();
    9798
    9899        // Write EXIF tags
     
    136137        OutputStream os = new BufferedOutputStream(new FileOutputStream(
    137138            finalPath + ".jpg"));
    138         new ExifRewriter().updateExifMetadataLossless(tempFile, os, outputSet);
    139         tempFile.delete();
     139        new ExifRewriter().updateExifMetadataLossless(imageBytes, os, outputSet);
     140
    140141        os.close();
    141142      } catch (InterruptedException e) {
     
    151152
    152153      // Increases the progress bar.
    153       monitor.worked(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX / amount);
    154       monitor.setCustomText("Downloaded " + (i + 1) + "/" + amount);
     154      this.monitor.worked(PleaseWaitProgressMonitor.PROGRESS_BAR_MAX / this.amount);
     155      this.monitor.setCustomText("Downloaded " + (i + 1) + "/" + this.amount);
    155156    }
    156157  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java

    r31401 r31445  
    3131  /**
    3232   * Main constructor.
    33    * 
     33   *
    3434   * @param ex
    3535   *          {@link ExecutorService} object that is executing this thread.
    3636   * @param queryString
     37   *          A String containing the parameters for the download.
    3738   * @param layer
     39   *          The layer to store the data.
    3840   */
    3941  public MapillaryImageInfoDownloaderThread(ExecutorService ex,
     
    4850    try {
    4951      BufferedReader br = new BufferedReader(new InputStreamReader(new URL(URL
    50           + queryString).openStream(), "UTF-8"));
     52          + this.queryString).openStream(), "UTF-8"));
    5153      JsonObject jsonobj = Json.createReader(br).readObject();
    5254      if (!jsonobj.getBoolean("more"))
    53         ex.shutdown();
     55        this.ex.shutdown();
    5456      JsonArray jsonarr = jsonobj.getJsonArray("ims");
    5557      JsonObject data;
     
    5759        data = jsonarr.getJsonObject(i);
    5860        String key = data.getString("key");
    59         for (MapillaryAbstractImage image : layer.getMapillaryData()
     61        for (MapillaryAbstractImage image : this.layer.getMapillaryData()
    6062            .getImages()) {
    6163          if (image instanceof MapillaryImage) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31418 r31445  
    1818import org.openstreetmap.josm.Main;
    1919import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     20import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    2021import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    2122import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     
    4445   *
    4546   * @param ex
     47   *          {@link ExecutorService} executing this thread.
    4648   * @param queryString
     49   *          String containing the parameters for the download.
    4750   */
    4851  public MapillarySequenceDownloadThread(ExecutorService ex, String queryString) {
     
    5760      BufferedReader br;
    5861      br = new BufferedReader(new InputStreamReader(
    59           new URL(URL + queryString).openStream(), "UTF-8"));
     62          new URL(URL + this.queryString).openStream(), "UTF-8"));
    6063      JsonObject jsonall = Json.createReader(br).readObject();
    6164
    62       if (!jsonall.getBoolean("more") && !ex.isShutdown())
    63         ex.shutdown();
     65      if (!jsonall.getBoolean("more") && !this.ex.isShutdown())
     66        this.ex.shutdown();
    6467      JsonArray jsonseq = jsonall.getJsonArray("ss");
    6568      boolean isSequenceWrong = false;
     
    7780                .getJsonNumber(j).doubleValue()));
    7881          } catch (IndexOutOfBoundsException e) {
    79             Main.warn("Mapillary bug at " + URL + queryString);
     82            Main.warn("Mapillary bug at " + URL + this.queryString);
    8083            isSequenceWrong = true;
    8184          }
     
    9598
    9699        LOCK.lock();
    97         MapillaryImage.LOCK.lock();
     100        MapillaryAbstractImage.LOCK.lock();
    98101        try {
    99102          for (MapillaryImage img : finalImages) {
    100             if (layer.getMapillaryData().getImages().contains(img)) {
     103            if (this.layer.getMapillaryData().getImages().contains(img)) {
    101104              // The image in finalImages is substituted by the one in the
    102105              // database, as they represent the same picture.
    103               img = (MapillaryImage) layer.getMapillaryData().getImages()
    104                   .get(layer.getMapillaryData().getImages().indexOf(img));
     106              img = (MapillaryImage) this.layer.getMapillaryData().getImages()
     107                  .get(this.layer.getMapillaryData().getImages().indexOf(img));
    105108              sequence.add(img);
    106               ((MapillaryImage) layer.getMapillaryData().getImages()
    107                   .get(layer.getMapillaryData().getImages().indexOf(img)))
     109              ((MapillaryImage) this.layer.getMapillaryData().getImages()
     110                  .get(this.layer.getMapillaryData().getImages().indexOf(img)))
    108111                  .setSequence(sequence);
    109112              finalImages.set(finalImages.indexOf(img), img);
     
    114117          }
    115118        } finally {
    116           MapillaryImage.LOCK.unlock();
     119          MapillaryAbstractImage.LOCK.unlock();
    117120          LOCK.unlock();
    118121        }
    119122
    120         layer.getMapillaryData().add(
     123        this.layer.getMapillaryData().add(
    121124            new ArrayList<MapillaryAbstractImage>(finalImages), false);
    122125      }
    123126    } catch (IOException e) {
    124       Main.error("Error reading the url " + URL + queryString
     127      Main.error("Error reading the url " + URL + this.queryString
    125128          + " might be a Mapillary problem.");
    126129    }
    127     layer.getMapillaryData().dataUpdated();
     130    MapillaryData.dataUpdated();
    128131  }
    129132
    130133  private boolean isInside(MapillaryAbstractImage image) {
    131     for (int i = 0; i < layer.bounds.size(); i++)
    132       if (layer.bounds.get(i).contains(image.getLatLon()))
     134    for (int i = 0; i < this.layer.bounds.size(); i++)
     135      if (this.layer.bounds.get(i).contains(image.getLatLon()))
    133136        return true;
    134137    return false;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31409 r31445  
    1212
    1313import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    1415import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1516import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
     
    3637   *
    3738   * @param queryStringParts
     39   *          The query data.
    3840   * @param layer
     41   *          The layer to store the images.
    3942   *
    4043   */
     
    4649
    4750    // TODO: Move this line to the appropriate place, here's no GET-request
    48     Main.info("GET " + sequenceQueryString + " (Mapillary plugin)");
     51    Main.info("GET " + this.sequenceQueryString + " (Mapillary plugin)");
    4952
    5053    this.layer = layer;
     
    5255
    5356  // TODO: Maybe move into a separate utility class?
    54   private String buildQueryString(ConcurrentHashMap<String, Double> hash) {
     57  private static String buildQueryString(ConcurrentHashMap<String, Double> hash) {
    5558    StringBuilder ret = new StringBuilder("?client_id="
    5659        + MapillaryDownloader.CLIENT_ID);
     
    8184      Main.error("Mapillary download interrupted (probably because of closing the layer).");
    8285    }
    83     layer.updateHelpText();
    84     layer.getMapillaryData().dataUpdated();
     86    this.layer.updateHelpText();
     87    MapillaryData.dataUpdated();
    8588    MapillaryFilterDialog.getInstance().refresh();
    8689    MapillaryMainDialog.getInstance().updateImage();
     
    9295    int page = 0;
    9396    while (!ex.isShutdown()) {
    94       ex.execute(new MapillarySequenceDownloadThread(ex, sequenceQueryString
    95           + "&page=" + page + "&limit=10"));
     97      ex.execute(new MapillarySequenceDownloadThread(ex,
     98          this.sequenceQueryString + "&page=" + page + "&limit=10"));
    9699      while (ex.getQueue().remainingCapacity() == 0)
    97100        Thread.sleep(500);
     
    99102    }
    100103    ex.awaitTermination(15, TimeUnit.SECONDS);
    101     layer.getMapillaryData().dataUpdated();
     104    MapillaryData.dataUpdated();
    102105  }
    103106
     
    107110    int page = 0;
    108111    while (!ex.isShutdown()) {
    109       ex.execute(new MapillaryImageInfoDownloaderThread(ex, imageQueryString
    110           + "&page=" + page + "&limit=20", layer));
     112      ex.execute(new MapillaryImageInfoDownloaderThread(ex,
     113          this.imageQueryString + "&page=" + page + "&limit=20", this.layer));
    111114      while (ex.getQueue().remainingCapacity() == 0)
    112115        Thread.sleep(100);
     
    121124    int page = 0;
    122125    while (!ex.isShutdown()) {
    123       ex.execute(new MapillaryTrafficSignDownloaderThread(ex, signQueryString
    124           + "&page=" + page + "&limit=20", layer));
     126      ex.execute(new MapillaryTrafficSignDownloaderThread(ex,
     127          this.signQueryString + "&page=" + page + "&limit=20", this.layer));
    125128      while (ex.getQueue().remainingCapacity() == 0)
    126129        Thread.sleep(100);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryTrafficSignDownloaderThread.java

    r31409 r31445  
    3636   *          {@link ExecutorService} object that is executing this thread.
    3737   * @param queryString
     38   *          A String containing the parameter for the download.
    3839   * @param layer
     40   *          The layer to store the data.
    3941   */
    4042  public MapillaryTrafficSignDownloaderThread(ExecutorService ex,
     
    5052    try {
    5153      br = new BufferedReader(new InputStreamReader(
    52           new URL(URL + queryString).openStream(), "UTF-8"));
     54          new URL(URL + this.queryString).openStream(), "UTF-8"));
    5355      JsonObject jsonobj = Json.createReader(br).readObject();
    5456      if (!jsonobj.getBoolean("more")) {
    55         ex.shutdown();
     57        this.ex.shutdown();
    5658      }
    5759      JsonArray jsonarr = jsonobj.getJsonArray("ims");
     
    6668            for (int k = 0; k < rects.size(); k++) {
    6769              JsonObject data = rects.getJsonObject(k);
    68               for (MapillaryAbstractImage image : layer.getMapillaryData()
     70              for (MapillaryAbstractImage image : this.layer.getMapillaryData()
    6971                  .getImages())
    7072                if (image instanceof MapillaryImage
     
    7981          for (int j = 0; j < rects.size(); j++) {
    8082            JsonObject data = rects.getJsonObject(j);
    81             for (MapillaryAbstractImage image : layer.getMapillaryData()
     83            for (MapillaryAbstractImage image : this.layer.getMapillaryData()
    8284                .getImages())
    8385              if (image instanceof MapillaryImage
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31399 r31445  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
     5import java.awt.AWTEvent;
    56import java.awt.Cursor;
    67import java.awt.event.ActionEvent;
     
    1314
    1415import javax.swing.JLabel;
    15 import javax.swing.SwingUtilities;
     16import javax.swing.SwingConstants;
    1617
    1718import org.openstreetmap.josm.Main;
     
    3536   */
    3637  public HyperlinkLabel() {
    37     super(tr("View in website"), SwingUtilities.RIGHT);
     38    super(tr("View in website"), SwingConstants.RIGHT);
    3839    this.addActionListener(this);
    3940    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    4041
    41     enableEvents(MouseEvent.MOUSE_EVENT_MASK);
     42    enableEvents(AWTEvent.MOUSE_EVENT_MASK);
    4243  }
    4344
     
    5657   *
    5758   * @param key
     59   *          The key of the image that the hyperlink will point to.
    5860   */
    5961  public void setURL(String key) {
     
    7577   */
    7678  public String getNormalText() {
    77     return text;
     79    return this.text;
    7880  }
    7981
     
    9496   *
    9597   * @param listener
     98   *          The listener to be added.
    9699   */
    97100  public void addActionListener(ActionListener listener) {
    98     listenerList.add(ActionListener.class, listener);
     101    this.listenerList.add(ActionListener.class, listener);
    99102  }
    100103
     
    104107   *
    105108   * @param listener
     109   *          The listener to be added.
    106110   */
    107111  public void removeActionListener(ActionListener listener) {
    108     listenerList.remove(ActionListener.class, listener);
     112    this.listenerList.remove(ActionListener.class, listener);
    109113  }
    110114
     
    115119   */
    116120  protected void fireActionPerformed(ActionEvent evt) {
    117     Object[] listeners = listenerList.getListenerList();
     121    Object[] listeners = this.listenerList.getListenerList();
    118122    for (int i = 0; i < listeners.length; i += 2) {
    119123      if (listeners[i] == ActionListener.class) {
     
    131135    if (desktop.isSupported(Desktop.Action.BROWSE)) {
    132136      try {
    133         desktop.browse(url.toURI());
     137        desktop.browse(this.url.toURI());
    134138      } catch (IOException | URISyntaxException e1) {
    135139        Main.error(e1);
     
    138142      Runtime runtime = Runtime.getRuntime();
    139143      try {
    140         runtime.exec("xdg-open " + url);
     144        runtime.exec("xdg-open " + this.url);
    141145      } catch (IOException exc) {
    142146        exc.printStackTrace();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r31401 r31445  
    5656  /**
    5757   * Main constructor.
    58    * 
     58   *
    5959   * @param ok
     60   *          The button for to OK option.
    6061   */
    6162  public MapillaryExportDialog(JButton ok) {
     
    6667
    6768    RewriteButtonAction action = new RewriteButtonAction(this);
    68     group = new ButtonGroup();
    69     all = new JRadioButton(action);
    70     all.setText(tr("Export all images"));
    71     sequence = new JRadioButton(action);
    72     sequence.setText(tr("Export selected sequence"));
    73     selected = new JRadioButton(action);
    74     selected.setText(tr("Export selected images"));
    75     rewrite = new JRadioButton(action);
    76     rewrite.setText(tr("Rewrite imported images"));
    77     group.add(all);
    78     group.add(sequence);
    79     group.add(selected);
    80     group.add(rewrite);
     69    this.group = new ButtonGroup();
     70    this.all = new JRadioButton(action);
     71    this.all.setText(tr("Export all images"));
     72    this.sequence = new JRadioButton(action);
     73    this.sequence.setText(tr("Export selected sequence"));
     74    this.selected = new JRadioButton(action);
     75    this.selected.setText(tr("Export selected images"));
     76    this.rewrite = new JRadioButton(action);
     77    this.rewrite.setText(tr("Rewrite imported images"));
     78    this.group.add(this.all);
     79    this.group.add(this.sequence);
     80    this.group.add(this.selected);
     81    this.group.add(this.rewrite);
    8182    // Some options are disabled depending on the circumstances
    8283    if (MapillaryData.getInstance().getSelectedImage() == null
    8384        || !(MapillaryData.getInstance().getSelectedImage() instanceof MapillaryImage && ((MapillaryImage) MapillaryData
    8485            .getInstance().getSelectedImage()).getSequence() != null)) {
    85       sequence.setEnabled(false);
     86      this.sequence.setEnabled(false);
    8687    }
    8788    if (MapillaryData.getInstance().getMultiSelectedImages().isEmpty()) {
    88       selected.setEnabled(false);
     89      this.selected.setEnabled(false);
    8990    }
    90     rewrite.setEnabled(false);
     91    this.rewrite.setEnabled(false);
    9192    for (MapillaryAbstractImage img : MapillaryData.getInstance().getImages())
    9293      if (img instanceof MapillaryImportedImage)
    93         rewrite.setEnabled(true);
     94        this.rewrite.setEnabled(true);
    9495
    95     path = new JLabel(tr("Select a folder"));
    96     choose = new JButton(tr("Explore"));
    97     choose.addActionListener(this);
     96    this.path = new JLabel(tr("Select a folder"));
     97    this.choose = new JButton(tr("Explore"));
     98    this.choose.addActionListener(this);
    9899
    99100    // All options belong to the same jpanel so the are in line.
    100101    JPanel jpanel = new JPanel();
    101102    jpanel.setLayout(new BoxLayout(jpanel, BoxLayout.PAGE_AXIS));
    102     jpanel.add(all);
    103     jpanel.add(sequence);
    104     jpanel.add(selected);
    105     jpanel.add(rewrite);
     103    jpanel.add(this.all);
     104    jpanel.add(this.sequence);
     105    jpanel.add(this.selected);
     106    jpanel.add(this.rewrite);
    106107    jpanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    107     path.setAlignmentX(Component.CENTER_ALIGNMENT);
    108     choose.setAlignmentX(Component.CENTER_ALIGNMENT);
     108    this.path.setAlignmentX(Component.CENTER_ALIGNMENT);
     109    this.choose.setAlignmentX(Component.CENTER_ALIGNMENT);
    109110
    110111    add(jpanel);
    111     add(path);
    112     add(choose);
     112    add(this.path);
     113    add(this.choose);
    113114  }
    114115
     
    118119  @Override
    119120  public void actionPerformed(ActionEvent e) {
    120     chooser = new JFileChooser();
    121     chooser.setCurrentDirectory(new java.io.File(System
     121    this.chooser = new JFileChooser();
     122    this.chooser.setCurrentDirectory(new java.io.File(System
    122123        .getProperty("user.home")));
    123     chooser.setDialogTitle(tr("Select a directory"));
    124     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    125     chooser.setAcceptAllFileFilterUsed(false);
     124    this.chooser.setDialogTitle(tr("Select a directory"));
     125    this.chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     126    this.chooser.setAcceptAllFileFilterUsed(false);
    126127
    127     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
    128       path.setText(chooser.getSelectedFile().toString());
     128    if (this.chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     129      this.path.setText(this.chooser.getSelectedFile().toString());
    129130      this.updateUI();
    130       ok.setEnabled(true);
     131      this.ok.setEnabled(true);
    131132    }
    132133  }
     
    157158    @Override
    158159    public void actionPerformed(ActionEvent arg0) {
    159       choose.setEnabled(!rewrite.isSelected());
    160       if (rewrite.isSelected()) {
    161         lastPath = dlg.path.getText();
    162         dlg.path.setText(" ");
    163       } else if (lastPath != null) {
    164         dlg.path.setText(lastPath);
     160      MapillaryExportDialog.this.choose.setEnabled(!MapillaryExportDialog.this.rewrite.isSelected());
     161      if (MapillaryExportDialog.this.rewrite.isSelected()) {
     162        this.lastPath = this.dlg.path.getText();
     163        this.dlg.path.setText(" ");
     164      } else if (this.lastPath != null) {
     165        this.dlg.path.setText(this.lastPath);
    165166      }
    166167
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterChooseSigns.java

    r31389 r31445  
    4949
    5050  private MapillaryFilterChooseSigns() {
    51     maxSpeed.setSelected(true);
    52     stop.setSelected(true);
    53     giveWay.setSelected(true);
    54     roundabout.setSelected(true);
    55     access.setSelected(true);
    56     intersection.setSelected(true);
    57     direction.setSelected(true);
    58     uneven.setSelected(true);
    59     noParking.setSelected(true);
    60     noOvertaking.setSelected(true);
    61     crossing.setSelected(true);
    62     noTurn.setSelected(true);
     51    this.maxSpeed.setSelected(true);
     52    this.stop.setSelected(true);
     53    this.giveWay.setSelected(true);
     54    this.roundabout.setSelected(true);
     55    this.access.setSelected(true);
     56    this.intersection.setSelected(true);
     57    this.direction.setSelected(true);
     58    this.uneven.setSelected(true);
     59    this.noParking.setSelected(true);
     60    this.noOvertaking.setSelected(true);
     61    this.crossing.setSelected(true);
     62    this.noTurn.setSelected(true);
    6363
    6464    // Max speed sign
     
    6767    maxspeedLabel.setIcon(new ImageProvider("signs/speed.png").get());
    6868    maxspeedPanel.add(maxspeedLabel);
    69     maxspeedPanel.add(maxSpeed);
     69    maxspeedPanel.add(this.maxSpeed);
    7070    this.add(maxspeedPanel);
    7171
     
    7575    stopLabel.setIcon(new ImageProvider("signs/stop.png").get());
    7676    stopPanel.add(stopLabel);
    77     stopPanel.add(stop);
     77    stopPanel.add(this.stop);
    7878    this.add(stopPanel);
    7979
     
    8383    giveWayLabel.setIcon(new ImageProvider("signs/right_of_way.png").get());
    8484    giveWayPanel.add(giveWayLabel);
    85     giveWayPanel.add(giveWay);
     85    giveWayPanel.add(this.giveWay);
    8686    this.add(giveWayPanel);
    8787
     
    9292        .get());
    9393    roundaboutPanel.add(roundaboutLabel);
    94     roundaboutPanel.add(roundabout);
     94    roundaboutPanel.add(this.roundabout);
    9595    this.add(roundaboutPanel);
    9696
     
    100100    noEntryLabel.setIcon(new ImageProvider("signs/no_entry.png").get());
    101101    noEntryPanel.add(noEntryLabel);
    102     noEntryPanel.add(access);
     102    noEntryPanel.add(this.access);
    103103    this.add(noEntryPanel);
    104104
     
    109109        .setIcon(new ImageProvider("signs/intersection_danger.png").get());
    110110    intersectionPanel.add(intersectionLabel);
    111     intersectionPanel.add(intersection);
     111    intersectionPanel.add(this.intersection);
    112112    this.add(intersectionPanel);
    113113
     
    118118        .get());
    119119    directionPanel.add(directionLabel);
    120     directionPanel.add(direction);
     120    directionPanel.add(this.direction);
    121121    this.add(directionPanel);
    122122
     
    126126    noTurnLabel.setIcon(new ImageProvider("signs/no_turn.png").get());
    127127    noTurnPanel.add(noTurnLabel);
    128     noTurnPanel.add(noTurn);
     128    noTurnPanel.add(this.noTurn);
    129129    this.add(noTurnPanel);
    130130
     
    134134    unevenLabel.setIcon(new ImageProvider("signs/uneaven.png").get());
    135135    unevenPanel.add(unevenLabel);
    136     unevenPanel.add(uneven);
     136    unevenPanel.add(this.uneven);
    137137    this.add(unevenPanel);
    138138
     
    142142    noParkingLabel.setIcon(new ImageProvider("signs/no_parking.png").get());
    143143    noParkingPanel.add(noParkingLabel);
    144     noParkingPanel.add(noParking);
     144    noParkingPanel.add(this.noParking);
    145145    this.add(noParkingPanel);
    146146
     
    151151        .get());
    152152    noOvertakingPanel.add(noOvertakingLabel);
    153     noOvertakingPanel.add(noOvertaking);
     153    noOvertakingPanel.add(this.noOvertaking);
    154154    this.add(noOvertakingPanel);
    155155
     
    159159    crossingLabel.setIcon(new ImageProvider("signs/crossing.png").get());
    160160    crossingPanel.add(crossingLabel);
    161     crossingPanel.add(crossing);
     161    crossingPanel.add(this.crossing);
    162162    this.add(crossingPanel);
    163163
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryFilterDialog.java

    r31415 r31445  
    7878      "prohibitory_noturn" };
    7979  /** The the {@link JCheckBox} where the respective tag should be searched */
    80   private final JCheckBox[] SIGN_CHECKBOXES = { signFilter.maxSpeed,
    81       signFilter.stop, signFilter.giveWay, signFilter.roundabout,
    82       signFilter.access, signFilter.access, signFilter.intersection,
    83       signFilter.direction, signFilter.direction, signFilter.intersection,
    84       signFilter.uneven, signFilter.noParking, signFilter.noOvertaking,
    85       signFilter.crossing, signFilter.noTurn, signFilter.noTurn };
     80  private final JCheckBox[] SIGN_CHECKBOXES = { this.signFilter.maxSpeed,
     81      this.signFilter.stop, this.signFilter.giveWay, this.signFilter.roundabout,
     82      this.signFilter.access, this.signFilter.access, this.signFilter.intersection,
     83      this.signFilter.direction, this.signFilter.direction, this.signFilter.intersection,
     84      this.signFilter.uneven, this.signFilter.noParking, this.signFilter.noOvertaking,
     85      this.signFilter.crossing, this.signFilter.noTurn, this.signFilter.noTurn };
    8686
    8787  private MapillaryFilterDialog() {
     
    9191            KeyEvent.VK_M, Shortcut.NONE), 200);
    9292
    93     signChooser.setEnabled(false);
     93    this.signChooser.setEnabled(false);
    9494    JPanel signChooserPanel = new JPanel();
    9595    signChooserPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    96     signChooserPanel.add(signChooser);
     96    signChooserPanel.add(this.signChooser);
    9797
    9898    JPanel fromPanel = new JPanel();
    9999    fromPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    100100    fromPanel.add(new JLabel("Not older than: "));
    101     spinner = new SpinnerNumberModel(1, 0, 10000, 1);
    102     fromPanel.add(new JSpinner(spinner));
    103     time = new JComboBox<>(TIME_LIST);
    104     fromPanel.add(time);
     101    this.spinner = new SpinnerNumberModel(1, 0, 10000, 1);
     102    fromPanel.add(new JSpinner(this.spinner));
     103    this.time = new JComboBox<>(TIME_LIST);
     104    fromPanel.add(this.time);
    105105
    106106    JPanel userSearchPanel = new JPanel();
    107107    userSearchPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    108     user = new JTextField(10);
    109     user.addActionListener(new UpdateAction());
     108    this.user = new JTextField(10);
     109    this.user.addActionListener(new UpdateAction());
    110110    userSearchPanel.add(new JLabel("User"));
    111     userSearchPanel.add(user);
    112 
    113     imported.setSelected(true);
    114     downloaded.setSelected(true);
     111    userSearchPanel.add(this.user);
     112
     113    this.imported.setSelected(true);
     114    this.downloaded.setSelected(true);
    115115
    116116    JPanel col1 = new JPanel(new GridLayout(2, 1));
    117     col1.add(downloaded);
     117    col1.add(this.downloaded);
    118118    col1.add(fromPanel);
    119     panel.add(col1);
     119    this.panel.add(col1);
    120120    JPanel col2 = new JPanel(new GridLayout(2, 1));
    121     col2.add(imported);
     121    col2.add(this.imported);
    122122    col2.add(userSearchPanel);
    123     panel.add(col2);
     123    this.panel.add(col2);
    124124    JPanel col3 = new JPanel(new GridLayout(2, 1));
    125     col3.add(onlySigns);
     125    col3.add(this.onlySigns);
    126126    col3.add(signChooserPanel);
    127     panel.add(col3);
    128 
    129     createLayout(panel, true,
    130         Arrays.asList(new SideButton[] { updateButton, resetButton }));
     127    this.panel.add(col3);
     128
     129    createLayout(this.panel, true,
     130        Arrays.asList(new SideButton[] { this.updateButton, this.resetButton }));
    131131  }
    132132
     
    156156   */
    157157  public void reset() {
    158     imported.setSelected(true);
    159     downloaded.setSelected(true);
    160     onlySigns.setEnabled(true);
    161     onlySigns.setSelected(false);
    162     user.setText("");
    163     time.setSelectedItem(TIME_LIST[0]);
    164     spinner.setValue(1);
     158    this.imported.setSelected(true);
     159    this.downloaded.setSelected(true);
     160    this.onlySigns.setEnabled(true);
     161    this.onlySigns.setSelected(false);
     162    this.user.setText("");
     163    this.time.setSelectedItem(TIME_LIST[0]);
     164    this.spinner.setValue(1);
    165165    refresh();
    166166  }
     
    195195          }
    196196        }
    197         if (!user.getText().equals("")
    198             && !user.getText().equals(((MapillaryImage) img).getUser())) {
     197        if (!this.user.getText().equals("")
     198            && !this.user.getText().equals(((MapillaryImage) img).getUser())) {
    199199          img.setVisible(false);
    200200          continue;
     
    203203      // Calculates the amount of days since the image was taken
    204204      Long currentTime = currentTime();
    205       if (time.getSelectedItem().equals(TIME_LIST[1])) {
     205      if (this.time.getSelectedItem().equals(TIME_LIST[1])) {
    206206        if (img.getCapturedAt() < currentTime
    207             - ((Integer) spinner.getValue()).longValue() * 365 * 24 * 60 * 60
     207            - ((Integer) this.spinner.getValue()).longValue() * 365 * 24 * 60 * 60
    208208            * 1000) {
    209209          img.setVisible(false);
     
    211211        }
    212212      }
    213       if (time.getSelectedItem().equals(TIME_LIST[2])) {
     213      if (this.time.getSelectedItem().equals(TIME_LIST[2])) {
    214214        if (img.getCapturedAt() < currentTime
    215             - ((Integer) spinner.getValue()).longValue() * 30 * 24 * 60 * 60
     215            - ((Integer) this.spinner.getValue()).longValue() * 30 * 24 * 60 * 60
    216216            * 1000) {
    217217          img.setVisible(false);
     
    219219        }
    220220      }
    221       if (time.getSelectedItem().equals(TIME_LIST[3])) {
     221      if (this.time.getSelectedItem().equals(TIME_LIST[3])) {
    222222        if (img.getCapturedAt() < currentTime
    223             - ((Integer) spinner.getValue()).longValue() * 60 * 60 * 1000) {
     223            - ((Integer) this.spinner.getValue()).longValue() * 60 * 60 * 1000) {
    224224          img.setVisible(false);
    225225          continue;
     
    240240   */
    241241  private boolean checkSigns(MapillaryImage img) {
    242     for (int i = 0; i < SIGN_TAGS.length; i++) {
    243       if (checkSign(img, SIGN_CHECKBOXES[i], SIGN_TAGS[i]))
     242    for (int i = 0; i < this.SIGN_TAGS.length; i++) {
     243      if (checkSign(img, this.SIGN_CHECKBOXES[i], this.SIGN_TAGS[i]))
    244244        return true;
    245245    }
     
    247247  }
    248248
    249   private boolean checkSign(MapillaryImage img, JCheckBox signCheckBox,
     249  private static boolean checkSign(MapillaryImage img, JCheckBox signCheckBox,
    250250      String singString) {
    251251    boolean contains = false;
     
    259259  }
    260260
    261   private long currentTime() {
     261  private static long currentTime() {
    262262    Calendar cal = Calendar.getInstance();
    263263    return cal.getTimeInMillis();
     
    274274    @Override
    275275    public void actionPerformed(ActionEvent arg0) {
    276       onlySigns.setEnabled(downloaded.isSelected());
     276      MapillaryFilterDialog.this.onlySigns.setEnabled(MapillaryFilterDialog.this.downloaded.isSelected());
    277277    }
    278278  }
     
    318318    @Override
    319319    public void actionPerformed(ActionEvent arg0) {
    320       signChooser.setEnabled(onlySigns.isSelected());
     320      MapillaryFilterDialog.this.signChooser.setEnabled(MapillaryFilterDialog.this.onlySigns.isSelected());
    321321    }
    322322  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java

    r31389 r31445  
    55import java.awt.Component;
    66import java.awt.Dimension;
     7import java.awt.GridBagConstraints;
    78import java.awt.GridBagLayout;
    89import java.awt.event.ActionEvent;
     
    5051  private final DefaultTreeModel redoTreeModel = new DefaultTreeModel(
    5152      new DefaultMutableTreeNode());
    52   private final JTree undoTree = new JTree(undoTreeModel);
    53   private final JTree redoTree = new JTree(redoTreeModel);
     53  private final JTree undoTree = new JTree(this.undoTreeModel);
     54  private final JTree redoTree = new JTree(this.redoTreeModel);
    5455
    5556  private JSeparator separator = new JSeparator();
     
    6768    MapillaryRecord.getInstance().addListener(this);
    6869
    69     undoTree.expandRow(0);
    70     undoTree.setShowsRootHandles(true);
    71     undoTree.setRootVisible(false);
    72     undoTree.setCellRenderer(new MapillaryCellRenderer());
    73     redoTree.expandRow(0);
    74     redoTree.setCellRenderer(new MapillaryCellRenderer());
    75     redoTree.setShowsRootHandles(true);
    76     redoTree.setRootVisible(false);
     70    this.undoTree.expandRow(0);
     71    this.undoTree.setShowsRootHandles(true);
     72    this.undoTree.setRootVisible(false);
     73    this.undoTree.setCellRenderer(new MapillaryCellRenderer());
     74    this.redoTree.expandRow(0);
     75    this.redoTree.setCellRenderer(new MapillaryCellRenderer());
     76    this.redoTree.setShowsRootHandles(true);
     77    this.redoTree.setRootVisible(false);
    7778
    7879    JPanel treesPanel = new JPanel(new GridBagLayout());
    79     treesPanel.add(spacer, GBC.eol());
    80     spacer.setVisible(false);
    81     treesPanel.add(undoTree, GBC.eol().fill(GBC.HORIZONTAL));
    82     separator.setVisible(false);
    83     treesPanel.add(separator, GBC.eol().fill(GBC.HORIZONTAL));
    84     treesPanel.add(redoTree, GBC.eol().fill(GBC.HORIZONTAL));
     80    treesPanel.add(this.spacer, GBC.eol());
     81    this.spacer.setVisible(false);
     82    treesPanel.add(this.undoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     83    this.separator.setVisible(false);
     84    treesPanel.add(this.separator, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     85    treesPanel.add(this.redoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
    8586    treesPanel.add(Box.createRigidArea(new Dimension(0, 0)),
    8687        GBC.std().weight(0, 1));
    87     treesPanel.setBackground(redoTree.getBackground());
    88 
    89     undoButton = new SideButton(new UndoAction());
    90     redoButton = new SideButton(new RedoAction());
     88    treesPanel.setBackground(this.redoTree.getBackground());
     89
     90    this.undoButton = new SideButton(new UndoAction());
     91    this.redoButton = new SideButton(new RedoAction());
    9192
    9293    createLayout(treesPanel, true,
    93         Arrays.asList(new SideButton[] { undoButton, redoButton }));
     94        Arrays.asList(new SideButton[] { this.undoButton, this.redoButton }));
    9495  }
    9596
     
    106107
    107108  private void buildTree() {
    108     redoButton.setEnabled(true);
    109     undoButton.setEnabled(true);
     109    this.redoButton.setEnabled(true);
     110    this.undoButton.setEnabled(true);
    110111    ArrayList<MapillaryCommand> commands = MapillaryRecord.getInstance().commandList;
    111112    int position = MapillaryRecord.getInstance().position;
     
    114115      undoCommands = new ArrayList<>(commands.subList(0, position + 1));
    115116    else
    116       undoButton.setEnabled(false);
     117      this.undoButton.setEnabled(false);
    117118    ArrayList<MapillaryCommand> redoCommands = new ArrayList<>();
    118119    if (commands.size() > 0 && position + 1 < commands.size())
     
    120121          commands.size()));
    121122    else
    122       redoButton.setEnabled(false);
     123      this.redoButton.setEnabled(false);
    123124
    124125    DefaultMutableTreeNode redoRoot = new DefaultMutableTreeNode();
     
    134135    }
    135136
    136     separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty());
    137     spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty());
    138 
    139     undoTreeModel.setRoot(undoRoot);
    140     redoTreeModel.setRoot(redoRoot);
     137    this.separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty());
     138    this.spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty());
     139
     140    this.undoTreeModel.setRoot(undoRoot);
     141    this.redoTreeModel.setRoot(redoRoot);
    141142  }
    142143
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31389 r31445  
    7777        visibleRect = MapillaryImageDisplay.this.visibleRect;
    7878      }
    79       mouseIsDragging = false;
    80       selectedRect = null;
     79      this.mouseIsDragging = false;
     80      MapillaryImageDisplay.this.selectedRect = null;
    8181      if (image == null)
    8282        return;
     
    8787      // borders, this point is not calculated
    8888      // again if there was less than 1.5seconds since the last event.
    89       if (e.getWhen() - lastTimeForMousePoint > 1500 || mousePointInImg == null) {
    90         lastTimeForMousePoint = e.getWhen();
    91         mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
     89      if (e.getWhen() - this.lastTimeForMousePoint > 1500 || this.mousePointInImg == null) {
     90        this.lastTimeForMousePoint = e.getWhen();
     91        this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
    9292      }
    9393      // Applicate the zoom to the visible rectangle in image coordinates
     
    119119      // cursor doesn't move on the image.
    120120      Rectangle drawRect = calculateDrawImageRectangle(visibleRect);
    121       visibleRect.x = mousePointInImg.x
     121      visibleRect.x = this.mousePointInImg.x
    122122          + ((drawRect.x - e.getX()) * visibleRect.width) / drawRect.width;
    123       visibleRect.y = mousePointInImg.y
     123      visibleRect.y = this.mousePointInImg.y
    124124          + ((drawRect.y - e.getY()) * visibleRect.height) / drawRect.height;
    125125      // The position is also limited by the image size
     
    178178    @Override
    179179    public void mousePressed(MouseEvent e) {
    180       if (image == null) {
    181         mouseIsDragging = false;
    182         selectedRect = null;
     180      if (MapillaryImageDisplay.this.image == null) {
     181        this.mouseIsDragging = false;
     182        MapillaryImageDisplay.this.selectedRect = null;
    183183        return;
    184184      }
     
    192192        return;
    193193      if (e.getButton() == DRAG_BUTTON) {
    194         mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
    195         mouseIsDragging = true;
    196         selectedRect = null;
     194        this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
     195        this.mouseIsDragging = true;
     196        MapillaryImageDisplay.this.selectedRect = null;
    197197      } else if (e.getButton() == ZOOM_BUTTON) {
    198         mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
    199         checkPointInVisibleRect(mousePointInImg, visibleRect);
    200         mouseIsDragging = false;
    201         selectedRect = new Rectangle(mousePointInImg.x, mousePointInImg.y, 0, 0);
     198        this.mousePointInImg = comp2imgCoord(visibleRect, e.getX(), e.getY());
     199        checkPointInVisibleRect(this.mousePointInImg, visibleRect);
     200        this.mouseIsDragging = false;
     201        MapillaryImageDisplay.this.selectedRect = new Rectangle(this.mousePointInImg.x, this.mousePointInImg.y, 0, 0);
    202202        MapillaryImageDisplay.this.repaint();
    203203      } else {
    204         mouseIsDragging = false;
    205         selectedRect = null;
     204        this.mouseIsDragging = false;
     205        MapillaryImageDisplay.this.selectedRect = null;
    206206      }
    207207    }
     
    209209    @Override
    210210    public void mouseDragged(MouseEvent e) {
    211       if (!mouseIsDragging && selectedRect == null)
     211      if (!this.mouseIsDragging && MapillaryImageDisplay.this.selectedRect == null)
    212212        return;
    213213      Image image;
     
    218218      }
    219219      if (image == null) {
    220         mouseIsDragging = false;
    221         selectedRect = null;
    222         return;
    223       }
    224       if (mouseIsDragging) {
     220        this.mouseIsDragging = false;
     221        MapillaryImageDisplay.this.selectedRect = null;
     222        return;
     223      }
     224      if (this.mouseIsDragging) {
    225225        Point p = comp2imgCoord(visibleRect, e.getX(), e.getY());
    226         visibleRect.x += mousePointInImg.x - p.x;
    227         visibleRect.y += mousePointInImg.y - p.y;
     226        visibleRect.x += this.mousePointInImg.x - p.x;
     227        visibleRect.y += this.mousePointInImg.y - p.y;
    228228        checkVisibleRectPos(image, visibleRect);
    229229        synchronized (MapillaryImageDisplay.this) {
     
    231231        }
    232232        MapillaryImageDisplay.this.repaint();
    233       } else if (selectedRect != null) {
     233      } else if (MapillaryImageDisplay.this.selectedRect != null) {
    234234        Point p = comp2imgCoord(visibleRect, e.getX(), e.getY());
    235235        checkPointInVisibleRect(p, visibleRect);
    236         Rectangle rect = new Rectangle(p.x < mousePointInImg.x ? p.x
    237             : mousePointInImg.x, p.y < mousePointInImg.y ? p.y
    238             : mousePointInImg.y, p.x < mousePointInImg.x ? mousePointInImg.x
    239             - p.x : p.x - mousePointInImg.x,
    240             p.y < mousePointInImg.y ? mousePointInImg.y - p.y : p.y
    241                 - mousePointInImg.y);
     236        Rectangle rect = new Rectangle(p.x < this.mousePointInImg.x ? p.x
     237            : this.mousePointInImg.x, p.y < this.mousePointInImg.y ? p.y
     238            : this.mousePointInImg.y, p.x < this.mousePointInImg.x ? this.mousePointInImg.x
     239            - p.x : p.x - this.mousePointInImg.x,
     240            p.y < this.mousePointInImg.y ? this.mousePointInImg.y - p.y : p.y
     241                - this.mousePointInImg.y);
    242242        checkVisibleRectSize(image, rect);
    243243        checkVisibleRectPos(image, rect);
     
    249249    @Override
    250250    public void mouseReleased(MouseEvent e) {
    251       if (!mouseIsDragging && selectedRect == null)
     251      if (!this.mouseIsDragging && MapillaryImageDisplay.this.selectedRect == null)
    252252        return;
    253253      Image image;
     
    256256      }
    257257      if (image == null) {
    258         mouseIsDragging = false;
    259         selectedRect = null;
    260         return;
    261       }
    262       if (mouseIsDragging) {
    263         mouseIsDragging = false;
    264       } else if (selectedRect != null) {
    265         int oldWidth = selectedRect.width;
    266         int oldHeight = selectedRect.height;
     258        this.mouseIsDragging = false;
     259        MapillaryImageDisplay.this.selectedRect = null;
     260        return;
     261      }
     262      if (this.mouseIsDragging) {
     263        this.mouseIsDragging = false;
     264      } else if (MapillaryImageDisplay.this.selectedRect != null) {
     265        int oldWidth = MapillaryImageDisplay.this.selectedRect.width;
     266        int oldHeight = MapillaryImageDisplay.this.selectedRect.height;
    267267        // Check that the zoom doesn't exceed 2:1
    268         if (selectedRect.width < getSize().width / 2) {
    269           selectedRect.width = getSize().width / 2;
    270         }
    271         if (selectedRect.height < getSize().height / 2) {
    272           selectedRect.height = getSize().height / 2;
     268        if (MapillaryImageDisplay.this.selectedRect.width < getSize().width / 2) {
     269          MapillaryImageDisplay.this.selectedRect.width = getSize().width / 2;
     270        }
     271        if (MapillaryImageDisplay.this.selectedRect.height < getSize().height / 2) {
     272          MapillaryImageDisplay.this.selectedRect.height = getSize().height / 2;
    273273        }
    274274        // Set the same ratio for the visible rectangle and the display
    275275        // area
    276         int hFact = selectedRect.height * getSize().width;
    277         int wFact = selectedRect.width * getSize().height;
     276        int hFact = MapillaryImageDisplay.this.selectedRect.height * getSize().width;
     277        int wFact = MapillaryImageDisplay.this.selectedRect.width * getSize().height;
    278278        if (hFact > wFact) {
    279           selectedRect.width = hFact / getSize().height;
     279          MapillaryImageDisplay.this.selectedRect.width = hFact / getSize().height;
    280280        } else {
    281           selectedRect.height = wFact / getSize().width;
     281          MapillaryImageDisplay.this.selectedRect.height = wFact / getSize().width;
    282282        }
    283283        // Keep the center of the selection
    284         if (selectedRect.width != oldWidth) {
    285           selectedRect.x -= (selectedRect.width - oldWidth) / 2;
    286         }
    287         if (selectedRect.height != oldHeight) {
    288           selectedRect.y -= (selectedRect.height - oldHeight) / 2;
    289         }
    290         checkVisibleRectSize(image, selectedRect);
    291         checkVisibleRectPos(image, selectedRect);
     284        if (MapillaryImageDisplay.this.selectedRect.width != oldWidth) {
     285          MapillaryImageDisplay.this.selectedRect.x -= (MapillaryImageDisplay.this.selectedRect.width - oldWidth) / 2;
     286        }
     287        if (MapillaryImageDisplay.this.selectedRect.height != oldHeight) {
     288          MapillaryImageDisplay.this.selectedRect.y -= (MapillaryImageDisplay.this.selectedRect.height - oldHeight) / 2;
     289        }
     290        checkVisibleRectSize(image, MapillaryImageDisplay.this.selectedRect);
     291        checkVisibleRectPos(image, MapillaryImageDisplay.this.selectedRect);
    292292        synchronized (MapillaryImageDisplay.this) {
    293           MapillaryImageDisplay.this.visibleRect = selectedRect;
    294         }
    295         selectedRect = null;
     293          MapillaryImageDisplay.this.visibleRect = MapillaryImageDisplay.this.selectedRect;
     294        }
     295        MapillaryImageDisplay.this.selectedRect = null;
    296296        MapillaryImageDisplay.this.repaint();
    297297      }
     
    337337    JPanel southPanel = new JPanel();
    338338    southPanel.setLayout(new BorderLayout());
    339     hyperlink = new HyperlinkLabel();
    340     southPanel.add(hyperlink, BorderLayout.EAST);
     339    this.hyperlink = new HyperlinkLabel();
     340    southPanel.add(this.hyperlink, BorderLayout.EAST);
    341341    southPanel.setOpaque(false);
    342342
     
    347347   * Sets a new picture to be displayed.
    348348   *
    349    * @param image
     349   * @param image The picture to be displayed.
    350350   */
    351351  public void setImage(BufferedImage image) {
    352352    synchronized (this) {
    353353      this.image = image;
    354       selectedRect = null;
     354      this.selectedRect = null;
    355355      if (image != null)
    356356        this.visibleRect = new Rectangle(0, 0, image.getWidth(null),
     
    394394          + target.height, visibleRect.x, visibleRect.y, visibleRect.x
    395395          + visibleRect.width, visibleRect.y + visibleRect.height, null);
    396       if (selectedRect != null) {
    397         Point topLeft = img2compCoord(visibleRect, selectedRect.x,
    398             selectedRect.y);
    399         Point bottomRight = img2compCoord(visibleRect, selectedRect.x
    400             + selectedRect.width, selectedRect.y + selectedRect.height);
     396      if (this.selectedRect != null) {
     397        Point topLeft = img2compCoord(visibleRect, this.selectedRect.x,
     398            this.selectedRect.y);
     399        Point bottomRight = img2compCoord(visibleRect, this.selectedRect.x
     400            + this.selectedRect.width, this.selectedRect.y + this.selectedRect.height);
    401401        g.setColor(new Color(128, 128, 128, 180));
    402402        g.fillRect(target.x, target.y, target.width, topLeft.y - target.y);
     
    427427  }
    428428
    429   private final Point getCenterImgCoord(Rectangle visibleRect) {
     429  private final static Point getCenterImgCoord(Rectangle visibleRect) {
    430430    return new Point(visibleRect.x + visibleRect.width / 2, visibleRect.y
    431431        + visibleRect.height / 2);
     
    498498  }
    499499
    500   private final void checkVisibleRectPos(Image image, Rectangle visibleRect) {
     500  private final static void checkVisibleRectPos(Image image, Rectangle visibleRect) {
    501501    if (visibleRect.x < 0) {
    502502      visibleRect.x = 0;
     
    513513  }
    514514
    515   private void checkVisibleRectSize(Image image, Rectangle visibleRect) {
     515  private static void checkVisibleRectSize(Image image, Rectangle visibleRect) {
    516516    if (visibleRect.width > image.getWidth(null)) {
    517517      visibleRect.width = image.getWidth(null);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31409 r31445  
    9999    MapillaryData.getInstance().addListener(this);
    100100    addShortcuts();
    101     mapillaryImageDisplay = new MapillaryImageDisplay();
    102 
    103     blueButton.setForeground(Color.BLUE);
    104     redButton.setForeground(Color.RED);
     101    this.mapillaryImageDisplay = new MapillaryImageDisplay();
     102
     103    this.blueButton.setForeground(Color.BLUE);
     104    this.redButton.setForeground(Color.RED);
    105105
    106106    createLayout(
    107         mapillaryImageDisplay,
    108         Arrays.asList(new SideButton[] { blueButton, previousButton,
    109             nextButton, redButton }),
     107        this.mapillaryImageDisplay,
     108        Arrays.asList(new SideButton[] { this.blueButton, this.previousButton,
     109            this.nextButton, this.redButton }),
    110110        Main.pref.getBoolean("mapillary.reverse-buttons"));
    111111    disableAllButtons();
     
    117117   */
    118118  private void addShortcuts() {
    119     nextButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     119    this.nextButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    120120        KeyStroke.getKeyStroke("PAGE_DOWN"), "next");
    121     nextButton.getActionMap().put("next", new nextPictureAction());
    122     previousButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     121    this.nextButton.getActionMap().put("next", new nextPictureAction());
     122    this.previousButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    123123        KeyStroke.getKeyStroke("PAGE_UP"), "previous");
    124     previousButton.getActionMap().put("previous", new previousPictureAction());
    125     blueButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     124    this.previousButton.getActionMap().put("previous",
     125        new previousPictureAction());
     126    this.blueButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    126127        KeyStroke.getKeyStroke("control PAGE_UP"), "blue");
    127     blueButton.getActionMap().put("blue", new blueAction());
    128     redButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
     128    this.blueButton.getActionMap().put("blue", new blueAction());
     129    this.redButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    129130        KeyStroke.getKeyStroke("control PAGE_DOWN"), "red");
    130     redButton.getActionMap().put("red", new redAction());
     131    this.redButton.getActionMap().put("red", new redAction());
    131132  }
    132133
     
    143144
    144145  /**
     146   * Sets a new mode for the dialog.
     147   *
    145148   * @param mode
     149   *          The mode to be set.
    146150   */
    147151  public void setMode(Mode mode) {
     
    149153      case NORMAL:
    150154        createLayout(
    151             mapillaryImageDisplay,
    152             Arrays.asList(new SideButton[] { blueButton, previousButton,
    153                 nextButton, redButton }),
     155            this.mapillaryImageDisplay,
     156            Arrays.asList(new SideButton[] { this.blueButton,
     157                this.previousButton, this.nextButton, this.redButton }),
    154158            Main.pref.getBoolean("mapillary.reverse-buttons"));
    155159        break;
    156160      case WALK:
    157161        createLayout(
    158             mapillaryImageDisplay,
    159             Arrays.asList(new SideButton[] { playButton, pauseButton,
    160                 stopButton }),
     162            this.mapillaryImageDisplay,
     163            Arrays.asList(new SideButton[] { this.playButton, this.pauseButton,
     164                this.stopButton }),
    161165            Main.pref.getBoolean("mapillary.reverse-buttons"));
    162166        break;
     
    202206      }
    203207      if (this.image == null) {
    204         mapillaryImageDisplay.setImage(null);
     208        this.mapillaryImageDisplay.setImage(null);
    205209        setTitle(tr(BASE_TITLE));
    206210        disableAllButtons();
     
    210214      this.nextButton.setEnabled(false);
    211215      this.previousButton.setEnabled(false);
    212       if (image.getSequence() != null) {
    213         MapillaryAbstractImage tempImage = image;
     216      if (this.image.getSequence() != null) {
     217        MapillaryAbstractImage tempImage = this.image;
    214218        while (tempImage.next() != null) {
    215219          tempImage = tempImage.next();
     
    220224        }
    221225      }
    222       if (image.getSequence() != null) {
    223         MapillaryAbstractImage tempImage = image;
     226      if (this.image.getSequence() != null) {
     227        MapillaryAbstractImage tempImage = this.image;
    224228        while (tempImage.previous() != null) {
    225229          tempImage = tempImage.previous();
     
    230234        }
    231235      }
    232       if (image instanceof MapillaryImage) {
    233         mapillaryImageDisplay.hyperlink.setVisible(true);
     236      if (this.image instanceof MapillaryImage) {
     237        this.mapillaryImageDisplay.hyperlink.setVisible(true);
    234238        MapillaryImage mapillaryImage = (MapillaryImage) this.image;
    235         mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
     239        this.mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
    236240        // Downloads the thumbnail.
    237241        this.mapillaryImageDisplay.setImage(null);
    238         if (thumbnailCache != null)
    239           thumbnailCache.cancelOutstandingTasks();
    240         thumbnailCache = new MapillaryCache(mapillaryImage.getKey(),
     242        if (this.thumbnailCache != null)
     243          this.thumbnailCache.cancelOutstandingTasks();
     244        this.thumbnailCache = new MapillaryCache(mapillaryImage.getKey(),
    241245            MapillaryCache.Type.THUMBNAIL);
    242         thumbnailCache.submit(this, false);
     246        this.thumbnailCache.submit(this, false);
    243247
    244248        // Downloads the full resolution image.
    245249        if (fullQuality) {
    246           if (imageCache != null)
    247             imageCache.cancelOutstandingTasks();
    248           imageCache = new MapillaryCache(mapillaryImage.getKey(),
     250          if (this.imageCache != null)
     251            this.imageCache.cancelOutstandingTasks();
     252          this.imageCache = new MapillaryCache(mapillaryImage.getKey(),
    249253              MapillaryCache.Type.FULL_IMAGE);
    250           imageCache.submit(this, false);
    251         }
    252       } else if (image instanceof MapillaryImportedImage) {
    253         mapillaryImageDisplay.hyperlink.setVisible(false);
    254         mapillaryImageDisplay.hyperlink.setURL(null);
     254          this.imageCache.submit(this, false);
     255        }
     256      } else if (this.image instanceof MapillaryImportedImage) {
     257        this.mapillaryImageDisplay.hyperlink.setVisible(false);
     258        this.mapillaryImageDisplay.hyperlink.setURL(null);
    255259        MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image;
    256260        try {
    257           mapillaryImageDisplay.setImage(mapillaryImage.getImage());
     261          this.mapillaryImageDisplay.setImage(mapillaryImage.getImage());
    258262        } catch (IOException e) {
    259263          Main.error(e);
     
    266270
    267271  private void disableAllButtons() {
    268     nextButton.setEnabled(false);
    269     previousButton.setEnabled(false);
    270     blueButton.setEnabled(false);
    271     redButton.setEnabled(false);
    272     mapillaryImageDisplay.hyperlink.setVisible(false);
     272    this.nextButton.setEnabled(false);
     273    this.previousButton.setEnabled(false);
     274    this.blueButton.setEnabled(false);
     275    this.redButton.setEnabled(false);
     276    this.mapillaryImageDisplay.hyperlink.setVisible(false);
    273277  }
    274278
     
    277281   *
    278282   * @param image
     283   *          The image to be shown.
    279284   */
    280285  public synchronized void setImage(MapillaryAbstractImage image) {
     
    429434    @Override
    430435    public void actionPerformed(ActionEvent e) {
    431       if (thread != null)
    432         thread.stopWalk();
     436      if (this.thread != null)
     437        this.thread.stopWalk();
    433438    }
    434439
     
    453458    @Override
    454459    public void actionPerformed(ActionEvent e) {
    455       if (thread != null)
    456         thread.play();
     460      if (this.thread != null)
     461        this.thread.play();
    457462    }
    458463
     
    479484    @Override
    480485    public void actionPerformed(ActionEvent e) {
    481       thread.pause();
     486      this.thread.pause();
    482487    }
    483488
     
    510515          return;
    511516        if (this.mapillaryImageDisplay.getImage() == null)
    512           mapillaryImageDisplay.setImage(img);
     517          this.mapillaryImageDisplay.setImage(img);
    513518        else if (img.getHeight() > this.mapillaryImageDisplay.getImage()
    514519            .getHeight()) {
    515           mapillaryImageDisplay.setImage(img);
     520          this.mapillaryImageDisplay.setImage(img);
    516521        }
    517522      } catch (IOException e) {
     
    539544    panel.add(data, BorderLayout.CENTER);
    540545    if (reverse) {
    541       buttonsPanel = new JPanel(new GridLayout(1, 1));
     546      this.buttonsPanel = new JPanel(new GridLayout(1, 1));
    542547      if (!buttons.isEmpty() && buttons.get(0) != null) {
    543548        final JPanel buttonRowPanel = new JPanel(Main.pref.getBoolean(
    544549            "dialog.align.left", false) ? new FlowLayout(FlowLayout.LEFT)
    545550            : new GridLayout(1, buttons.size()));
    546         buttonsPanel.add(buttonRowPanel);
     551        this.buttonsPanel.add(buttonRowPanel);
    547552        for (SideButton button : buttons)
    548553          buttonRowPanel.add(button);
    549554      }
    550       panel.add(buttonsPanel, BorderLayout.NORTH);
     555      panel.add(this.buttonsPanel, BorderLayout.NORTH);
    551556      createLayout(panel, true, null);
    552557    } else
    553558      createLayout(panel, true, buttons);
    554     this.add(titleBar, BorderLayout.NORTH);
     559    this.add(this.titleBar, BorderLayout.NORTH);
    555560  }
    556561
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31418 r31445  
    77import java.awt.event.ActionEvent;
    88import java.io.IOException;
     9import java.net.MalformedURLException;
    910import java.net.URI;
    1011import java.net.URISyntaxException;
     
    2324import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    2425import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader;
     26import org.openstreetmap.josm.plugins.mapillary.oauth.MapillaryUser;
    2527import org.openstreetmap.josm.plugins.mapillary.oauth.OAuthPortListener;
    2628
     
    5254    JPanel panel = new JPanel();
    5355
    54     reverseButtons.setSelected(Main.pref
     56    this.reverseButtons.setSelected(Main.pref
    5557        .getBoolean("mapillary.reverse-buttons"));
    56     displayHour.setSelected(Main.pref
     58    this.displayHour.setSelected(Main.pref
    5759        .getBoolean("mapillary.display-hour", true));
    58     format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));
    59     moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));
     60    this.format24.setSelected(Main.pref.getBoolean("mapillary.format-24"));
     61    this.moveTo.setSelected(Main.pref.getBoolean("mapillary.move-to-picture", true));
    6062
    6163    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    62     panel.add(reverseButtons);
     64    panel.add(this.reverseButtons);
    6365
    6466    // Sets the value of the ComboBox.
    6567    if (Main.pref.get("mapillary.download-mode").equals(
    6668        MapillaryDownloader.MODES[0]))
    67       downloadMode.setSelectedItem(MapillaryDownloader.MODES[0]);
     69      this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[0]);
    6870    if (Main.pref.get("mapillary.download-mode").equals(
    6971        MapillaryDownloader.MODES[1]))
    70       downloadMode.setSelectedItem(MapillaryDownloader.MODES[1]);
     72      this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[1]);
    7173    if (Main.pref.get("mapillary.download-mode").equals(
    7274        MapillaryDownloader.MODES[2]))
    73       downloadMode.setSelectedItem(MapillaryDownloader.MODES[2]);
     75      this.downloadMode.setSelectedItem(MapillaryDownloader.MODES[2]);
    7476    JPanel downloadModePanel = new JPanel();
    7577    downloadModePanel.add(new JLabel(tr("Download mode: ")));
    76     downloadModePanel.add(downloadMode);
     78    downloadModePanel.add(this.downloadMode);
    7779    panel.add(downloadModePanel);
    7880
    79     panel.add(displayHour);
    80     panel.add(format24);
    81     panel.add(moveTo);
     81    panel.add(this.displayHour);
     82    panel.add(this.format24);
     83    panel.add(this.moveTo);
    8284    JButton oauth = new JButton(new OAuthAction());
    8385    if (Main.pref.get("mapillary.access-token") == null)
    8486      oauth.setText("Login");
    8587    else
    86       oauth.setText("Logged as: " + Main.pref.get("mapillary.username") + ". Click to relogin.");
     88      try {
     89        oauth.setText("Logged as: " + MapillaryUser.getUsername() + ". Click to relogin.");
     90      } catch (MalformedURLException e) {
     91        // TODO Auto-generated catch block
     92        e.printStackTrace();
     93      } catch (IOException e) {
     94        // TODO Auto-generated catch block
     95        e.printStackTrace();
     96      }
    8797    panel.add(oauth);
    8898    gui.getDisplayPreference().addSubTab(this, "Mapillary", panel);
     
    92102  public boolean ok() {
    93103    boolean mod = false;
    94     Main.pref.put("mapillary.reverse-buttons", reverseButtons.isSelected());
     104    Main.pref.put("mapillary.reverse-buttons", this.reverseButtons.isSelected());
    95105
    96106    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false);
    97     if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0]))
     107    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[0]))
    98108      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[0]);
    99     if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1]))
     109    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[1]))
    100110      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[1]);
    101     if (downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) {
     111    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES[2])) {
    102112      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES[2]);
    103113      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
    104114    }
    105115
    106     Main.pref.put("mapillary.display-hour", displayHour.isSelected());
    107     Main.pref.put("mapillary.format-24", format24.isSelected());
    108     Main.pref.put("mapillary.move-to-picture", moveTo.isSelected());
     116    Main.pref.put("mapillary.display-hour", this.displayHour.isSelected());
     117    Main.pref.put("mapillary.format-24", this.format24.isSelected());
     118    Main.pref.put("mapillary.move-to-picture", this.moveTo.isSelected());
    109119    return mod;
    110120  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryWalkDialog.java

    r31416 r31445  
    3232  public MapillaryWalkDialog() {
    3333    JPanel interval = new JPanel();
    34     spin = new SpinnerNumberModel(2000, 500, 10000, 500);
     34    this.spin = new SpinnerNumberModel(2000, 500, 10000, 500);
    3535    interval.add(new JLabel("Interval (miliseconds): "));
    36     interval.add(new JSpinner(spin));
     36    interval.add(new JSpinner(this.spin));
    3737    add(interval);
    3838
    39     waitForPicture = new JCheckBox("Wait for full quality pictures");
    40     waitForPicture.setSelected(true);
    41     add(waitForPicture);
     39    this.waitForPicture = new JCheckBox("Wait for full quality pictures");
     40    this.waitForPicture.setSelected(true);
     41    add(this.waitForPicture);
    4242
    43     followSelection = new JCheckBox("Follow selected image");
    44     followSelection.setSelected(true);
    45     add(followSelection);
     43    this.followSelection = new JCheckBox("Follow selected image");
     44    this.followSelection.setSelected(true);
     45    add(this.followSelection);
    4646
    47     goForward = new JCheckBox("Go forward");
    48     goForward.setSelected(true);
    49     add(goForward);
     47    this.goForward = new JCheckBox("Go forward");
     48    this.goForward.setSelected(true);
     49    add(this.goForward);
    5050  }
    5151}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/AbstractMode.java

    r31422 r31445  
    4040    double minDistance = Double.MAX_VALUE;
    4141    MapillaryAbstractImage closest = null;
    42     for (MapillaryAbstractImage image : data.getImages()) {
     42    for (MapillaryAbstractImage image : this.data.getImages()) {
    4343      Point imagePoint = Main.map.mapView.getPoint(image.getLatLon());
    4444      imagePoint.setLocation(imagePoint.getX(), imagePoint.getY());
     
    5454
    5555  /**
    56    * Paints whatever the mode needs.
    57    *
     56   * Paint the dataset using the engine set.
    5857   * @param g
    59    * @param mv
     58   * @param mv The object that can translate GeoPoints to screen coordinates.
    6059   * @param box
    6160   */
     
    8988    public void run() {
    9089      while (true) {
    91         if (moved
    92             && Calendar.getInstance().getTimeInMillis() - lastDownload >= DOWNLOAD_COOLDOWN) {
    93           lastDownload = Calendar.getInstance().getTimeInMillis();
     90        if (this.moved
     91            && Calendar.getInstance().getTimeInMillis() - this.lastDownload >= DOWNLOAD_COOLDOWN) {
     92          this.lastDownload = Calendar.getInstance().getTimeInMillis();
    9493          MapillaryDownloader.completeView();
    95           moved = false;
    96           MapillaryData.getInstance().dataUpdated();
     94          this.moved = false;
     95          MapillaryData.dataUpdated();
    9796        }
    9897        synchronized (this) {
     
    106105
    107106    public void moved() {
    108       moved = true;
     107      this.moved = true;
    109108    }
    110109  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java

    r31389 r31445  
    1212import org.openstreetmap.josm.gui.MapView;
    1313import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     14import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    1415import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    1516import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     
    3132   */
    3233  public JoinMode() {
    33     cursor = Cursor.CROSSHAIR_CURSOR;
     34    this.cursor = Cursor.CROSSHAIR_CURSOR;
    3435  }
    3536
    3637  @Override
    3738  public void mousePressed(MouseEvent e) {
    38     if (data.getHighlighted() == null)
     39    if (this.data.getHighlighted() == null)
    3940      return;
    40     if (lastClick == null
    41         && data.getHighlighted() instanceof MapillaryImportedImage) {
    42       lastClick = (MapillaryImportedImage) data.getHighlighted();
    43     } else if (lastClick != null
    44         && data.getHighlighted() instanceof MapillaryImportedImage) {
    45       if (((data.getHighlighted().previous() == null && lastClick.next() == null) || (data
    46           .getHighlighted().next() == null && lastClick.previous() == null))
    47           && (data.getHighlighted().getSequence() != lastClick.getSequence() || lastClick
     41    if (this.lastClick == null
     42        && this.data.getHighlighted() instanceof MapillaryImportedImage) {
     43      this.lastClick = (MapillaryImportedImage) this.data.getHighlighted();
     44    } else if (this.lastClick != null
     45        && this.data.getHighlighted() instanceof MapillaryImportedImage) {
     46      if (((this.data.getHighlighted().previous() == null && this.lastClick.next() == null) || (this.data
     47          .getHighlighted().next() == null && this.lastClick.previous() == null))
     48          && (this.data.getHighlighted().getSequence() != this.lastClick.getSequence() || this.lastClick
    4849              .getSequence() == null)) {
    49         join(lastClick, (MapillaryImportedImage) data.getHighlighted());
    50       } else if (lastClick.next() == data.getHighlighted()
    51           || lastClick.previous() == data.getHighlighted())
    52         unjoin(lastClick, (MapillaryImportedImage) data.getHighlighted());
    53       lastClick = null;
     50        join(this.lastClick, (MapillaryImportedImage) this.data.getHighlighted());
     51      } else if (this.lastClick.next() == this.data.getHighlighted()
     52          || this.lastClick.previous() == this.data.getHighlighted())
     53        unjoin(this.lastClick, (MapillaryImportedImage) this.data.getHighlighted());
     54      this.lastClick = null;
    5455    }
    55     data.dataUpdated();
     56    MapillaryData.dataUpdated();
    5657  }
    5758
    5859  @Override
    5960  public void mouseMoved(MouseEvent e) {
    60     lastPos = e;
     61    this.lastPos = e;
    6162    if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer))
    6263      return;
    6364    MapillaryAbstractImage closestTemp = getClosest(e.getPoint());
    64     data.setHighlightedImage(closestTemp);
    65     data.dataUpdated();
     65    this.data.setHighlightedImage(closestTemp);
     66    MapillaryData.dataUpdated();
    6667  }
    6768
    6869  @Override
    6970  public void paint(Graphics2D g, MapView mv, Bounds box) {
    70     if (lastClick != null) {
     71    if (this.lastClick != null) {
    7172      g.setColor(Color.WHITE);
    72       Point p0 = mv.getPoint(lastClick.getLatLon());
    73       Point p1 = lastPos.getPoint();
     73      Point p0 = mv.getPoint(this.lastClick.getLatLon());
     74      Point p1 = this.lastPos.getPoint();
    7475      g.drawLine(p0.x, p0.y, p1.x, p1.y);
    7576    }
    7677  }
    7778
    78   private void join(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     79  private static void join(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     80    MapillaryImportedImage firstImage = img1;
     81    MapillaryImportedImage secondImage = img2;
     82
    7983    if (img1.next() != null) {
    80       MapillaryImportedImage temp = img1;
    81       img1 = img2;
    82       img2 = temp;
     84      firstImage = img2;
     85      secondImage = img1;
    8386    }
    84     if (img1.getSequence() == null) {
     87    if (firstImage.getSequence() == null) {
    8588      MapillarySequence seq = new MapillarySequence();
    86       seq.add(img1);
    87       img1.setSequence(seq);
     89      seq.add(firstImage);
     90      firstImage.setSequence(seq);
    8891    }
    89     if (img2.getSequence() == null) {
     92    if (secondImage.getSequence() == null) {
    9093      MapillarySequence seq = new MapillarySequence();
    91       seq.add(img2);
     94      seq.add(secondImage);
    9295      img2.setSequence(seq);
    9396    }
    9497
    95     for (MapillaryAbstractImage img : img2.getSequence().getImages()) {
    96       img1.getSequence().add(img);
    97       img.setSequence(img1.getSequence());
     98    for (MapillaryAbstractImage img : secondImage.getSequence().getImages()) {
     99      firstImage.getSequence().add(img);
     100      img.setSequence(firstImage.getSequence());
    98101    }
    99102  }
    100103
    101   private void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     104  private static void unjoin(MapillaryImportedImage img1, MapillaryImportedImage img2) {
     105    MapillaryImportedImage firstImage = img1;
     106    MapillaryImportedImage secondImage = img2;
     107
    102108    if (img1.next() != img2) {
    103       MapillaryImportedImage temp = img1;
    104       img1 = img2;
    105       img2 = temp;
     109      firstImage = img2;
     110      secondImage = img1;
    106111    }
    107112
    108     ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(img1
     113    ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
    109114        .getSequence().getImages()
    110         .subList(0, img1.getSequence().getImages().indexOf(img2)));
    111     ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(img1
     115        .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
     116    ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
    112117        .getSequence()
    113118        .getImages()
    114         .subList(img1.getSequence().getImages().indexOf(img2),
    115             img1.getSequence().getImages().size()));
     119        .subList(firstImage.getSequence().getImages().indexOf(secondImage),
     120            firstImage.getSequence().getImages().size()));
    116121
    117122    MapillarySequence seq1 = new MapillarySequence();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31422 r31445  
    33import java.awt.Graphics2D;
    44import java.awt.Point;
     5import java.awt.event.InputEvent;
    56import java.awt.event.MouseEvent;
    67import java.util.ArrayList;
     
    1314import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1415import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     16import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
    1517import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    1618import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     
    4042   */
    4143  public SelectMode() {
    42     record = MapillaryRecord.getInstance();
     44    this.record = MapillaryRecord.getInstance();
    4345  }
    4446
    4547  @Override
    4648  public void mousePressed(MouseEvent e) {
    47     lastButton = e.getButton();
     49    this.lastButton = e.getButton();
    4850    if (e.getButton() != MouseEvent.BUTTON1)
    4951      return;
     
    5254        && closest != null && Main.map.mapMode == Main.map.mapModeSelect) {
    5355      this.lastClicked = this.closest;
    54       data.setSelectedImage(closest);
     56      this.data.setSelectedImage(closest);
    5557      return;
    5658    } else if (Main.map.mapView.getActiveLayer() != MapillaryLayer
     
    5860      return;
    5961    // Double click
    60     if (e.getClickCount() == 2 && data.getSelectedImage() != null
     62    if (e.getClickCount() == 2 && this.data.getSelectedImage() != null
    6163        && closest != null) {
    6264      for (MapillaryAbstractImage img : closest.getSequence().getImages()) {
    63         data.addMultiSelectedImage(img);
     65        this.data.addMultiSelectedImage(img);
    6466      }
    6567    }
     
    6769    this.lastClicked = this.closest;
    6870    this.closest = closest;
    69     if (data.getMultiSelectedImages().contains(closest))
     71    if (this.data.getMultiSelectedImages().contains(closest))
    7072      return;
    7173    // ctrl+click
    72     if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK)
     74    if (e.getModifiers() == (InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK)
    7375        && closest != null)
    74       data.addMultiSelectedImage(closest);
     76      this.data.addMultiSelectedImage(closest);
    7577    // shift + click
    76     else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)
     78    else if (e.getModifiers() == (InputEvent.BUTTON1_MASK | InputEvent.SHIFT_MASK)
    7779        && this.lastClicked instanceof MapillaryImage) {
    7880      if (this.closest != null && this.lastClicked != null
     
    8284            .indexOf(this.lastClicked);
    8385        if (i < j)
    84           data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()
     86          this.data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()
    8587              .getImages().subList(i, j + 1)));
    8688        else
    87           data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()
     89          this.data.addMultiSelectedImage(new ArrayList<>(this.closest.getSequence()
    8890              .getImages().subList(j, i + 1)));
    8991      }
    9092      // click
    9193    } else
    92       data.setSelectedImage(closest);
     94      this.data.setSelectedImage(closest);
    9395  }
    9496
     
    99101
    100102    if (!Main.pref.getBoolean("mapillary.developer"))
    101       for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
     103      for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    102104        if (img instanceof MapillaryImage)
    103105          return;
    104106      }
    105     if (data.getSelectedImage() != null) {
    106       if (lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) {
     107    if (this.data.getSelectedImage() != null) {
     108      if (this.lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) {
    107109        LatLon to = Main.map.mapView.getLatLon(e.getX(), e.getY());
    108         LatLon from = Main.map.mapView.getLatLon(start.getX(), start.getY());
    109         for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
     110        LatLon from = Main.map.mapView.getLatLon(this.start.getX(), this.start.getY());
     111        for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    110112
    111113          img.move(to.getX() - from.getX(), to.getY() - from.getY());
    112114        }
    113115        Main.map.repaint();
    114       } else if (lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) {
    115         this.closest.turn(Math.toDegrees(Math.atan2((e.getX() - start.x),
    116             -(e.getY() - start.y)))
    117             - closest.getTempCa());
    118         for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
    119           img.turn(Math.toDegrees(Math.atan2((e.getX() - start.x),
    120               -(e.getY() - start.y))) - closest.getTempCa());
     116      } else if (this.lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) {
     117        this.closest.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x),
     118            -(e.getY() - this.start.y)))
     119            - this.closest.getTempCa());
     120        for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
     121          img.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x),
     122              -(e.getY() - this.start.y))) - this.closest.getTempCa());
    121123        }
    122124        Main.map.repaint();
     
    127129  @Override
    128130  public void mouseReleased(MouseEvent e) {
    129     if (data.getSelectedImage() == null)
    130       return;
    131     if (data.getSelectedImage().getTempCa() != data.getSelectedImage().getCa()) {
    132       double from = data.getSelectedImage().getTempCa();
    133       double to = data.getSelectedImage().getCa();
    134       record.addCommand(new CommandTurnImage(data.getMultiSelectedImages(), to
     131    if (this.data.getSelectedImage() == null)
     132      return;
     133    if (this.data.getSelectedImage().getTempCa() != this.data.getSelectedImage().getCa()) {
     134      double from = this.data.getSelectedImage().getTempCa();
     135      double to = this.data.getSelectedImage().getCa();
     136      this.record.addCommand(new CommandTurnImage(this.data.getMultiSelectedImages(), to
    135137          - from));
    136     } else if (data.getSelectedImage().getTempLatLon() != data
     138    } else if (this.data.getSelectedImage().getTempLatLon() != this.data
    137139        .getSelectedImage().getLatLon()) {
    138       LatLon from = data.getSelectedImage().getTempLatLon();
    139       LatLon to = data.getSelectedImage().getLatLon();
    140       record.addCommand(new CommandMoveImage(data.getMultiSelectedImages(), to
     140      LatLon from = this.data.getSelectedImage().getTempLatLon();
     141      LatLon to = this.data.getSelectedImage().getLatLon();
     142      this.record.addCommand(new CommandMoveImage(this.data.getMultiSelectedImages(), to
    141143          .getX() - from.getX(), to.getY() - from.getY()));
    142144    }
    143     for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
     145    for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    144146      if (img != null)
    145147        img.stopMoving();
     
    158160    if (closestTemp != null
    159161        && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
    160         && !imageHighlighted) {
     162        && !this.imageHighlighted) {
    161163      Main.map.mapMode.putValue("active", Boolean.FALSE);
    162       imageHighlighted = true;
     164      this.imageHighlighted = true;
    163165
    164166    } else if (closestTemp == null
    165167        && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
    166         && imageHighlighted && nothingHighlighted) {
    167       nothingHighlighted = false;
     168        && this.imageHighlighted && this.nothingHighlighted) {
     169      this.nothingHighlighted = false;
    168170      Main.map.mapMode.putValue("active", Boolean.TRUE);
    169171
    170     } else if (imageHighlighted && !nothingHighlighted
     172    } else if (this.imageHighlighted && !this.nothingHighlighted
    171173        && Main.map.mapView.getEditLayer().data != null
    172174        && Main.map.mapView.getActiveLayer() instanceof OsmDataLayer) {
     
    176178        primivitive.setHighlighted(false);
    177179      }
    178       imageHighlighted = false;
    179       nothingHighlighted = true;
    180     }
    181 
    182     if (data.getHighlighted() != closestTemp && closestTemp != null) {
    183       data.setHighlightedImage(closestTemp);
     180      this.imageHighlighted = false;
     181      this.nothingHighlighted = true;
     182    }
     183
     184    if (this.data.getHighlighted() != closestTemp && closestTemp != null) {
     185      this.data.setHighlightedImage(closestTemp);
    184186      MapillaryMainDialog.getInstance().setImage(closestTemp);
    185187      MapillaryMainDialog.getInstance().updateImage(false);
    186     } else if (data.getHighlighted() != closestTemp && closestTemp == null) {
    187       data.setHighlightedImage(null);
    188       MapillaryMainDialog.getInstance().setImage(data.getSelectedImage());
     188    } else if (this.data.getHighlighted() != closestTemp && closestTemp == null) {
     189      this.data.setHighlightedImage(null);
     190      MapillaryMainDialog.getInstance().setImage(this.data.getSelectedImage());
    189191      MapillaryMainDialog.getInstance().updateImage();
    190192    }
    191     data.dataUpdated();
     193    MapillaryData.dataUpdated();
    192194  }
    193195
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31418 r31445  
    88import java.net.ServerSocket;
    99import java.net.Socket;
    10 import java.net.URL;
    1110import java.util.Scanner;
    1211
     
    5453      serverSocket.close();
    5554
     55      MapillaryUser.reset();
     56
    5657      Main.info("Successful login with Mapillary, the access token is: "
    5758          + accessToken);
    5859      // Saves the access token in preferences.
    5960      Main.pref.put("mapillary.access-token", accessToken);
    60       // Sets the logged username in preferences.
    61       Main.pref
    62           .put(
    63               "mapillary.username",
    64               OAuthUtils
    65                   .getWithHeader(
    66                       new URL(
    67                           "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))
    68                   .getString("username"));
    6961
    70       Main.info("The username is: " + Main.pref.get("mapillary.username"));
     62      Main.info("The username is: " + MapillaryUser.getUsername());
    7163
    7264    } catch (BindException e) {
     
    7769  }
    7870
    79   private void writeContent(PrintWriter out) {
     71  private static void writeContent(PrintWriter out) {
    8072    String response = "<html><head><title>Mapillary login</title></head><body>Login successful, return to JOSM.</body></html>";
    8173    out.println("HTTP/1.1 200 OK");
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthUtils.java

    r31418 r31445  
    11package org.openstreetmap.josm.plugins.mapillary.oauth;
    22
     3import java.io.BufferedOutputStream;
    34import java.io.BufferedReader;
     5import java.io.ByteArrayOutputStream;
     6import java.io.File;
     7import java.io.FileOutputStream;
    48import java.io.IOException;
    59import java.io.InputStreamReader;
     10import java.io.OutputStream;
     11import java.io.UnsupportedEncodingException;
    612import java.net.HttpURLConnection;
    713import java.net.URL;
    8 
     14import java.security.InvalidKeyException;
     15import java.security.NoSuchAlgorithmException;
     16import java.util.HashMap;
     17import java.util.UUID;
     18
     19import javax.imageio.ImageIO;
    920import javax.json.Json;
    1021import javax.json.JsonObject;
    1122
     23import org.apache.commons.imaging.ImageReadException;
     24import org.apache.commons.imaging.ImageWriteException;
     25import org.apache.commons.imaging.Imaging;
     26import org.apache.commons.imaging.common.ImageMetadata;
     27import org.apache.commons.imaging.common.RationalNumber;
     28import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
     29import org.apache.commons.imaging.formats.jpeg.exif.ExifRewriter;
     30import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
     31import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
     32import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
     33import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
     34import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
     35import org.apache.http.HttpEntity;
     36import org.apache.http.HttpResponse;
     37import org.apache.http.client.HttpClient;
     38import org.apache.http.client.methods.HttpPost;
     39import org.apache.http.entity.ContentType;
     40import org.apache.http.entity.mime.MultipartEntityBuilder;
     41import org.apache.http.entity.mime.content.FileBody;
     42import org.apache.http.entity.mime.content.StringBody;
     43import org.apache.http.impl.client.HttpClientBuilder;
    1244import org.openstreetmap.josm.Main;
     45import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     46import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
     47import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
    1348
    1449/**
     
    2055public class OAuthUtils {
    2156
    22   /** URL where to upload the images. */
    23   public static final String MAPILLARY_UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
     57  private static final String[] keys = { "key", "AWSAccessKeyId", "acl",
     58      "policy", "signature", "Content-Type" };
     59  private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
     60
     61  // Count to name temporal files.
     62  private static int c = 0;
    2463
    2564  /**
     
    2867   *
    2968   * @param url
     69   *          The {@link URL} where the request must be made.
    3070   * @return A JsonObject containing the result of the GET request.
    3171   * @throws IOException
     72   *           Errors relating to the connection.
    3273   */
    3374  public static JsonObject getWithHeader(URL url) throws IOException {
     
    4182    return Json.createReader(in).readObject();
    4283  }
     84
     85  /**
     86   * Uploads the given MapillaryImportedImage object.
     87   *
     88   * @param image
     89   *
     90   * @throws NoSuchAlgorithmException
     91   * @throws UnsupportedEncodingException
     92   * @throws InvalidKeyException
     93   *
     94   */
     95  public static void upload(MapillaryImportedImage image)
     96      throws InvalidKeyException, UnsupportedEncodingException,
     97      NoSuchAlgorithmException {
     98    try {
     99      upload(image, UUID.randomUUID());
     100    } catch (IOException e) {
     101      Main.error(e);
     102    }
     103  }
     104
     105  /**
     106   * @param image
     107   * @param uuid
     108   *          The UUID used to create the sequence.
     109   * @param username
     110   *          The username who is going to upload the picture.
     111   * @throws NoSuchAlgorithmException
     112   * @throws InvalidKeyException
     113   * @throws IOException
     114   */
     115  public static void upload(MapillaryImportedImage image, UUID uuid)
     116      throws NoSuchAlgorithmException, InvalidKeyException, IOException {
     117    String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/"
     118        + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_"
     119        + image.getCa() + "_" + image.datetimeOriginal + ".jpg";
     120
     121    String policy = null;
     122    String signature = null;
     123    policy = MapillaryUser.getSecrets().get("images_policy");
     124    signature = MapillaryUser.getSecrets().get("images_hash");
     125
     126    HashMap<String, String> hash = new HashMap<>();
     127    hash.put("key", key);
     128    hash.put("AWSAccessKeyId", "AKIAI2X3BJAT2W75HILA");
     129    hash.put("acl", "private");
     130    hash.put("policy", policy);
     131    hash.put("signature", signature);
     132    hash.put("Content-Type", "image/jpeg");
     133
     134    try {
     135      uploadFile(updateFile(image), hash);
     136    } catch (ImageReadException | ImageWriteException e) {
     137      Main.error(e);
     138    }
     139
     140  }
     141
     142  /**
     143   * @param file
     144   * @param hash
     145   * @throws IOException
     146   */
     147  public static void uploadFile(File file, HashMap<String, String> hash)
     148      throws IOException {
     149    HttpClientBuilder builder = HttpClientBuilder.create();
     150    HttpClient httpClient = builder.build();
     151    HttpPost httpPost = new HttpPost(UPLOAD_URL);
     152
     153    MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
     154    for (String key : keys) {
     155      entityBuilder.addPart(key, new StringBody(hash.get(key),
     156          ContentType.TEXT_PLAIN));
     157      System.out.println(key + " => " + hash.get(key));
     158    }
     159    entityBuilder.addPart("file", new FileBody(file));
     160
     161    HttpEntity entity = entityBuilder.build();
     162    httpPost.setEntity(entity);
     163
     164    System.out.println(httpPost);
     165    HttpResponse response = httpClient.execute(httpPost);
     166    System.out.println(response.toString());
     167  }
     168
     169  /**
     170   * Uploads the given {@link MapillarySequence}.
     171   *
     172   * @param sequence
     173   *          The sequence to upload. It must contain only
     174   *          {@link MapillaryImportedImage} objects.
     175   * @throws NoSuchAlgorithmException
     176   * @throws UnsupportedEncodingException
     177   * @throws InvalidKeyException
     178   */
     179  public static void uploadSequence(MapillarySequence sequence)
     180      throws InvalidKeyException, UnsupportedEncodingException,
     181      NoSuchAlgorithmException {
     182    UUID uuid = UUID.randomUUID();
     183
     184    for (MapillaryAbstractImage img : sequence.getImages()) {
     185      if (!(img instanceof MapillaryImportedImage))
     186        throw new IllegalArgumentException(
     187            "The sequence contains downloaded images.");
     188      try {
     189        upload((MapillaryImportedImage) img, uuid);
     190      } catch (IOException e) {
     191        Main.error(e);
     192      }
     193    }
     194  }
     195
     196  private static File updateFile(MapillaryImportedImage image)
     197      throws ImageReadException, IOException, ImageWriteException {
     198    TiffOutputSet outputSet = null;
     199    TiffOutputDirectory exifDirectory = null;
     200    // If the image is imported, loads the rest of the EXIF data.
     201    ImageMetadata metadata = Imaging.getMetadata(image.getFile());
     202    final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     203    if (null != jpegMetadata) {
     204      final TiffImageMetadata exif = jpegMetadata.getExif();
     205      if (null != exif) {
     206        outputSet = exif.getOutputSet();
     207      }
     208    }
     209    if (null == outputSet) {
     210      outputSet = new TiffOutputSet();
     211    }
     212    exifDirectory = outputSet.getOrCreateExifDirectory();
     213
     214    exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF);
     215    exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF,
     216        GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF_VALUE_TRUE_NORTH);
     217
     218    exifDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     219    exifDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION,
     220        RationalNumber.valueOf(image.getCa()));
     221
     222    exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     223    exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
     224        ((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss"));
     225
     226    outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat());
     227    File tempFile = new File(c + ".tmp");
     228    OutputStream os = new BufferedOutputStream(new FileOutputStream(tempFile));
     229
     230    // Transforms the image into a byte array.
     231    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
     232    ImageIO.write(image.getImage(), "jpg", outputStream);
     233    byte[] imageBytes = outputStream.toByteArray();
     234
     235    new ExifRewriter().updateExifMetadataLossless(imageBytes, os, outputSet);
     236
     237    return tempFile;
     238  }
    43239}
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImageTest.java

    r31411 r31445  
    88import java.util.TimeZone;
    99
    10 import org.junit.Before;
    1110import org.junit.Test;
    1211import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.plugins.mapillary.util.TestUtil;
    1412
    1513/**
    1614 *
    1715 */
    18 public class MapillaryAbstractImageTest {
    19 
    20   @Before
    21   public void init() {
    22     TestUtil.initPlugin();
    23   }
     16public class MapillaryAbstractImageTest extends AbstractTest{
    2417
    2518  /**
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillarySequenceDownloadThreadTest.java

    r31409 r31445  
    2828    @Before
    2929    public void setUp() {
    30         MapillaryData.TEST_MODE = true;
    3130        TestUtil.initPlugin();
    3231    }
Note: See TracChangeset for help on using the changeset viewer.