Changeset 31460 in osm for applications/editors


Ignore:
Timestamp:
2015-08-06T16:55:15+02:00 (9 years ago)
Author:
nokutu
Message:

Created several new tests and improved comments.

Location:
applications/editors/josm/plugins/mapillary
Files:
4 added
14 edited
1 moved

Legend:

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

    r31445 r31460  
    2121
    2222  /**
    23    * Lock that locks next() and previous() methods. Used when downloading images
    24    * to prevent concurrency problems.
     23   * Lock that locks {@link MapillaryAbstractImage#next()} and
     24   * {@link MapillaryAbstractImage#previous()} methods. Used when downloading
     25   * images to prevent concurrency problems.
    2526   */
    2627  public static Lock LOCK = new ReentrantLock();
     
    213214   * Returns the date the picture was taken in the given format.
    214215   *
    215    * @param format Format of the date. See {@link SimpleDateFormat}.
     216   * @param format
     217   *          Format of the date. See {@link SimpleDateFormat}.
    216218   * @return A String containing the date the picture was taken using the given
    217219   *         format.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31459 r31460  
    117117   * @return The image under the mouse cursor.
    118118   */
    119   public MapillaryAbstractImage getHighlighted() {
     119  public MapillaryAbstractImage getHighlightedImage() {
    120120    return this.highlightedImage;
    121121  }
     
    239239  public void selectPrevious(boolean moveToPicture) {
    240240    if (getSelectedImage() == null)
    241       return;
     241      throw new IllegalStateException();
    242242    if (getSelectedImage().getSequence() == null)
    243243      throw new IllegalStateException();
     
    277277    this.multiSelectedImages.clear();
    278278    this.multiSelectedImages.add(image);
    279     if (image != null) {
     279    if (image != null && Main.main != null) {
    280280      if (image instanceof MapillaryImage) {
    281281        MapillaryImage mapillaryImage = (MapillaryImage) image;
     
    284284          CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next());
    285285          if (mapillaryImage.next().next() != null)
    286             CacheUtils
    287                 .downloadPicture((MapillaryImage) mapillaryImage.next().next());
     286            CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.next()
     287                .next());
    288288        }
    289289        if (mapillaryImage.previous() != null) {
    290           CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous());
     290          CacheUtils
     291              .downloadPicture((MapillaryImage) mapillaryImage.previous());
    291292          if (mapillaryImage.previous().previous() != null)
    292             CacheUtils.downloadPicture((MapillaryImage) mapillaryImage.previous()
    293                 .previous());
     293            CacheUtils.downloadPicture((MapillaryImage) mapillaryImage
     294                .previous().previous());
    294295        }
    295296      }
    296297    }
    297     if (zoom)
     298    if (zoom && Main.main != null)
    298299      Main.map.mapView.zoomTo(getSelectedImage().getLatLon());
    299300    if (Main.main != null)
     
    325326        this.setSelectedImage(image);
    326327    }
    327     Main.map.mapView.repaint();
     328    if (Main.main != null)
     329      Main.map.mapView.repaint();
    328330  }
    329331
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31459 r31460  
    415415    g.drawImage(op.filter(bi, null), p.x - (width / 2), p.y - (height / 2),
    416416        Main.map.mapView);
    417     if (this.data.getHighlighted() == image) {
     417    if (this.data.getHighlightedImage() == image) {
    418418      drawPointHighlight(g, p, 16);
    419419    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31457 r31460  
    139139    return this.images.get(i - 1);
    140140  }
    141 
    142   /**
    143    * Returns the difference of index between two {@link MapillaryAbstractImage}
    144    * objects belonging to the same {@link MapillarySequence}.
    145    *
    146    * @param image1
    147    *          The first image.
    148    * @param image2
    149    *          The second image.
    150    * @return The distance between two {@link MapillaryAbstractImage} objects
    151    *         belonging to the same {@link MapillarySequence}.
    152    */
    153   public int getDistance(MapillaryAbstractImage image1,
    154       MapillaryAbstractImage image2) {
    155     if (!this.images.contains(image1) || !this.images.contains(image2))
    156       throw new IllegalArgumentException();
    157     return Math.abs(this.images.indexOf(image1) - this.images.indexOf(image2));
    158   }
    159141}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/WalkThread.java

    r31457 r31460  
    2222 */
    2323public class WalkThread extends Thread implements MapillaryDataListener {
    24   private int interval;
    25   private MapillaryData data;
    26   private Lock lock = new ReentrantLock();
     24  private final int interval;
     25  private final MapillaryData data;
     26  private final Lock lock;
    2727  private boolean end = false;
    2828  private final boolean waitForFullQuality;
     
    5353    this.data = MapillaryLayer.getInstance().getData();
    5454    this.data.addListener(this);
     55    this.lock = new ReentrantLock();
    5556  }
    5657
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31459 r31460  
    4545  public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    4646  /** Executor that will run the petitions. */
    47   private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
    48       100, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50));
     47  private static ThreadPoolExecutor EXECUTOR;
    4948
    5049  /**
     
    6362    queryStringParts.put("max_lat", maxLatLon.lat());
    6463    queryStringParts.put("max_lon", maxLatLon.lon());
     64    EXECUTOR = new ThreadPoolExecutor(3, 5, 100, TimeUnit.SECONDS,
     65        new ArrayBlockingQueue<Runnable>(50));
    6566    run(new MapillarySquareDownloadManagerThread(queryStringParts));
    6667  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryExportDialog.java

    r31451 r31460  
    3333  protected JOptionPane optionPane;
    3434  /** Button to export all downloaded images. */
    35   public JRadioButton all;
     35  public final JRadioButton all;
    3636  /**
    3737   * Button to export all images in the sequence of the selected MapillaryImage.
    3838   */
    39   public JRadioButton sequence;
     39  public final JRadioButton sequence;
    4040  /**
    4141   * Button to export all images belonging to the selected
    4242   * {@link MapillaryImage} objects.
    4343   */
    44   public JRadioButton selected;
     44  public final JRadioButton selected;
    4545  /** Button to rewrite all imported images. */
    46   public JRadioButton rewrite;
     46  public final JRadioButton rewrite;
    4747  /** Group of button containing all the options. */
    48   public ButtonGroup group;
    49   private JButton choose;
    50   private JLabel path;
     48  public final ButtonGroup group;
     49  private final JButton choose;
     50  private final JLabel path;
    5151  /** File chooser. */
    5252  public JFileChooser chooser;
    5353  protected String exportDirectory;
    54   private JButton ok;
     54  private final JButton ok;
    5555
    5656  /**
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31445 r31460  
    5757  private Rectangle selectedRect = null;
    5858
     59  /** HyperlinkLabel shown in the bottom right corner. */
    5960  protected HyperlinkLabel hyperlink;
    6061
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/JoinMode.java

    r31445 r31460  
    3737  @Override
    3838  public void mousePressed(MouseEvent e) {
    39     if (this.data.getHighlighted() == null)
     39    if (this.data.getHighlightedImage() == null)
    4040      return;
    4141    if (this.lastClick == null
    42         && this.data.getHighlighted() instanceof MapillaryImportedImage) {
    43       this.lastClick = (MapillaryImportedImage) this.data.getHighlighted();
     42        && this.data.getHighlightedImage() instanceof MapillaryImportedImage) {
     43      this.lastClick = (MapillaryImportedImage) this.data.getHighlightedImage();
    4444    } 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
     45        && this.data.getHighlightedImage() instanceof MapillaryImportedImage) {
     46      if (((this.data.getHighlightedImage().previous() == null && this.lastClick.next() == null) || (this.data
     47          .getHighlightedImage().next() == null && this.lastClick.previous() == null))
     48          && (this.data.getHighlightedImage().getSequence() != this.lastClick.getSequence() || this.lastClick
    4949              .getSequence() == 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());
     50        join(this.lastClick, (MapillaryImportedImage) this.data.getHighlightedImage());
     51      } else if (this.lastClick.next() == this.data.getHighlightedImage()
     52          || this.lastClick.previous() == this.data.getHighlightedImage())
     53        unjoin(this.lastClick, (MapillaryImportedImage) this.data.getHighlightedImage());
    5454      this.lastClick = null;
    5555    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31445 r31460  
    182182    }
    183183
    184     if (this.data.getHighlighted() != closestTemp && closestTemp != null) {
     184    if (this.data.getHighlightedImage() != closestTemp && closestTemp != null) {
    185185      this.data.setHighlightedImage(closestTemp);
    186186      MapillaryMainDialog.getInstance().setImage(closestTemp);
    187187      MapillaryMainDialog.getInstance().updateImage(false);
    188     } else if (this.data.getHighlighted() != closestTemp && closestTemp == null) {
     188    } else if (this.data.getHighlightedImage() != closestTemp && closestTemp == null) {
    189189      this.data.setHighlightedImage(null);
    190190      MapillaryMainDialog.getInstance().setImage(this.data.getSelectedImage());
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/AbstractTest.java

    r31456 r31460  
    1212public abstract class AbstractTest {
    1313
    14   private static boolean started = false;
    15 
    1614  /**
    1715   * Initiates the basic parts of JOSM.
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/ImportTest.java

    r31456 r31460  
    1010import javax.imageio.IIOException;
    1111
    12 import org.apache.commons.imaging.common.RationalNumber;
    13 import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
    1412import org.openstreetmap.josm.data.coor.LatLon;
    1513import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
    16 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    1714
    1815/**
     
    5148    img.getImage();
    5249  }
    53 
    54   /**
    55    * Test degMinSecToDouble method.
    56    */
    57   @Test
    58   public void degMinSecToDoubleTest() {
    59     RationalNumber[] num = new RationalNumber[3];
    60     num[0] = new RationalNumber(1, 1);
    61     num[1] = new RationalNumber(0, 1);
    62     num[2] = new RationalNumber(0, 1);
    63     String ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH;
    64     assertEquals(1, MapillaryUtils.degMinSecToDouble(num, ref), 0.01);
    65     ref = GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH;
    66     assertEquals(-1, MapillaryUtils.degMinSecToDouble(num, ref), 0.01);
    67     num[0] = new RationalNumber(180, 1);
    68     assertEquals(-180, MapillaryUtils.degMinSecToDouble(num, ref), 0.01);
    69     num[0] = new RationalNumber(190, 1);
    70     assertEquals(170, MapillaryUtils.degMinSecToDouble(num, ref), 0.01);
    71   }
    7250}
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImageTest.java

    r31445 r31460  
    4242  }
    4343
    44   private void testGetDate(String expected, MapillaryAbstractImage img,
     44  private static void testGetDate(String expected, MapillaryAbstractImage img,
    4545      boolean isoDates, boolean displayHour, boolean format24) {
    4646    Main.pref.put("iso.dates", isoDates);
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/oauth/UploadTest.java

    r31459 r31460  
    1 package org.openstreetmap.josm.plugins.mapillary;
     1package org.openstreetmap.josm.plugins.mapillary.oauth;
    22
    33import static org.junit.Assert.assertEquals;
     
    1818import org.junit.Test;
    1919import org.openstreetmap.josm.data.coor.LatLon;
     20import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
     21import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
    2022import org.openstreetmap.josm.plugins.mapillary.actions.MapillaryImportAction;
    2123import org.openstreetmap.josm.plugins.mapillary.oauth.UploadUtils;
    2224import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2325
     26/**
     27 * Tests the {@link UploadUtils} class.
     28 *
     29 * @author nokutu
     30 * @see UploadUtils
     31 */
    2432public class UploadTest extends AbstractTest {
    2533
    2634  /**
    27    * Tests the updateFile method from {@link MapillaryImportAction} class.
     35   * Tests the {@link UploadUtils#updateFile(MapillaryImportedImage)} method.
    2836   */
    2937  @Test
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/TestUtil.java

    r31456 r31460  
    11package org.openstreetmap.josm.plugins.mapillary.utils;
    22
    3 import java.io.File;
    43
    54import org.openstreetmap.josm.Main;
    65import org.openstreetmap.josm.data.projection.Projections;
    7 import org.openstreetmap.josm.plugins.PluginException;
    8 import org.openstreetmap.josm.plugins.PluginInformation;
    96import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    10 import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    117import org.openstreetmap.josm.tools.I18n;
    128
Note: See TracChangeset for help on using the changeset viewer.