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

Extracted import methods and added a few more links when right clicking on the hyperlink label of the main dialog. Now you can copy the tag and open the edit website.

Location:
applications/editors/josm/plugins/mapillary
Files:
18 edited

Legend:

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

    r31501 r31512  
    2929  /** Listeners of the class. */
    3030  private CopyOnWriteArrayList<MapillaryDataListener> listeners = new CopyOnWriteArrayList<>();
    31 
    3231  /** The bounds of the areas for which the pictures have been downloaded. */
    3332  public CopyOnWriteArrayList<Bounds> bounds;
     
    9493   *
    9594   * @param images
    96    *          The set of {@link MapillaryAbstractImage} objects that are going
     95   *          A {@link List} of {@link MapillaryAbstractImage} objects that are going
    9796   *          to be removed.
    9897   */
     
    348347
    349348  /**
    350    * Adds a MapillaryImage object to the list of selected images, (when ctrl +
     349   * Adds a {@link MapillaryImage} object to the list of selected images, (when ctrl +
    351350   * click)
    352351   *
    353352   * @param image
    354    *          The MapillaryImage object to be added.
     353   *          The {@link MapillaryImage} object to be added.
    355354   */
    356355  public void addMultiSelectedImage(MapillaryAbstractImage image) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryDataListener.java

    r31401 r31512  
    2525  public void selectedImageChanged(MapillaryAbstractImage oldImage,
    2626      MapillaryAbstractImage newImage);
    27 
    2827}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31501 r31512  
    1212 */
    1313public class MapillaryImage extends MapillaryAbstractImage {
    14   /** Unique identifier of the object */
     14  /** Unique identifier of the object. */
    1515  private final String key;
    16   /** The user that made the image */
     16  /** The user that made the image. */
    1717  private String user;
    18   /** Set of traffic signs in the image */
     18  /** Set of traffic signs in the image. */
    1919  private List<String> signs;
     20  /** Where the picture was taken. */
    2021  private String location;
    2122
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31501 r31512  
    124124        this.mode.zoomChanged();
    125125    }
    126     if (MapillaryPlugin.EXPORT_MENU != null) { // Does not execute when in
    127                                                // headless mode
     126    // Does not execute when in headless mode
     127    if (MapillaryPlugin.EXPORT_MENU != null) {
    128128      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true);
    129129      if (!MapillaryMainDialog.getInstance().isShowing())
     
    362362   * @param g
    363363   * @param p
     364   *          The {@link Point} where the image must be set.
    364365   * @param size
     366   *          The width in pixels of the highlight.
    365367   */
    366368  private void drawPointHighlight(Graphics2D g, Point p, int size) {
     
    385387   * @param g
    386388   * @param image
     389   *          The {@link MapillaryAbstractImage} which is being drown.
    387390   * @param icon
     391   *          The {@link ImageIcon} that represents the image.
    388392   * @param p
     393   *          The P¡{@link Point} when the image lies.
    389394   */
    390395  private void draw(Graphics2D g, MapillaryAbstractImage image, ImageIcon icon,
     
    437442
    438443  /**
    439    * Returns the 2 closest images belonging to a different sequence.
     444   * Returns the 2 closest images belonging to a different sequence and
     445   * different from the currently selected one.
    440446   *
    441447   * @return An array of length 2 containing the two closest images belonging to
     
    500506    if (oldLayer == null && newLayer != null) {
    501507      newLayer.data.addDataSetListener(this);
    502 
    503508    } else if (oldLayer != null && newLayer == null) {
    504509      oldLayer.data.removeDataSetListener(this);
     
    513518  }
    514519
     520  /**
     521   * Threads that runs a delayed Mapillary download.
     522   *
     523   * @author nokutu
     524   *
     525   */
    515526  private class delayedDownload extends Thread {
    516527
     
    569580  @Override
    570581  public void layerAdded(Layer newLayer) {
    571     // Nothing
    572582  }
    573583
    574584  @Override
    575585  public void layerRemoved(Layer oldLayer) {
    576     // Nothing
    577586  }
    578587
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31501 r31512  
    1212 */
    1313public class MapillarySequence {
     14  /** The images in the sequence. */
    1415  private final List<MapillaryAbstractImage> images;
     16  /** Unique identifier. Used only for {@link MapillaryImage} sequences. */
    1517  private String key;
     18  /** Epoch time when the sequence was created */
    1619  private long created_at;
    1720
     
    4245   * object.
    4346   *
    44    * @return A List object containing all the {@link MapillaryAbstractImage}
    45    *         objects that are part of the sequence.
     47   * @return A {@link List} object containing all the
     48   *         {@link MapillaryAbstractImage} objects that are part of the
     49   *         sequence.
    4650   */
    4751  public List<MapillaryAbstractImage> getImages() {
     
    7276   * Returns the unique identifier of the sequence.
    7377   *
    74    * @return A String containing the unique identifier of the sequence. null
    75    *         means that the sequence has been created locally for imported
     78   * @return A {@code String} containing the unique identifier of the sequence.
     79   *         null means that the sequence has been created locally for imported
    7680   *         images.
    7781   */
     
    123127
    124128  /**
    125    * Returns the previous {@link MapillaryAbstractImage} in the sequence of a given
    126    * {@link MapillaryAbstractImage} object.
     129   * Returns the previous {@link MapillaryAbstractImage} in the sequence of a
     130   * given {@link MapillaryAbstractImage} object.
    127131   *
    128132   * @param image
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31495 r31512  
    1414
    1515import org.apache.commons.imaging.ImageReadException;
    16 import org.apache.commons.imaging.Imaging;
    17 import org.apache.commons.imaging.common.ImageMetadata;
    18 import org.apache.commons.imaging.common.RationalNumber;
    19 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
    20 import org.apache.commons.imaging.formats.tiff.TiffField;
    21 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
    22 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    2316import org.openstreetmap.josm.Main;
    2417import org.openstreetmap.josm.actions.JosmAction;
    25 import org.openstreetmap.josm.data.coor.LatLon;
    2618import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    27 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2819import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    2920import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     
    4435
    4536  private JFileChooser chooser;
    46 
    47   /**
    48    * Amount of pictures without the proper EXIF tags.
    49    */
    50   private int noTagsPics = 0;
    5137
    5238  /**
     
    8470            continue;
    8571          for (int j = 0; j < file.listFiles().length; j++) {
    86             int k = file.listFiles()[j].getName().lastIndexOf('.');
    87             String extension = null;
    88             if (k > 0) {
    89               extension = file.listFiles()[j].getName().substring(k + 1);
    90             }
     72            String extension = MapillaryUtils.getExtension(file.listFiles()[j]);
    9173            try {
    9274              if (extension.equals("jpg") || extension.equals("jpeg"))
    93                 images.add(readJPG(file.listFiles()[j]));
    94 
     75                images.add(MapillaryUtils.readJPG(file.listFiles()[j]));
    9576              else if (extension.equals("png"))
    96                 images.add(readPNG(file.listFiles()[j]));
     77                images.add(MapillaryUtils.readPNG(file.listFiles()[j]));
    9778            } catch (ImageReadException | IOException | NullPointerException e1) {
    9879              Main.error(e1);
     
    10081          }
    10182        } else {
    102           if (file.getPath().substring(file.getPath().length() - 4)
    103               .equals(".jpg")
    104               || file.getPath().substring(file.getPath().length() - 5)
    105                   .equals(".jpeg")) {
     83          String extension = MapillaryUtils.getExtension(file);
     84          if (extension.equals("jpg") || extension.equals("jpeg")) {
    10685            try {
    107               images.add(readJPG(file));
     86              images.add(MapillaryUtils.readJPG(file));
    10887            } catch (ImageReadException ex) {
    10988              Main.error(ex);
     
    11392          } else if (file.getPath().substring(file.getPath().length() - 4)
    11493              .equals(".png")) {
    115             images.add(readPNG(file));
     94            images.add(MapillaryUtils.readPNG(file));
    11695          }
    11796        }
     
    121100    }
    122101  }
    123 
    124   /**
    125    * Reads a JPG pictures that contains the needed GPS information (position and
    126    * direction) and creates a new icon in that position.
    127    *
    128    * @param file
    129    *          The file where the picture is located.
    130    * @return The imported image.
    131    * @throws ImageReadException
    132    *           If the file isn't an image.
    133    * @throws IOException
    134    *           If the file doesn't have the valid metadata.
    135    */
    136   public MapillaryImportedImage readJPG(File file) throws IOException,
    137       ImageReadException {
    138     final ImageMetadata metadata = Imaging.getMetadata(file);
    139     if (metadata instanceof JpegImageMetadata) {
    140       final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    141       final TiffField lat_ref = jpegMetadata
    142           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    143       final TiffField lat = jpegMetadata
    144           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    145       final TiffField lon_ref = jpegMetadata
    146           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    147       final TiffField lon = jpegMetadata
    148           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    149       final TiffField ca = jpegMetadata
    150           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    151       final TiffField datetimeOriginal = jpegMetadata
    152           .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    153       if (lat_ref == null || lat == null || lon == null || lon_ref == null) {
    154         return readNoTags(file);
    155       }
    156       double latValue = 0;
    157       double lonValue = 0;
    158       double caValue = 0;
    159       if (lat.getValue() instanceof RationalNumber[])
    160         latValue = MapillaryUtils.degMinSecToDouble(
    161             (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
    162       if (lon.getValue() instanceof RationalNumber[])
    163         lonValue = MapillaryUtils.degMinSecToDouble(
    164             (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    165       if (ca != null && ca.getValue() instanceof RationalNumber)
    166         caValue = ((RationalNumber) ca.getValue()).doubleValue();
    167       if (datetimeOriginal != null)
    168         return new MapillaryImportedImage(latValue, lonValue, caValue, file,
    169             datetimeOriginal.getStringValue());
    170       else
    171         return new MapillaryImportedImage(latValue, lonValue, caValue, file);
    172     }
    173     throw new IllegalStateException("Invalid format.");
    174   }
    175 
    176   /**
    177    * Reads a image file that doesn't contain the needed GPS information. And
    178    * creates a new icon in the middle of the map.
    179    *
    180    * @param file
    181    *          The file where the image is located.
    182    * @return The imported image.
    183    */
    184   public MapillaryImportedImage readNoTags(File file) {
    185     return readNoTags(
    186         file,
    187         Main.map.mapView.getProjection().eastNorth2latlon(
    188             Main.map.mapView.getCenter()));
    189   }
    190 
    191   /**
    192    * Reads a image file that doesn't contain the needed GPS information. And
    193    * creates a new icon in the middle of the map.
    194    *
    195    * @param file
    196    *          The file where the image is located.
    197    * @param pos
    198    *          A {@link LatLon} object indicating the position in the map where
    199    *          the image must be set.
    200    * @return The imported image.
    201    */
    202   public MapillaryImportedImage readNoTags(File file, LatLon pos) {
    203     double HORIZONTAL_DISTANCE = 0.0001;
    204     double horDev;
    205     if (this.noTagsPics % 2 == 0)
    206       horDev = HORIZONTAL_DISTANCE * this.noTagsPics / 2;
    207     else
    208       horDev = -HORIZONTAL_DISTANCE * ((this.noTagsPics + 1) / 2);
    209     this.noTagsPics++;
    210     return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
    211   }
    212 
    213   /**
    214    * Reads an image in PNG format.
    215    *
    216    * @param file
    217    *          The file where the image is located.
    218    * @return The imported image.
    219    */
    220   public MapillaryImportedImage readPNG(File file) {
    221     return readNoTags(file);
    222   }
    223102}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31495 r31512  
    1616
    1717import org.apache.commons.imaging.ImageReadException;
    18 import org.apache.commons.imaging.Imaging;
    19 import org.apache.commons.imaging.common.ImageMetadata;
    20 import org.apache.commons.imaging.common.RationalNumber;
    21 import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
    22 import org.apache.commons.imaging.formats.tiff.TiffField;
    23 import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
    24 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    2518import org.openstreetmap.josm.Main;
    2619import org.openstreetmap.josm.actions.JosmAction;
    2720import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    28 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2921import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    3022import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
     
    8678        if (file.isDirectory()) {
    8779          for (int j = 0; j < file.listFiles().length; j++) {
    88             int k = file.listFiles()[j].getName().lastIndexOf('.');
    89             String extension = null;
    90             if (k > 0) {
    91               extension = file.listFiles()[j].getName().substring(k + 1);
    92             }
     80            String extension = MapillaryUtils.getExtension(file.listFiles()[j]);
    9381            try {
    9482              if (extension.equals("jpg") || extension.equals("jpeg"))
    95                 readJPG(file.listFiles()[j]);
     83                MapillaryUtils.readJPG(file.listFiles()[j], true);
    9684            } catch (ImageReadException | NullPointerException | IOException e) {
    9785              Main.error(e);
     
    9987          }
    10088        } else {
    101           if (file.getPath().substring(file.getPath().length() - 4)
    102               .equals(".jpg")
    103               || file.getPath().substring(file.getPath().length() - 5)
    104                   .equals(".jpeg")) {
     89          String extension = MapillaryUtils.getExtension(file);
     90          if (extension.equals("jpg") || extension.equals("jpeg")) {
    10591            try {
    106               readJPG(file);
     92              this.images.add(MapillaryUtils.readJPG(file, true));
    10793            } catch (ImageReadException ex) {
    10894              Main.error(ex);
    10995            } catch (IOException ex) {
    11096              Main.error(ex);
     97            } catch (IllegalArgumentException ex) {
     98              // Ignored image.
    11199            }
    112100          }
     
    117105    }
    118106    MapillaryUtils.showAllPictures();
    119   }
    120 
    121   /**
    122    * Reads a JPG pictures that contains the needed GPS information (position and
    123    * direction) and creates a new icon in that position.
    124    *
    125    * @param file
    126    *          The file where the image is located.
    127    * @throws ImageReadException
    128    *           If the file doesn't contain an image.
    129    * @throws IOException
    130    *           If the file doesn't contain valid metadata.
    131    */
    132   public void readJPG(File file) throws ImageReadException, IOException {
    133     final ImageMetadata metadata = Imaging.getMetadata(file);
    134     if (metadata instanceof JpegImageMetadata) {
    135       final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    136       final TiffField lat_ref = jpegMetadata
    137           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    138       final TiffField lat = jpegMetadata
    139           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    140       final TiffField lon_ref = jpegMetadata
    141           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    142       final TiffField lon = jpegMetadata
    143           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    144       final TiffField ca = jpegMetadata
    145           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    146       final TiffField datetimeOriginal = jpegMetadata
    147           .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    148       if (lat_ref == null || lat == null || lon == null || lon_ref == null
    149           || datetimeOriginal == null)
    150         return;
    151 
    152       double latValue = 0;
    153       double lonValue = 0;
    154       double caValue = 0;
    155       if (lat.getValue() instanceof RationalNumber[])
    156         latValue = MapillaryUtils.degMinSecToDouble(
    157             (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
    158       if (lon.getValue() instanceof RationalNumber[])
    159         lonValue = MapillaryUtils.degMinSecToDouble(
    160             (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    161       if (ca != null && ca.getValue() instanceof RationalNumber)
    162         caValue = ((RationalNumber) ca.getValue()).doubleValue();
    163 
    164       MapillaryImportedImage image = new MapillaryImportedImage(latValue,
    165           lonValue, caValue, file, datetimeOriginal.getStringValue());
    166       this.images.add(image);
    167     }
    168107  }
    169108
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryJoinAction.java

    r31425 r31512  
    1414
    1515/**
    16  * Changes the mode of the Layer, from Select mode to Join mode and viceversa.
     16 * Changes the mode of the Layer, from Select mode to Join mode and vice versa.
    1717 *
    1818 * @author nokutu
     
    3636  @Override
    3737  public void actionPerformed(ActionEvent arg0) {
    38     if (MapillaryLayer.getInstance().mode instanceof SelectMode) {
     38    if (MapillaryLayer.getInstance().mode instanceof SelectMode)
    3939      MapillaryLayer.getInstance().setMode(new JoinMode());
    40     } else {
     40    else
    4141      MapillaryLayer.getInstance().setMode(new SelectMode());
    42     }
    4342  }
    4443}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31491 r31512  
    2121
    2222/**
     23 * Action called when an upload to the Mapillary servers is going to be
     24 * performed. It lets you select a couple of options.
     25 *
    2326 * @author nokutu
    2427 *
     
    6063  @Override
    6164  public void imagesAdded() {
    62     // Nothing
    6365  }
    6466
     
    7173      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.UPLOAD_MENU, false);
    7274  }
    73 
    7475}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31501 r31512  
    9595  }
    9696
     97  /**
     98   * Downloads the sequence positions, directions and keys.
     99   *
     100   * @throws InterruptedException
     101   *           if the thread is interrupted while running this method.
     102   */
    97103  private void downloadSequences() throws InterruptedException {
    98104    int page = 0;
     
    109115  }
    110116
     117  /**
     118   * Downloads the image's author's username and the image's location.
     119   *
     120   * @throws InterruptedException
     121   *           if the thread is interrupted while running this method.
     122   */
    111123  private void completeImages() throws InterruptedException {
    112124    int page = 0;
     
    122134  }
    123135
     136  /**
     137   * Downloads the traffic signs in the images.
     138   *
     139   * @throws InterruptedException
     140   *           if the thread is interrupted while running this method.
     141   */
    124142  private void downloadSigns() throws InterruptedException {
    125143    int page = 0;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31501 r31512  
    3434  private String text;
    3535  private URL url;
     36  private String key;
    3637
    3738  /**
     
    6364   */
    6465  public void setURL(String key) {
     66    this.key = key;
    6567    if (key == null) {
    6668      this.url = null;
     
    110112    private static final long serialVersionUID = 1384054752970921552L;
    111113
    112     JMenuItem copy;
     114    private JMenuItem copy;
     115    private JMenuItem copyTag;
     116    private JMenuItem edit;
    113117
    114118    public LinkPopUp() {
    115       this.copy = new JMenuItem("Copy key");
     119      this.copy = new JMenuItem(tr("Copy key"));
    116120      this.copy.addActionListener(new copyAction());
    117121      add(this.copy);
     122
     123      this.copyTag = new JMenuItem(tr("Copy key tag"));
     124      this.copyTag.addActionListener(new copyTagAction());
     125      add(this.copyTag);
     126
     127      this.edit = new JMenuItem(tr("Edit on webpage"));
     128      this.edit.addActionListener(new editAction());
     129      add(this.edit);
    118130    }
    119131
     
    128140        clpbrd.setContents(stringSelection, null);
    129141      }
    130 
     142    }
     143
     144    private class copyTagAction implements ActionListener {
     145
     146      @Override
     147      public void actionPerformed(ActionEvent arg0) {
     148        StringSelection stringSelection = new StringSelection(
     149            "mapillary="
     150                + ((MapillaryImage) MapillaryMainDialog.getInstance()
     151                    .getImage()).getKey());
     152        Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
     153        clpbrd.setContents(stringSelection, null);
     154      }
     155    }
     156
     157    private class editAction implements ActionListener {
     158
     159      @Override
     160      public void actionPerformed(ActionEvent arg0) {
     161        try {
     162          MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/"
     163              + HyperlinkLabel.this.key));
     164        } catch (MalformedURLException e) {
     165          Main.error(e);
     166        }
     167      }
    131168    }
    132169  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31511 r31512  
    5353      return;
    5454    MapillaryAbstractImage closest = getClosest(e.getPoint());
    55     if (Main.map.mapView.getActiveLayer() instanceof OsmDataLayer
     55    if (!(Main.map.mapView.getActiveLayer() instanceof MapillaryLayer)
    5656        && closest != null && Main.map.mapMode == Main.map.mapModeSelect) {
    5757      this.lastClicked = this.closest;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java

    r31476 r31512  
    88
    99/**
     10 * Represents the current logged in user and stores its data.
     11 *
    1012 * @author nokutu
    1113 *
     
    3840        isTokenValid = false;
    3941      }
    40 
    4142    return username;
    4243  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31511 r31512  
    1515
    1616/**
    17  * Listens to the OAuth port in order to get the access token.
     17 * Listens to the OAuth port (8763) in order to get the access token and sends
     18 * back a simple reply.
    1819 *
    1920 * @author nokutu
     
    6667        Main.info("The username is: " + MapillaryUser.getUsername());
    6768      }
    68 
    6969    } catch (BindException e) {
    7070      return;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31496 r31512  
    265265        ((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss"));
    266266
     267    // Removes the ImageDescription tag, that causes problems in the upload.
    267268    rootDirectory.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION);
    268269
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31511 r31512  
    44
    55import java.awt.Desktop;
     6import java.io.File;
    67import java.io.IOException;
    78import java.net.URISyntaxException;
     
    1415import javax.swing.SwingUtilities;
    1516
     17import org.apache.commons.imaging.ImageReadException;
     18import org.apache.commons.imaging.Imaging;
     19import org.apache.commons.imaging.common.ImageMetadata;
    1620import org.apache.commons.imaging.common.RationalNumber;
     21import org.apache.commons.imaging.formats.jpeg.JpegImageMetadata;
     22import org.apache.commons.imaging.formats.tiff.TiffField;
     23import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
    1724import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    1825import org.openstreetmap.josm.Main;
     
    2128import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    2229import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     30import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2331import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    2432import org.openstreetmap.josm.plugins.mapillary.MapillarySequence;
     
    3341
    3442  private static double MIN_ZOOM_SQUARE_SIDE = 0.002;
     43
     44  private static int noTagsPics = 0;
    3545
    3646  /**
     
    281291    return formatter.format(cal.getTime());
    282292  }
     293
     294  /**
     295   * Reads a JPG pictures that contains the needed GPS information (position and
     296   * direction) and creates a new icon in that position.
     297   *
     298   * @param file
     299   *          The file where the picture is located.
     300   * @return The imported image.
     301   * @throws ImageReadException
     302   *           If the file isn't an image.
     303   * @throws IOException
     304   *           If the file doesn't have the valid metadata.
     305   */
     306  public static MapillaryImportedImage readJPG(File file) throws IOException,
     307      ImageReadException {
     308    return readJPG(file, false);
     309  }
     310
     311  /**
     312   * Reads a JPG pictures that contains the needed GPS information (position and
     313   * direction) and creates a new icon in that position.
     314   *
     315   * @param file
     316   *          The {@link File} where the picture is located.
     317   * @param exceptionNoTags
     318   *          {@code true} if an exception must be thrown if the image doesn't
     319   *          have all the needed EXIF tags; {@code false} returns an image in
     320   *          the center of the screen.
     321   * @return The imported image.
     322   * @throws ImageReadException
     323   *           If the {@link File} isn't an image.
     324   * @throws IOException
     325   *           If the {@link File} doesn't have the valid metadata.
     326   * @throws IllegalArgumentException
     327   *           if exceptionNoTags is set to {@code true} and the image doesn't
     328   *           have the needed EXIF tags.
     329   */
     330  public static MapillaryImportedImage readJPG(File file,
     331      boolean exceptionNoTags) throws IOException, ImageReadException {
     332    final ImageMetadata metadata = Imaging.getMetadata(file);
     333    if (metadata instanceof JpegImageMetadata) {
     334      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     335      final TiffField lat_ref = jpegMetadata
     336          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
     337      final TiffField lat = jpegMetadata
     338          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
     339      final TiffField lon_ref = jpegMetadata
     340          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
     341      final TiffField lon = jpegMetadata
     342          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
     343      final TiffField ca = jpegMetadata
     344          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     345      final TiffField datetimeOriginal = jpegMetadata
     346          .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     347      if (lat_ref == null || lat == null || lon == null || lon_ref == null) {
     348        if (exceptionNoTags)
     349          throw new IllegalArgumentException(
     350              "The image doesn't have the needed EXIF tags.");
     351        else
     352          return readNoTags(file);
     353      }
     354      double latValue = 0;
     355      double lonValue = 0;
     356      double caValue = 0;
     357      if (lat.getValue() instanceof RationalNumber[])
     358        latValue = MapillaryUtils.degMinSecToDouble(
     359            (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     360      if (lon.getValue() instanceof RationalNumber[])
     361        lonValue = MapillaryUtils.degMinSecToDouble(
     362            (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
     363      if (ca != null && ca.getValue() instanceof RationalNumber)
     364        caValue = ((RationalNumber) ca.getValue()).doubleValue();
     365      if (datetimeOriginal != null)
     366        return new MapillaryImportedImage(latValue, lonValue, caValue, file,
     367            datetimeOriginal.getStringValue());
     368      else
     369        return new MapillaryImportedImage(latValue, lonValue, caValue, file);
     370    }
     371    throw new IllegalStateException("Invalid format.");
     372  }
     373
     374  /**
     375   * Reads a image file that doesn't contain the needed GPS information. And
     376   * creates a new icon in the middle of the map.
     377   *
     378   * @param file
     379   *          The file where the image is located.
     380   * @param pos
     381   *          A {@link LatLon} object indicating the position in the map where
     382   *          the image must be set.
     383   * @return The imported image.
     384   */
     385  public static MapillaryImportedImage readNoTags(File file, LatLon pos) {
     386    double HORIZONTAL_DISTANCE = 0.0001;
     387    double horDev;
     388    if (noTagsPics % 2 == 0)
     389      horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;
     390    else
     391      horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
     392    noTagsPics++;
     393    return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
     394  }
     395
     396  /**
     397   * Reads an image in PNG format.
     398   *
     399   * @param file
     400   *          The file where the image is located.
     401   * @return The imported image.
     402   */
     403  public static MapillaryImportedImage readPNG(File file) {
     404    return readNoTags(file);
     405  }
     406
     407  /**
     408   * Reads a image file that doesn't contain the needed GPS information. And
     409   * creates a new icon in the middle of the map.
     410   *
     411   * @param file
     412   *          The file where the image is located.
     413   * @return The imported image.
     414   */
     415  public static MapillaryImportedImage readNoTags(File file) {
     416    return readNoTags(
     417        file,
     418        Main.map.mapView.getProjection().eastNorth2latlon(
     419            Main.map.mapView.getCenter()));
     420  }
     421
     422  /**
     423   * Returns the extension of a {@link File} object.
     424   *
     425   * @param file
     426   *          The {@link File} object whose extension is going to be returned.
     427   * @return A {@code String} object containing the extension.
     428   */
     429  public static String getExtension(File file) {
     430    if (file.isDirectory())
     431      throw new IllegalArgumentException("The file is a directory");
     432    int k = file.getName().lastIndexOf('.');
     433    if (k > 0) {
     434      return file.getName().substring(k + 1).toLowerCase();
     435    }
     436    throw new IllegalArgumentException("Error parsing the extension");
     437  }
    283438}
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java

    r31460 r31512  
    1111
    1212import org.openstreetmap.josm.data.coor.LatLon;
    13 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
     13import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    1414
    1515/**
     
    2727  public void importNoTagsTest() {
    2828    File image = new File("images/icon16.png");
    29     MapillaryImportedImage img = new MapillaryImportAction().readNoTags(image,
     29    MapillaryImportedImage img = MapillaryUtils.readNoTags(image,
    3030        new LatLon(0, 0));
    3131    assertEquals(0, img.getCa(), 0.01);
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/UploadTest.java

    r31460 r31512  
    2020import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
    2121import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    22 import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
    2322import org.openstreetmap.josm.plugins.mapillary.oauth.UploadUtils;
    2423import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
     
    3837  public void updateFileTest() {
    3938    File image = new File("images/icon16.png");
    40     MapillaryImportedImage img = new MapillaryImportAction().readNoTags(image,
     39    MapillaryImportedImage img = MapillaryUtils.readNoTags(image,
    4140        new LatLon(0, 0));
    4241    File updatedFile = null;
Note: See TracChangeset for help on using the changeset viewer.