Ignore:
Timestamp:
2015-07-30T13:17:49+02:00 (10 years ago)
Author:
nokutu
Message:

Improved tests and code quality. Login is already working. Tests now do not requiere the JOSM window to be opened.

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
1 added
7 edited

Legend:

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

    r31415 r31418  
    6868   */
    6969  public synchronized void add(List<MapillaryAbstractImage> images) {
     70    add(images, true);
     71  }
     72
     73  /**
     74   * Adds an MapillaryImage to the object, and then repaints mapView.
     75   *
     76   * @param image
     77   *          The image to be added.
     78   */
     79  public synchronized void add(MapillaryAbstractImage image) {
     80    add(image, true);
     81  }
     82
     83  /**
     84   * Adds a new listener.
     85   *
     86   * @param lis
     87   *          Listener to be added.
     88   */
     89  public void addListener(MapillaryDataListener lis) {
     90    listeners.add(lis);
     91  }
     92
     93  /**
     94   * Removes a listener.
     95   *
     96   * @param lis
     97   *          Listener to be removed.
     98   */
     99  public void removeListener(MapillaryDataListener lis) {
     100    listeners.remove(lis);
     101  }
     102
     103  /**
     104   * Adds a set of MapillaryImages to the object, but doesn't repaint mapView.
     105   * This is needed for concurrency.
     106   *
     107   * @param images
     108   *          The set of images to be added.
     109   * @param update
     110   *          Whether the map must be updated or no.
     111   */
     112  public synchronized void add(List<MapillaryAbstractImage> images,
     113      boolean update) {
    70114    for (MapillaryAbstractImage image : images) {
    71       add(image);
    72     }
    73   }
    74 
    75   /**
    76    * Adds an MapillaryImage to the object, and then repaints mapView.
     115      add(image, update);
     116    }
     117  }
     118
     119  /**
     120   * Highlights the image under the cursor.
     121   *
     122   * @param image
     123   *          The image under the cursor.
     124   */
     125  public void setHighlightedImage(MapillaryAbstractImage image) {
     126    highlightedImage = image;
     127  }
     128
     129  /**
     130   * Returns the image under the mouse cursor.
     131   *
     132   * @return The image under the mouse cursor.
     133   */
     134  public MapillaryAbstractImage getHighlighted() {
     135    return highlightedImage;
     136  }
     137
     138  /**
     139   * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
     140   * needed for concurrency.
    77141   *
    78142   * @param image
    79143   *          The image to be added.
    80    */
    81   public synchronized void add(MapillaryAbstractImage image) {
     144   * @param update
     145   *          Whether the map must be updated or not.
     146   */
     147  public synchronized void add(MapillaryAbstractImage image, boolean update) {
    82148    if (!images.contains(image)) {
    83149      this.images.add(image);
    84150    }
    85     dataUpdated();
    86     fireImagesAdded();
    87   }
    88 
    89   /**
    90    * Adds a new listener.
    91    *
    92    * @param lis
    93    *          Listener to be added.
    94    */
    95   public void addListener(MapillaryDataListener lis) {
    96     listeners.add(lis);
    97   }
    98 
    99   /**
    100    * Removes a listener.
    101    *
    102    * @param lis
    103    *          Listener to be removed.
    104    */
    105   public void removeListener(MapillaryDataListener lis) {
    106     listeners.remove(lis);
    107   }
    108 
    109   /**
    110    * Adds a set of MapillaryImages to the object, but doesn't repaint mapView.
    111    * This is needed for concurrency.
    112    *
    113    * @param images
    114    *          The set of images to be added.
    115    */
    116   public synchronized void addWithoutUpdate(List<MapillaryAbstractImage> images) {
    117     for (MapillaryAbstractImage image : images) {
    118       addWithoutUpdate(image);
    119     }
    120   }
    121 
    122   /**
    123    * Highlights the image under the cursor.
    124    *
    125    * @param image
    126    *          The image under the cursor.
    127    */
    128   public void setHighlightedImage(MapillaryAbstractImage image) {
    129     highlightedImage = image;
    130   }
    131 
    132   /**
    133    * Returns the image under the mouse cursor.
    134    *
    135    * @return The image under the mouse cursor.
    136    */
    137   public MapillaryAbstractImage getHighlighted() {
    138     return highlightedImage;
    139   }
    140 
    141   /**
    142    * Adds a MapillaryImage to the object, but doesn't repaint mapView. This is
    143    * needed for concurrency.
    144    *
    145    * @param image
    146    *          The image to be added.
    147    */
    148   public synchronized void addWithoutUpdate(MapillaryAbstractImage image) {
    149     if (!images.contains(image)) {
    150       this.images.add(image);
    151     }
     151    if (update)
     152      dataUpdated();
    152153    fireImagesAdded();
    153154  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31417 r31418  
    5252  private final MapillaryDownloadAction downloadAction;
    5353  private final MapillaryExportAction exportAction;
     54  /** Import action */
    5455  public static MapillaryImportAction importAction;
    5556  private final MapillaryZoomAction zoomAction;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31417 r31418  
    5050   */
    5151  public MapillaryImportAction() {
    52     super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory + "images/icon24.png"),
    53         tr("Import local pictures"), Shortcut.registerShortcut(
    54             "Import Mapillary", tr("Import pictures into Mapillary layer"),
     52    super(tr("Import pictures"), new ImageProvider(MapillaryPlugin.directory
     53        + "images/icon24.png"), tr("Import local pictures"), Shortcut
     54        .registerShortcut("Import Mapillary",
     55            tr("Import pictures into Mapillary layer"),
    5556            KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImport",
    5657        false);
     
    174175   */
    175176  public MapillaryImportedImage readNoTags(File file) {
     177    return readNoTags(
     178        file,
     179        Main.map.mapView.getProjection().eastNorth2latlon(
     180            Main.map.mapView.getCenter()));
     181  }
     182
     183  /**
     184   * Reads a image file that doesn't contain the needed GPS information. And
     185   * creates a new icon in the middle of the map.
     186   *
     187   * @param file
     188   * @param pos
     189   *          A {@link LatLon} object indicating the position in the map where
     190   *          the image must be set.
     191   * @return The imported image.
     192   */
     193  public MapillaryImportedImage readNoTags(File file, LatLon pos) {
    176194    double HORIZONTAL_DISTANCE = 0.0001;
    177195    double horDev;
     
    180198    else
    181199      horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
    182     LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
    183         Main.map.mapView.getCenter());
    184200    noTagsPics++;
    185201    return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
     
    246262    result += degMinSec[2].doubleValue() / 3600; // seconds
    247263
    248     while (result >= 180) {
    249       result -= 180;
    250     }
    251     while (result <= -180) {
    252       result += 180;
    253     }
    254 
    255264    if (GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH.equals(ref)
    256265        || GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST.equals(ref)) {
     
    258267    }
    259268
     269    result = 360*((result+180)/360 - Math.floor((result+180)/360)) - 180;
    260270    return result;
    261271  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillaryDownloader.java

    r31409 r31418  
    3333  public final static String BASE_URL = "https://a.mapillary.com/v2/";
    3434  /** Client ID for the app */
    35   public final static String CLIENT_ID = "NzNRM2otQkR2SHJzaXJmNmdQWVQ0dzo1YTA2NmNlODhlNWMwOTBm";
     35  public final static String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    3636  /** Executor that will run the petitions. */
    3737  private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31417 r31418  
    118118        }
    119119
    120         layer.getMapillaryData().addWithoutUpdate(
    121             new ArrayList<MapillaryAbstractImage>(finalImages));
     120        layer.getMapillaryData().add(
     121            new ArrayList<MapillaryAbstractImage>(finalImages), false);
    122122      }
    123123    } catch (IOException e) {
     
    125125          + " might be a Mapillary problem.");
    126126    }
     127    layer.getMapillaryData().dataUpdated();
    127128  }
    128129
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31406 r31418  
    8484      oauth.setText("Login");
    8585    else
    86       oauth.setText("Already loged in, click to relogin.");
     86      oauth.setText("Logged as: " + Main.pref.get("mapillary.username") + ". Click to relogin.");
    8787    panel.add(oauth);
    8888    gui.getDisplayPreference().addSubTab(this, "Mapillary", panel);
     
    130130      portListener.start();
    131131
    132       String url = "http://www.mapillary.io/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=MkJKbDA0bnZuZlcxeTJHTmFqN3g1dzplZTlkZjQyYjYyZTczOTdi&response_type=token&scope=user:email";
     132      String url = "http://www.mapillary.com/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz&response_type=token&scope=user:read%20public:upload%20public:write";
    133133      Desktop desktop = Desktop.getDesktop();
    134134      if (desktop.isSupported(Desktop.Action.BROWSE)) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/OAuthPortListener.java

    r31412 r31418  
    88import java.net.ServerSocket;
    99import java.net.Socket;
     10import java.net.URL;
    1011import java.util.Scanner;
    1112
     
    2526      ServerSocket serverSocket = new ServerSocket(8763);
    2627      Socket clientSocket = serverSocket.accept();
    27       PrintWriter out = new PrintWriter(new OutputStreamWriter(clientSocket.getOutputStream(), "UTF-8"), true);
    28       Scanner in = new Scanner(new InputStreamReader(clientSocket.getInputStream(), "UTF-8"));
     28      PrintWriter out = new PrintWriter(new OutputStreamWriter(
     29          clientSocket.getOutputStream(), "UTF-8"), true);
     30      Scanner in = new Scanner(new InputStreamReader(
     31          clientSocket.getInputStream(), "UTF-8"));
    2932      String s;
    3033      String accessToken = null;
     
    4144          }
    4245          break;
    43         }
     46        } else if (s.contains("keep-alive"))
     47          break;
    4448      }
    4549
    4650      writeContent(out);
    4751
    48       Main.info("Successful login with Mapillary, the access token is: "
    49           + accessToken);
    50       Main.pref.put("mapillary.access-token", accessToken);
    51 
    5252      out.close();
    5353      in.close();
    5454      serverSocket.close();
     55
     56      Main.info("Successful login with Mapillary, the access token is: "
     57          + accessToken);
     58      // Saves the access token in preferences.
     59      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"));
     69
     70      Main.info("The username is: " + Main.pref.get("mapillary.username"));
     71
    5572    } catch (BindException e) {
    5673      return;
Note: See TracChangeset for help on using the changeset viewer.