Changeset 31352 in osm


Ignore:
Timestamp:
2015-07-08T17:09:38+02:00 (9 years ago)
Author:
floscher
Message:

Some code formatting and code style improvements

The changes are quite minor, except for those in MapillaryImportAction:
There I modified the method degMinSecToDouble to throw exceptions on invalid input and to return negative values when south of equator or west of 0-meridian.

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

Legend:

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

    r31350 r31352  
    203203    SimpleDateFormat formatter = new SimpleDateFormat(format);
    204204    try {
    205       Date dateTime = (Date) formatter.parse(date);
     205      Date dateTime = formatter.parse(date);
    206206      return dateTime.getTime();
    207207    } catch (ParseException e) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31350 r31352  
    66/**
    77 * A MapillaryImage object represents each of the images stored in Mapillary.
    8  * 
     8 *
    99 * @author nokutu
    1010 * @see MapillarySequence
     
    3333  /**
    3434   * Main contructor of the class MapillaryImage
    35    * 
     35   *
    3636   * @param key
    3737   *          The unique identifier of the image.
     
    5151  /**
    5252   * Returns the unique identifier of the object.
    53    * 
     53   *
    5454   * @return A String containing the unique identifier of the object.
    5555   */
     
    6060  /**
    6161   * Adds a new sign to the set of signs.
    62    * 
     62   *
    6363   * @param sign
    6464   *          A String that identifies the type of sign.
     
    7070  /**
    7171   * Returns a List containing the signs assigned to this image.
    72    * 
     72   *
    7373   * @return A List object containing the signs assigned to this image.
    7474   */
     
    7979  /**
    8080   * Sets the username of the person who took the image.
    81    * 
     81   *
    8282   * @param user
    8383   *          A String containing the username of the person who took the image.
     
    9393  /**
    9494   * Sets the MapillarySequence object which contains the MapillaryImage.
    95    * 
     95   *
    9696   * @param sequence
    9797   *          The MapillarySequence that contains the MapillaryImage.
     
    103103  /**
    104104   * Returns the sequence which contains this image.
    105    * 
     105   *
    106106   * @return The MapillarySequence object that contains this MapillaryImage.
    107107   */
     
    110110  }
    111111
     112  @Override
    112113  public String toString() {
    113114    return "Image[key=" + this.key + ";lat=" + this.latLon.lat() + ";lon="
     
    118119   * If the MapillaryImage belongs to a MapillarySequence, returns the next
    119120   * MapillarySequence in it.
    120    * 
     121   *
    121122   * @return The following MapillaryImage, or null if there is none.
    122123   */
     
    132133   * If the MapillaryImage belongs to a MapillarySequence, returns the previous
    133134   * MapillarySequence in it.
    134    * 
     135   *
    135136   * @return The previous MapillaryImage, or null if there is none.
    136137   */
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31350 r31352  
    4545  public MapillaryImportAction() {
    4646    super(tr("Import pictures"), new ImageProvider("icon24.png"),
    47         tr("Import local pictures"), Shortcut.registerShortcut(
    48             "Import Mapillary", tr("Import pictures into Mapillary layer"),
    49             KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImport",
    50         false);
     47        tr("Import local pictures"), Shortcut.registerShortcut("Import Mapillary",
     48            tr("Import pictures into Mapillary layer"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
     49        false, "mapillaryImport", false);
    5150    this.setEnabled(false);
    5251  }
     
    5554  public void actionPerformed(ActionEvent e) {
    5655    chooser = new JFileChooser();
    57     chooser.setCurrentDirectory(new java.io.File(System
    58         .getProperty("user.home")));
     56    chooser.setCurrentDirectory(new java.io.File(System.getProperty("user.home")));
    5957    chooser.setDialogTitle(tr("Select pictures"));
    6058    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    6159    chooser.setAcceptAllFileFilterUsed(false);
    62     chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",
    63         "jpeg", "png"));
     60    chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", "jpeg", "png"));
    6461    chooser.setMultiSelectionEnabled(true);
    6562    if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    6663      for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    6764        File file = chooser.getSelectedFiles()[i];
    68         if (file.isDirectory()) {
    69 
    70         } else {
     65        if (!file.isDirectory()) {
    7166          MapillaryLayer.getInstance();
    72           if (file.getPath().substring(file.getPath().length() - 4)
    73               .equals(".jpg")
    74               || file.getPath().substring(file.getPath().length() - 5)
    75                   .equals(".jpeg")) {
     67          if (file.getPath().substring(file.getPath().length() - 4).equals(".jpg")
     68              || file.getPath().substring(file.getPath().length() - 5).equals(".jpeg")) {
    7669            try {
    7770              readJPG(file);
     
    8174              Main.error(ex);
    8275            }
    83           } else if (file.getPath().substring(file.getPath().length() - 4)
    84               .equals(".png")) {
     76          } else if (file.getPath().substring(file.getPath().length() - 4).equals(".png")) {
    8577            readPNG(file);
    8678          }
     
    10294    if (metadata instanceof JpegImageMetadata) {
    10395      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    104       final TiffField lat_ref = jpegMetadata
    105           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    106       final TiffField lat = jpegMetadata
    107           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    108       final TiffField lon_ref = jpegMetadata
    109           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    110       final TiffField lon = jpegMetadata
    111           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    112       final TiffField ca = jpegMetadata
    113           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     96      final TiffField lat_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
     97      final TiffField lat = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
     98      final TiffField lon_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
     99      final TiffField lon = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
     100      final TiffField ca = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    114101      final TiffField datetimeOriginal = jpegMetadata
    115102          .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     
    121108      double lonValue = 0;
    122109      double caValue = 0;
    123       if (lat != null && lat.getValue() instanceof RationalNumber[])
    124         latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref
    125             .getValue().toString());
    126       if (lon != null && lon.getValue() instanceof RationalNumber[])
    127         lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref
    128             .getValue().toString());
     110      if (lat.getValue() instanceof RationalNumber[])
     111        latValue = degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     112      if (lon.getValue() instanceof RationalNumber[])
     113        lonValue = degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    129114      if (ca != null && ca.getValue() instanceof RationalNumber)
    130115        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    131       if (lat_ref.getValue().toString().equals("S"))
    132         latValue = -latValue;
    133       if (lon_ref.getValue().toString().equals("W"))
    134         lonValue = -lonValue;
    135116      if (datetimeOriginal != null)
    136         MapillaryData.getInstance().add(
    137             new MapillaryImportedImage(latValue, lonValue, caValue, file,
    138                 datetimeOriginal.getStringValue()));
     117        MapillaryData.getInstance()
     118            .add(new MapillaryImportedImage(latValue, lonValue, caValue, file, datetimeOriginal.getStringValue()));
    139119      else
    140         MapillaryData.getInstance().add(
    141             new MapillaryImportedImage(latValue, lonValue, caValue, file));
     120        MapillaryData.getInstance().add(new MapillaryImportedImage(latValue, lonValue, caValue, file));
    142121    }
    143122  }
     
    156135    else
    157136      horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
    158     LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
    159         Main.map.mapView.getCenter());
    160     MapillaryData.getInstance().add(
    161         new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
     137    LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(Main.map.mapView.getCenter());
     138    MapillaryData.getInstance().add(new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
    162139    noTagsPics++;
    163140  }
     
    167144  }
    168145
    169   private double DegMinSecToDouble(RationalNumber[] degMinSec, String ref) {
    170     RationalNumber deg = degMinSec[0];
    171     RationalNumber min = degMinSec[1];
    172     RationalNumber sec = degMinSec[2];
    173     return deg.doubleValue() + min.doubleValue() / 60 + sec.doubleValue()
    174         / 3600;
     146  /**
     147   * Calculates the decimal degree-value from a degree value given in degrees-minutes-seconds-format
     148   *
     149   * @param degMinSec an array of length 3, the values in there are (in this order) degrees, minutes and seconds
     150   * @param ref the latitude or longitude reference determining if the given value is:
     151   *        <ul>
     152   *        <li>north ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH}) or
     153   *        south ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH}) of the equator</li>
     154   *        <li>east ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST}) or
     155   *        west ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST}) of the equator</li>
     156   *        </ul>
     157   * @return the decimal degree-value for the given input, negative when west of 0-meridian or south of equator,
     158   *         positive otherwise
     159   * @throws IllegalArgumentException if {@code degMinSec} doesn't have length 3 or if {@code ref} is not one of the
     160   *         values mentioned above
     161   */
     162  private static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) {
     163    if (degMinSec == null || degMinSec.length != 3) { throw new IllegalArgumentException(); }
     164    switch (ref) {
     165    case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH:
     166    case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH:
     167    case GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST:
     168    case GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST:
     169      break;
     170    default:
     171      throw new IllegalArgumentException();
     172    }
     173
     174    double result = degMinSec[0].doubleValue(); // degrees
     175    result += degMinSec[1].doubleValue() / 60; // minutes
     176    result += degMinSec[2].doubleValue() / 3600; // seconds
     177
     178    if (ref == GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH
     179        || ref == GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST) {
     180      result *= -1;
     181    }
     182
     183    return result;
    175184  }
    176185}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java

    r31350 r31352  
    1111/**
    1212 * Command created when an image's position is changed.
    13  * 
     13 *
    1414 * @author nokutu
    1515 *
     
    4646  }
    4747
     48  @Override
    4849  public String toString() {
    4950    return trn("Moved {0} image", "Moved {0} images", images.size(),
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java

    r31350 r31352  
    1111/**
    1212 * Command created when an image's direction is changed.
    13  * 
     13 *
    1414 * @author nokutu
    1515 *
     
    4343  }
    4444
     45  @Override
    4546  public String toString() {
    4647    return trn("Turned {0} image", "Turned {0} images", this.images.size(),
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryExportManager.java

    r31350 r31352  
    2626 * {@link ArrayBlockingQueue}. Then it is picked by the first one and written on
    2727 * the selected folder. Each image will be named by its key.
    28  * 
     28 *
    2929 * @author nokutu
    3030 *
     
    5555  /**
    5656   * Constructor used to rewrite imported images.
    57    * 
     57   *
    5858   * @param images
    5959   * @throws IOException
     
    106106        try {
    107107          queue.put(((MapillaryImportedImage) image).getImage());
    108           queueImages.put((MapillaryImportedImage) image);
     108          queueImages.put(image);
    109109        } catch (InterruptedException e) {
    110110          Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryImageInfoDownloaderThread.java

    r31350 r31352  
    3636  }
    3737
     38  @Override
    3839  public void run() {
    3940    try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31350 r31352  
    4646  }
    4747
     48  @Override
    4849  public void run() {
    4950    try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31350 r31352  
    1616 * the Mapillary API has a parameter called page which is needed when the amount
    1717 * of requested images is quite big.
    18  * 
     18 *
    1919 * @author nokutu
    20  * 
     20 *
    2121 * @see MapillaryDownloader
    2222 */
     
    2929  public boolean imagesAdded = false;
    3030
    31   public MapillarySquareDownloadManagerThread(String urlImages,
    32       String urlSequences, String urlSigns, MapillaryLayer layer) {
     31  public MapillarySquareDownloadManagerThread(String urlImages, String urlSequences, String urlSigns,
     32      MapillaryLayer layer) {
    3333    this.urlImages = urlImages;
    3434    this.urlSequences = urlSequences;
     
    3737  }
    3838
     39  @Override
    3940  public void run() {
    4041    Main.map.statusLine.setHelpText("Downloading images from Mapillary");
     
    5253    }
    5354    if (layer.data.getImages().size() > 0)
    54       Main.map.statusLine.setHelpText(tr("Total images: ")
    55           + layer.data.getImages().size());
     55      Main.map.statusLine.setHelpText(tr("Total images: ") + layer.data.getImages().size());
    5656    else
    5757      Main.map.statusLine.setHelpText(tr("No images found"));
     
    6262
    6363  private void downloadSequences() throws InterruptedException {
    64     ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,
    65         new ArrayBlockingQueue<Runnable>(5));
     64    ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
    6665    int page = 0;
    6766    while (!ex.isShutdown()) {
    68       ex.execute(new MapillarySequenceDownloadThread(ex, urlSequences
    69           + "&page=" + page + "&limit=10", layer, this));
     67      ex.execute(new MapillarySequenceDownloadThread(ex, urlSequences + "&page=" + page + "&limit=10", layer, this));
    7068      while (ex.getQueue().remainingCapacity() == 0)
    7169        Thread.sleep(500);
     
    7775
    7876  private void completeImages() throws InterruptedException {
    79     ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,
    80         new ArrayBlockingQueue<Runnable>(5));
     77    ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
    8178    int page = 0;
    8279    while (!ex.isShutdown()) {
    83       ex.execute(new MapillaryImageInfoDownloaderThread(ex, urlImages
    84           + "&page=" + page + "&limit=20", layer));
     80      ex.execute(new MapillaryImageInfoDownloaderThread(ex, urlImages + "&page=" + page + "&limit=20", layer));
    8581      while (ex.getQueue().remainingCapacity() == 0)
    8682        Thread.sleep(100);
     
    9187
    9288  private void downloadSigns() throws InterruptedException {
    93     ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS,
    94         new ArrayBlockingQueue<Runnable>(5));
     89    ThreadPoolExecutor ex = new ThreadPoolExecutor(3, 5, 25, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5));
    9590    int page = 0;
    9691    while (!ex.isShutdown()) {
    97       ex.execute(new MapillarySignDownloaderThread(ex, urlSigns + "&page="
    98           + page + "&limit=20", layer));
     92      ex.execute(new MapillarySignDownloaderThread(ex, urlSigns + "&page=" + page + "&limit=20", layer));
    9993      while (ex.getQueue().remainingCapacity() == 0)
    10094        Thread.sleep(100);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31350 r31352  
    3838   * Sets the text of the label.
    3939   */
     40  @Override
    4041  public void setText(String text) {
    4142    super
     
    4647  /**
    4748   * Sets a new URL, just pass the key of the image or null if there is none.
    48    * 
     49   *
    4950   * @param key
    5051   */
     
    7172   * Processes mouse events and responds to clicks.
    7273   */
     74  @Override
    7375  protected void processMouseEvent(MouseEvent evt) {
    7476    super.processMouseEvent(evt);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31350 r31352  
    2626 * This object is a responsible JComponent which lets you zoom and drag. It is
    2727 * included in a {@link MapillaryMainDialog} object.
    28  * 
     28 *
    2929 * @author Jorge
    3030 * @see MapillaryImageDisplay
     
    341341  /**
    342342   * Sets a new picture to be displayed.
    343    * 
     343   *
    344344   * @param image
    345345   */
     
    357357  /**
    358358   * Returns the picture that is being displayerd
    359    * 
     359   *
    360360   * @return
    361361   */
     
    367367   * Paints the visible part of the picture.
    368368   */
     369  @Override
    369370  public void paintComponent(Graphics g) {
    370371    Image image;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryOAuthUI.java

    r31350 r31352  
    1414/**
    1515 * JPanel used to get the OAuth tokens from Mapillary.
    16  * 
     16 *
    1717 * @author nokutu
    1818 *
     
    3737    System.out.print(">>");
    3838    Verifier verifier = new Verifier(in.nextLine());
     39    in.close();
    3940    System.out.println();
    4041  }
Note: See TracChangeset for help on using the changeset viewer.