Ignore:
Timestamp:
2015-12-05T00:54:44+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] More sonar issues resolved, some tests added and v1.1.0 released

Location:
applications/editors/josm/plugins/mapillary
Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/build.gradle

    r31798 r31799  
    105105  manifest {
    106106    attributes("Plugin-Mainversion": project.property('plugin.main.version'),
    107                "Plugin-Version": "31784",
     107               "Plugin-Version": "31799",
    108108               "Plugin-Class": project.property('plugin.class'),
    109109               "Plugin-Description": project.property('plugin.description'),
  • applications/editors/josm/plugins/mapillary/gradle.properties

    r31783 r31799  
    77plugin.main.version=8433
    88plugin.requires=apache-commons;apache-http
    9 plugin.version=1.0.4
    10 #plugin.early=
    11 #plugin.stage=
     9plugin.version=1.1.0
     10#plugin.early=...
     11#plugin.stage=...
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java

    r31796 r31799  
    55import java.util.Calendar;
    66import java.util.Date;
     7import java.util.Locale;
    78
    89import org.openstreetmap.josm.Main;
     
    1718 */
    1819public abstract class MapillaryAbstractImage {
     20  /**
     21   * If two values for field ca differ by less than EPSILON both values are considered equal.
     22   */
     23  private static final float EPSILON = 1e-5f;
    1924
    2025  /** The time the image was captured, in Epoch format. */
     
    8792   */
    8893  public String getDate() {
    89     StringBuilder format = new StringBuilder("");
     94    StringBuilder format = new StringBuilder(26);
    9095    if (Main.pref.getBoolean("iso.dates"))
    9196      format.append("yyyy-MM-dd");
     
    108113   * @return A String containing the date the picture was taken using the given
    109114   *         format.
     115   * @throws NullPointerException if parameter format is <code>null</code>
    110116   */
    111117  public String getDate(String format) {
    112118    Date date = new Date(getCapturedAt());
    113119
    114     SimpleDateFormat formatter = new SimpleDateFormat(format);
     120    SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
    115121    formatter.setTimeZone(Calendar.getInstance().getTimeZone());
    116122    return formatter.format(date);
     
    165171   */
    166172  public boolean isModified() {
    167     return (this.getLatLon() != this.latLon || this.getCa() != this.ca);
     173    return !this.getLatLon().equals(this.latLon) || Math.abs(this.getCa() - this.ca) < EPSILON;
    168174  }
    169175
     
    197203   */
    198204  public MapillaryAbstractImage next() {
    199     synchronized (this.getClass()) {
     205    synchronized (MapillaryAbstractImage.class) {
    200206      if (this.getSequence() == null)
    201207        return null;
     
    211217   */
    212218  public MapillaryAbstractImage previous() {
    213     synchronized (this.getClass()) {
     219    synchronized (MapillaryAbstractImage.class) {
    214220      if (this.getSequence() == null)
    215221        return null;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31796 r31799  
    4242
    4343    // Adds the basic set of listeners.
    44     addListener(MapillaryPlugin.walkAction);
    45     addListener(MapillaryPlugin.zoomAction);
    46     addListener(MapillaryPlugin.uploadAction);
     44    addListener(MapillaryPlugin.getWalkAction());
     45    addListener(MapillaryPlugin.getZoomAction());
     46    addListener(MapillaryPlugin.getUploadAction());
    4747    if (Main.main != null)
    4848      addListener(MapillaryMainDialog.getInstance());
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31787 r31799  
    9595
    9696  @Override
    97   public boolean equals(Object object) {
    98     if (object instanceof MapillaryImportedImage)
    99       return this.file.equals(((MapillaryImportedImage) object).file);
     97  public boolean equals(Object other) {
     98    if (other != null && other.getClass() == this.getClass())
     99      return this.file.equals(((MapillaryImportedImage) other).file);
    100100    return false;
    101101  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31797 r31799  
    1818import java.awt.image.AffineTransformOp;
    1919import java.awt.image.BufferedImage;
    20 import java.util.ArrayList;
    21 import java.util.List;
    2220import java.util.concurrent.CopyOnWriteArrayList;
    2321
     
    7876
    7977  /** If the download is in semiautomatic during this object lifetime. */
    80   public boolean TEMP_SEMIAUTOMATIC = false;
     78  public boolean tempSemiautomatic;
    8179
    8280  /** Unique instance of the class. */
     
    9290  public AbstractMode mode;
    9391
    94   private int highlightPointRadius = Main.pref.getInteger(
    95       "mappaint.highlight.radius", 7);
    96   private int highlightStep = Main.pref
    97       .getInteger("mappaint.highlight.step", 4);
     92  private final int highlightPointRadius = Main.pref.getInteger("mappaint.highlight.radius", 7);
     93  private final int highlightStep = Main.pref.getInteger("mappaint.highlight.step", 4);
    9894
    9995  private volatile TexturePaint hatched;
     
    123119    }
    124120    // Does not execute when in headless mode
    125     if (MapillaryPlugin.EXPORT_MENU != null) {
    126       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, true);
     121    if (MapillaryPlugin.getExportMenu() != null) {
     122      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getExportMenu(), true);
    127123      if (!MapillaryMainDialog.getInstance().isShowing())
    128124        MapillaryMainDialog.getInstance().getButton().doClick();
     
    220216    MapillaryMainDialog.getInstance().setImage(null);
    221217    MapillaryMainDialog.getInstance().updateImage();
    222     MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false);
    223     MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false);
     218    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getExportMenu(), false);
     219    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getZoomMenu(), false);
    224220    Main.map.mapView.removeMouseListener(this.mode);
    225221    Main.map.mapView.removeMouseMotionListener(this.mode);
     
    464460  private MapillaryImage[] getClosestImagesFromDifferentSequences() {
    465461    if (!(this.data.getSelectedImage() instanceof MapillaryImage))
    466       return new MapillaryImage[2];
     462      return new MapillaryImage[]{null, null};
    467463    MapillaryImage selected = (MapillaryImage) this.data.getSelectedImage();
    468464    MapillaryImage[] ret = new MapillaryImage[2];
    469     double[] distances = { SEQUENCE_MAX_JUMP_DISTANCE,
    470         SEQUENCE_MAX_JUMP_DISTANCE };
     465    double[] distances = {
     466        SEQUENCE_MAX_JUMP_DISTANCE,
     467        SEQUENCE_MAX_JUMP_DISTANCE
     468    };
    471469    LatLon selectedCoords = this.data.getSelectedImage().getLatLon();
    472470    for (MapillaryAbstractImage imagePrev : this.data.getImages()) {
     
    501499  @Override
    502500  public Object getInfoComponent() {
    503     StringBuilder sb = new StringBuilder();
    504     sb.append(tr("Mapillary layer"));
    505     sb.append("\n");
    506     sb.append(tr("Total images:"));
    507     sb.append(" ");
    508     sb.append(this.data.size());
    509     sb.append("\n");
    510     return sb.toString();
     501    return new StringBuilder(35)
     502      .append(tr("Mapillary layer"))
     503      .append('\n')
     504      .append(tr("Total images:"))
     505      .append(' ')
     506      .append(this.data.size())
     507      .append('\n')
     508      .toString();
    511509  }
    512510
    513511  @Override
    514512  public String getToolTipText() {
    515     return this.data.size() + " " + tr("images");
     513    return this.data.size() + (' ' + tr("images"));
    516514  }
    517515
     
    568566    if (newLayer == this) {
    569567      MapillaryUtils.updateHelpText();
    570       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, true);
     568      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getJoinMenu(), true);
    571569    } else
    572       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.JOIN_MENU, false);
     570      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getJoinMenu(), false);
    573571  }
    574572
     
    589587   *
    590588   */
    591   private class DelayedDownload extends Thread {
     589  private static class DelayedDownload extends Thread {
    592590
    593591    @Override
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31796 r31799  
    4141 */
    4242public class MapillaryPlugin extends Plugin {
     43  public static final String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    4344
    4445  /** OS route separator */
     
    6364  private final MapillaryExportAction exportAction;
    6465  /** Import action */
    65   public static MapillaryImportAction importAction;
     66  private final MapillaryImportAction importAction;
    6667  /** Zoom action */
    67   public static MapillaryZoomAction zoomAction;
     68  private static MapillaryZoomAction zoomAction;
    6869  private final MapillaryDownloadViewAction downloadViewAction;
    6970  private final MapillaryImportIntoSequenceAction importIntoSequenceAction;
    7071  private final MapillaryJoinAction joinAction;
    7172  /** Walk action */
    72   public static MapillaryWalkAction walkAction;
     73  private static MapillaryWalkAction walkAction;
    7374  /** Upload action */
    74   public static MapillaryUploadAction uploadAction;
     75  private static MapillaryUploadAction uploadAction;
    7576
    7677  /** Menu button for the {@link MapillaryDownloadAction} action. */
    77   public static JMenuItem DOWNLOAD_MENU;
     78  private JMenuItem downloadMenu;
    7879  /** Menu button for the {@link MapillaryExportAction} action. */
    79   public static JMenuItem EXPORT_MENU;
     80  private static JMenuItem exportMenu;
    8081  /** Menu button for the {@link MapillaryImportAction} action. */
    81   public static JMenuItem IMPORT_MENU;
     82  private JMenuItem importMenu;
    8283  /** Menu button for the {@link MapillaryZoomAction} action. */
    83   public static JMenuItem ZOOM_MENU;
     84  private static JMenuItem zoomMenu;
    8485  /** Menu button for the {@link MapillaryDownloadViewAction} action. */
    85   public static JMenuItem DOWNLOAD_VIEW_MENU;
     86  private static JMenuItem downloadViewMenu;
    8687  /** Menu button for the {@link MapillaryImportIntoSequenceAction} action. */
    87   public static JMenuItem IMPORT_INTO_SEQUENCE_MENU;
     88  private JMenuItem importIntoSequenceMenu;
    8889  /** Menu button for the {@link MapillaryJoinAction} action. */
    89   public static JMenuItem JOIN_MENU;
     90  private static JMenuItem joinMenu;
    9091  /** Menu button for the {@link MapillaryWalkAction} action. */
    91   public static JMenuItem WALK_MENU;
     92  private static JMenuItem walkMenu;
    9293  /** Menu button for the {@link MapillaryUploadAction} action. */
    93   public static JMenuItem UPLOAD_MENU;
     94  private static JMenuItem uploadMenu;
    9495
    9596  /**
     
    102103    super(info);
    103104
    104     this.downloadAction = new MapillaryDownloadAction();
     105    downloadAction = new MapillaryDownloadAction();
    105106    walkAction = new MapillaryWalkAction();
    106     this.exportAction = new MapillaryExportAction();
     107    exportAction = new MapillaryExportAction();
    107108    importAction = new MapillaryImportAction();
    108109    zoomAction = new MapillaryZoomAction();
    109     this.downloadViewAction = new MapillaryDownloadViewAction();
    110     this.importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
    111     this.joinAction = new MapillaryJoinAction();
     110    downloadViewAction = new MapillaryDownloadViewAction();
     111    importIntoSequenceAction = new MapillaryImportIntoSequenceAction();
     112    joinAction = new MapillaryJoinAction();
    112113    uploadAction = new MapillaryUploadAction();
    113114
    114115    if (Main.main != null) { // important for headless mode
    115       DOWNLOAD_MENU = MainMenu.add(Main.main.menu.imageryMenu,
    116           this.downloadAction, false);
    117       EXPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, this.exportAction,
    118           false, 14);
    119       IMPORT_INTO_SEQUENCE_MENU = MainMenu.add(Main.main.menu.fileMenu,
    120           this.importIntoSequenceAction, false, 14);
    121       IMPORT_MENU = MainMenu.add(Main.main.menu.fileMenu, importAction, false,
    122           14);
    123       UPLOAD_MENU = MainMenu.add(Main.main.menu.fileMenu, uploadAction, false,
    124           14);
    125       ZOOM_MENU = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
    126       DOWNLOAD_VIEW_MENU = MainMenu.add(Main.main.menu.fileMenu,
    127           this.downloadViewAction, false, 14);
    128       JOIN_MENU = MainMenu.add(Main.main.menu.dataMenu, this.joinAction, false);
    129       WALK_MENU = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false);
    130 
    131       EXPORT_MENU.setEnabled(false);
    132       DOWNLOAD_MENU.setEnabled(false);
    133       IMPORT_MENU.setEnabled(false);
    134       IMPORT_INTO_SEQUENCE_MENU.setEnabled(false);
    135       ZOOM_MENU.setEnabled(false);
    136       DOWNLOAD_VIEW_MENU.setEnabled(false);
    137       JOIN_MENU.setEnabled(false);
    138       WALK_MENU.setEnabled(false);
     116      downloadMenu = MainMenu.add(Main.main.menu.imageryMenu, this.downloadAction, false);
     117      exportMenu = MainMenu.add(Main.main.menu.fileMenu, exportAction, false, 14);
     118      importIntoSequenceMenu = MainMenu.add(Main.main.menu.fileMenu, importIntoSequenceAction, false, 14);
     119      importMenu = MainMenu.add(Main.main.menu.fileMenu, importAction, false, 14);
     120      uploadMenu = MainMenu.add(Main.main.menu.fileMenu, uploadAction, false, 14);
     121      zoomMenu = MainMenu.add(Main.main.menu.viewMenu, zoomAction, false, 15);
     122      downloadViewMenu = MainMenu.add(Main.main.menu.fileMenu, this.downloadViewAction, false, 14);
     123      joinMenu = MainMenu.add(Main.main.menu.dataMenu, this.joinAction, false);
     124      walkMenu = MainMenu.add(Main.main.menu.moreToolsMenu, walkAction, false);
     125
     126      exportMenu.setEnabled(false);
     127      downloadMenu.setEnabled(false);
     128      importMenu.setEnabled(false);
     129      importIntoSequenceMenu.setEnabled(false);
     130      zoomMenu.setEnabled(false);
     131      downloadViewMenu.setEnabled(false);
     132      joinMenu.setEnabled(false);
     133      walkMenu.setEnabled(false);
    139134    }
    140135
    141136    try {
    142       CACHE = JCSCacheManager.getCache("mapillary", 10, 10000,
    143           this.getPluginDir() + "/cache/");
     137      CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, this.getPluginDir() + "/cache/");
    144138    } catch (IOException e) {
    145139      Main.error(e);
     
    148142    if (Main.pref.get("mapillary.access-token") == null)
    149143      MapillaryUser.isTokenValid = false;
     144  }
     145
     146  /**
     147   * @return the menu-item associated with the {@link MapillaryDownloadViewAction}
     148   */
     149  public static JMenuItem getDownloadViewMenu() {
     150    return downloadViewMenu;
     151  }
     152
     153  /**
     154   * @return the menu-item associated with the {@link MapillaryExportAction}
     155   */
     156  public static JMenuItem getExportMenu() {
     157    return exportMenu;
     158  }
     159
     160  /**
     161   * @return the menu-item associated with the {@link MapillaryJoinAction}
     162   */
     163  public static JMenuItem getJoinMenu() {
     164    return joinMenu;
     165  }
     166
     167  /**
     168   * @return the {@link MapillaryUploadAction} for the plugin
     169   */
     170  public static MapillaryDataListener getUploadAction() {
     171    return uploadAction;
     172  }
     173
     174  /**
     175   * @return the menu-item associated with the {@link MapillaryUploadAction}
     176   */
     177  public static JMenuItem getUploadMenu() {
     178    return uploadMenu;
     179  }
     180
     181  /**
     182   * @return the {@link MapillaryWalkAction} for the plugin
     183   */
     184  public static MapillaryWalkAction getWalkAction() {
     185    return walkAction;
     186  }
     187
     188  /**
     189   * @return the menu-item associated with the {@link MapillaryWalkAction}
     190   */
     191  public static JMenuItem getWalkMenu() {
     192    return walkMenu;
     193  }
     194
     195  /**
     196   * @return the {@link MapillaryZoomAction} for the plugin
     197   */
     198  public static MapillaryDataListener getZoomAction() {
     199    return zoomAction;
     200  }
     201
     202  /**
     203   * @return the menu-item associated with the {@link MapillaryZoomAction}
     204   */
     205  public static JMenuItem getZoomMenu() {
     206    return zoomMenu;
    150207  }
    151208
     
    159216      Main.map.addToggleDialog(MapillaryHistoryDialog.getInstance(), false);
    160217      Main.map.addToggleDialog(MapillaryFilterDialog.getInstance(), false);
    161       setMenuEnabled(DOWNLOAD_MENU, true);
     218      setMenuEnabled(downloadMenu, true);
    162219      if (MapillaryDownloader.getMode() == MapillaryDownloader.MODES.Manual)
    163         setMenuEnabled(DOWNLOAD_VIEW_MENU, true);
    164       setMenuEnabled(IMPORT_MENU, true);
    165       setMenuEnabled(IMPORT_INTO_SEQUENCE_MENU, true);
     220        setMenuEnabled(downloadViewMenu, true);
     221      setMenuEnabled(importMenu, true);
     222      setMenuEnabled(importIntoSequenceMenu, true);
    166223    }
    167224    if (oldFrame != null && newFrame == null) { // map frame destroyed
     
    169226      MapillaryHistoryDialog.destroyInstance();
    170227      MapillaryFilterDialog.destroyInstance();
    171       setMenuEnabled(DOWNLOAD_MENU, false);
    172       setMenuEnabled(DOWNLOAD_VIEW_MENU, false);
    173       setMenuEnabled(IMPORT_MENU, false);
    174       setMenuEnabled(IMPORT_INTO_SEQUENCE_MENU, false);
     228      setMenuEnabled(downloadMenu, false);
     229      setMenuEnabled(downloadViewMenu, false);
     230      setMenuEnabled(importMenu, false);
     231      setMenuEnabled(importIntoSequenceMenu, false);
    175232    }
    176233  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryTrafficSignLayer.java

    r31787 r31799  
    33
    44import java.awt.Color;
     5import java.awt.Component;
    56import java.awt.Font;
    67import java.awt.FontFormatException;
     
    1314import javax.swing.Action;
    1415import javax.swing.Icon;
     16import javax.swing.JLabel;
    1517
    1618import org.openstreetmap.josm.data.Bounds;
     
    2224import org.openstreetmap.josm.plugins.mapillary.traffico.TrafficoSign;
    2325import org.openstreetmap.josm.plugins.mapillary.traffico.TrafficoSignElement;
     26import org.openstreetmap.josm.tools.I18n;
    2427
    2528public class MapillaryTrafficSignLayer extends AbstractModifiableLayer {
     29  private static final String TRAFFICO_PATH = "data/fonts/traffico/traffico.ttf";
    2630  private static MapillaryTrafficSignLayer instance;
     31  private final Font traffico;
     32
     33  private MapillaryTrafficSignLayer() throws IOException {
     34    super("Mapillary traffic signs");
     35    try {
     36      traffico = Font.createFont(Font.TRUETYPE_FONT, new File("data/fonts/traffico/traffico.ttf")).deriveFont(50.0f);
     37    } catch (FontFormatException e) {
     38      throw new IOException(I18n.tr("Traffic sign font at ''{0}'' has wrong format.", TRAFFICO_PATH), e);
     39    } catch (IOException e) {
     40      throw new IOException(I18n.tr("Could not read font-file from ''{{0}}''.", TRAFFICO_PATH), e);
     41    }
     42  }
    2743
    2844  /**
     
    3046   *
    3147   * @return the only instance of the traffic sign layer
     48   * @throws IOException if some error occured while reading the icon-font traffico or
     49   *         if the traffico font has the wrong format
    3250   */
    33   public static MapillaryTrafficSignLayer getInstance() {
    34     return instance == null ? (instance = new MapillaryTrafficSignLayer())
    35         : instance;
    36   }
    37 
    38   /**
    39    * @param name
    40    */
    41   private MapillaryTrafficSignLayer() {
    42     super("Mapillary traffic signs");
     51  public static MapillaryTrafficSignLayer getInstance() throws IOException {
     52    if (instance == null)
     53      instance = new MapillaryTrafficSignLayer();
     54    return instance;
    4355  }
    4456
     
    6173  @Override
    6274  public void paint(Graphics2D g, MapView mv, Bounds box) {
    63     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    64         RenderingHints.VALUE_ANTIALIAS_ON);
    65     try {
    66       g.setFont(Font.createFont(Font.TRUETYPE_FONT,
    67           new File("data/fonts/traffico/traffico.ttf")).deriveFont(50.0f));
    68     } catch (FontFormatException e) {
    69       e.printStackTrace();
    70     } catch (IOException e) {
    71       e.printStackTrace();
    72     }
     75    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
     76    g.setFont(traffico);
    7377
    7478    Point[] points = new Point[3];
     
    9195    // Start iterating the images
    9296    g.setColor(Color.MAGENTA);
    93     for (MapillaryAbstractImage img : MapillaryLayer.getInstance()
    94         .getData().getImages()) {
     97    for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData().getImages()) {
    9598      if (img instanceof MapillaryImage) {
    96         g.fillOval(mv.getPoint(img.getLatLon()).x - 3,
    97             mv.getPoint(img.getLatLon()).y - 3, 6, 6);
     99        g.fillOval(mv.getPoint(img.getLatLon()).x - 3, mv.getPoint(img.getLatLon()).y - 3, 6, 6);
    98100        if (((MapillaryImage) img).getSigns().size() >= 1) {
    99101          Point imgLoc = mv.getPoint(img.getLatLon());
    100           for (TrafficoSignElement e : TrafficoSign.getSign("de",
    101               ((MapillaryImage) img).getSigns().get(0))) {
     102          for (TrafficoSignElement e : TrafficoSign.getSign("de", ((MapillaryImage) img).getSigns().get(0))) {
    102103            g.setColor(e.getColor());
    103104            g.drawString("" + e.getGlyph(), imgLoc.x, imgLoc.y);
     
    137138  @Override
    138139  public void mergeFrom(Layer from) {
    139     // Does nothing as this layer is not mergeable (see method
    140     // isMergable(Layer))
     140    // Does nothing as this layer is not mergeable (see method isMergable(Layer))
    141141  }
    142142
     
    163163  public void visitBoundingBox(BoundingXYVisitor v) {
    164164    // TODO Auto-generated method stub
    165 
    166165  }
    167166
     
    172171   */
    173172  @Override
    174   public Object getInfoComponent() {
    175     // TODO Auto-generated method stub
    176     return null;
     173  public Component getInfoComponent() {
     174    return new JLabel("Mapillary traffic sign layer");
    177175  }
    178176
     
    184182  @Override
    185183  public Action[] getMenuEntries() {
    186     // TODO Auto-generated method stub
    187     return null;
     184    return new Action[]{};
    188185  }
    189186
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryUploadAction.java

    r31787 r31799  
    7171      MapillaryAbstractImage newImage) {
    7272    if (oldImage == null && newImage != null)
    73       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.UPLOAD_MENU, true);
     73      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getUploadMenu(), true);
    7474    else if (oldImage != null && newImage == null)
    75       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.UPLOAD_MENU, false);
     75      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getUploadMenu(), false);
    7676  }
    7777}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryWalkAction.java

    r31787 r31799  
    101101      MapillaryAbstractImage newImage) {
    102102    if (newImage != null)
    103       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.WALK_MENU, true);
     103      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getWalkMenu(), true);
    104104    else
    105       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.WALK_MENU, false);
     105      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getWalkMenu(), false);
    106106  }
    107107
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryZoomAction.java

    r31787 r31799  
    5151      MapillaryAbstractImage newImage) {
    5252    if (oldImage == null && newImage != null)
    53       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, true);
     53      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getZoomMenu(), true);
    5454    else if (oldImage != null && newImage == null)
    55       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false);
     55      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getZoomMenu(), false);
    5656  }
    5757
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/FinishedUploadDialog.java

    r31787 r31799  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
    9 import java.net.MalformedURLException;
     9import java.io.IOException;
    1010import java.net.URL;
    1111
     
    4949      try {
    5050        MapillaryUtils.browse(new URL("http://www.mapillary.com/map/upload/im"));
    51       } catch (MalformedURLException e1) {
     51      } catch (IOException e1) {
    5252        Main.error(e1);
    5353      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31787 r31799  
    1212import java.awt.event.ActionListener;
    1313import java.awt.event.MouseEvent;
     14import java.io.IOException;
    1415import java.net.MalformedURLException;
    1516import java.net.URL;
     
    161162      public void actionPerformed(ActionEvent arg0) {
    162163        try {
    163           MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/"
    164               + HyperlinkLabel.this.key));
    165         } catch (MalformedURLException e) {
     164          MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/" + HyperlinkLabel.this.key));
     165        } catch (IOException e) {
    166166          Main.error(e);
    167167        }
     
    211211    if (this.url == null)
    212212      return;
    213     MapillaryUtils.browse(this.url);
     213    try {
     214      MapillaryUtils.browse(this.url);
     215    } catch (IOException e1) {
     216      Main.error(e1);
     217    }
    214218  }
    215219}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31797 r31799  
    439439      putValue(SHORT_DESCRIPTION, tr("Stops the walk."));
    440440      putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryStop.png"));
    441       MapillaryPlugin.walkAction.addListener(this);
     441      MapillaryPlugin.getWalkAction().addListener(this);
    442442    }
    443443
     
    457457
    458458    private static final long serialVersionUID = -17943404752082788L;
    459     private WalkThread thread;
     459    private transient WalkThread thread;
    460460
    461461    public PlayAction() {
     
    463463      putValue(SHORT_DESCRIPTION, tr("Continues with the paused walk."));
    464464      putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryPlay.png"));
    465       MapillaryPlugin.walkAction.addListener(this);
     465      MapillaryPlugin.getWalkAction().addListener(this);
    466466    }
    467467
     
    489489      putValue(SHORT_DESCRIPTION, tr("Pauses the walk."));
    490490      putValue(SMALL_ICON, ImageProvider.get("dialogs/mapillaryPause.png"));
    491       MapillaryPlugin.walkAction.addListener(this);
     491      MapillaryPlugin.getWalkAction().addListener(this);
    492492    }
    493493
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryPreferenceSetting.java

    r31796 r31799  
    66import java.awt.FlowLayout;
    77import java.awt.event.ActionEvent;
    8 import java.net.MalformedURLException;
     8import java.io.IOException;
    99import java.net.URL;
    1010
     
    9999        .put("mapillary.reverse-buttons", this.reverseButtons.isSelected());
    100100
    101     MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, false);
     101    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), false);
    102102    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Automatic.toString()))
    103103      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Automatic.toString());
     
    106106    if (this.downloadMode.getSelectedItem().equals(MapillaryDownloader.MODES.Manual.toString())) {
    107107      Main.pref.put("mapillary.download-mode", MapillaryDownloader.MODES.Manual.toString());
    108       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
     108      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), true);
    109109    }
    110110    Main.pref.put("mapillary.display-hour", this.displayHour.isSelected());
     
    133133      OAuthPortListener portListener = new OAuthPortListener();
    134134      portListener.start();
    135       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";
     135      String url = "http://www.mapillary.com/connect?redirect_uri=http:%2F%2Flocalhost:8763%2F&client_id="+MapillaryPlugin.CLIENT_ID+"&response_type=token&scope=user:read%20public:upload%20public:write";
    136136      try {
    137137        MapillaryUtils.browse(new URL(url));
    138       } catch (MalformedURLException e) {
     138      } catch (IOException e) {
    139139        Main.error(e);
    140140      }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillaryDownloader.java

    r31797 r31799  
    4040  /** Base URL of the Mapillary API. */
    4141  public static final String BASE_URL = "https://a.mapillary.com/v2/";
    42   /** Client ID for the app */
    43   public static final String CLIENT_ID = "T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz";
    4442  /** Executor that will run the petitions. */
    4543  private static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(3, 5,
     
    179177  public static MapillaryDownloader.MODES getMode() {
    180178    if (Main.pref.get("mapillary.download-mode").equals(MODES.Automatic.toString())
    181         && (!MapillaryLayer.hasInstance() || !MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC))
     179        && (!MapillaryLayer.hasInstance() || !MapillaryLayer.getInstance().tempSemiautomatic))
    182180      return MODES.Automatic;
    183181    else if (Main.pref.get("mapillary.download-mode").equals(MODES.Semiautomatic.toString())
    184         || (MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC))
     182        || (MapillaryLayer.hasInstance() && MapillaryLayer.getInstance().tempSemiautomatic))
    185183      return MODES.Semiautomatic;
    186184    else if (Main.pref.get("mapillary.download-mode").equals(MODES.Manual.toString()))
     
    201199      });
    202200    } else {
    203       MapillaryLayer.getInstance().TEMP_SEMIAUTOMATIC = true;
    204       MapillaryPlugin.setMenuEnabled(MapillaryPlugin.DOWNLOAD_VIEW_MENU, true);
     201      MapillaryLayer.getInstance().tempSemiautomatic = true;
     202      MapillaryPlugin.setMenuEnabled(MapillaryPlugin.getDownloadViewMenu(), true);
    205203      JOptionPane
    206204          .showMessageDialog(
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySquareDownloadManagerThread.java

    r31787 r31799  
    55import java.net.URLEncoder;
    66import java.util.Locale;
     7import java.util.Map.Entry;
    78import java.util.concurrent.ArrayBlockingQueue;
    8 import java.util.concurrent.ConcurrentHashMap;
     9import java.util.concurrent.ConcurrentMap;
    910import java.util.concurrent.ThreadPoolExecutor;
    1011import java.util.concurrent.TimeUnit;
     
    1213import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     15import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1416import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    1517import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     
    4951   *
    5052   */
    51   public MapillarySquareDownloadManagerThread(
    52       ConcurrentHashMap<String, Double> queryStringParts) {
     53  public MapillarySquareDownloadManagerThread(ConcurrentMap<String, Double> queryStringParts) {
    5354    this.imageQueryString = buildQueryString(queryStringParts);
    5455    this.sequenceQueryString = buildQueryString(queryStringParts);
     
    6061
    6162  // TODO: Maybe move into a separate utility class?
    62   private static String buildQueryString(ConcurrentHashMap<String, Double> hash) {
    63     StringBuilder ret = new StringBuilder("?client_id="
    64         + MapillaryDownloader.CLIENT_ID);
    65     for (String key : hash.keySet())
    66       if (key != null)
     63  private static String buildQueryString(ConcurrentMap<String, Double> hash) {
     64    StringBuilder ret = new StringBuilder().append("?client_id=").append(MapillaryPlugin.CLIENT_ID);
     65    for (Entry<String, Double> entry : hash.entrySet())
     66      if (entry.getKey() != null)
    6767        try {
    68           ret.append("&" + URLEncoder.encode(key, "UTF-8")).append(
    69               "="
    70                   + URLEncoder.encode(
    71                       String.format(Locale.UK, "%f", hash.get(key)), "UTF-8"));
     68          ret.append('&')
     69            .append(URLEncoder.encode(entry.getKey(), "UTF-8"))
     70            .append('=')
     71            .append(URLEncoder.encode(String.format(Locale.UK, "%f", entry.getValue()), "UTF-8"));
    7272        } catch (UnsupportedEncodingException e) {
    7373          // This should not happen, as the encoding is hard-coded
     
    106106    while (!this.downloadExecutor.isShutdown()) {
    107107      this.downloadExecutor.execute(new MapillarySequenceDownloadThread(
    108           this.downloadExecutor, this.sequenceQueryString + "&page=" + page
    109               + "&limit=10"));
     108          this.downloadExecutor, this.sequenceQueryString + "&page=" + page + "&limit=10"));
    110109      while (this.downloadExecutor.getQueue().remainingCapacity() == 0)
    111110        Thread.sleep(500);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java

    r31787 r31799  
    55import java.net.URL;
    66import java.util.HashMap;
     7import java.util.Map;
    78
    89import org.openstreetmap.josm.Main;
     10import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    911
    1012/**
     
    1719
    1820  private static String username;
    19   private static String images_policy;
    20   private static String images_hash;
     21  private static String imagesPolicy;
     22  private static String imagesHash;
    2123  /** If the stored token is valid or not. */
    2224  public static boolean isTokenValid = true;
     
    3537            .getWithHeader(
    3638                new URL(
    37                     "https://a.mapillary.com/v2/me?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))
     39                    "https://a.mapillary.com/v2/me?client_id="+MapillaryPlugin.CLIENT_ID))
    3840            .getString("username");
    3941      } catch (IOException e) {
     
    4850   *         strings.
    4951   */
    50   public static HashMap<String, String> getSecrets() {
     52  public static Map<String, String> getSecrets() {
    5153    if (!isTokenValid)
    5254      return null;
    53     HashMap<String, String> hash = new HashMap<>();
     55    Map<String, String> hash = new HashMap<>();
    5456    try {
    55       if (images_hash == null)
    56         images_hash = OAuthUtils
     57      if (imagesHash == null)
     58        imagesHash = OAuthUtils
    5759            .getWithHeader(
    5860                new URL(
    59                     "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))
     61                    "https://a.mapillary.com/v2/me/uploads/secrets?client_id="+MapillaryPlugin.CLIENT_ID))
    6062            .getString("images_hash");
    61       hash.put("images_hash", images_hash);
    62       if (images_policy == null)
    63         images_policy = OAuthUtils
     63      hash.put("images_hash", imagesHash);
     64      if (imagesPolicy == null)
     65        imagesPolicy = OAuthUtils
    6466            .getWithHeader(
    6567                new URL(
    66                     "https://a.mapillary.com/v2/me/uploads/secrets?client_id=T1Fzd20xZjdtR0s1VDk5OFNIOXpYdzoxNDYyOGRkYzUyYTFiMzgz"))
     68                    "https://a.mapillary.com/v2/me/uploads/secrets?client_id="+MapillaryPlugin.CLIENT_ID))
    6769            .getString("images_policy");
    6870    } catch (IOException e) {
     
    7072      reset();
    7173    }
    72     hash.put("images_policy", images_policy);
     74    hash.put("images_policy", imagesPolicy);
    7375    return hash;
    7476  }
     
    7981  public static void reset() {
    8082    username = null;
    81     images_policy = null;
    82     images_hash = null;
     83    imagesPolicy = null;
     84    imagesHash = null;
    8385    isTokenValid = false;
    8486    Main.pref.put("mapillary.access-token", null);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/traffico/TrafficoSign.java

    r31795 r31799  
    1515
    1616public final class TrafficoSign {
     17  private static Map<String, Map<String, TrafficoSignElement[]>> signs = new HashMap<>();
     18
    1719  private TrafficoSign() {
    1820    // private constructor to avoid instantiation
    1921  }
    20 
    21   private static Map<String, Map<String, TrafficoSignElement[]>> signs = new HashMap<>();
    2222
    2323  public static TrafficoSignElement[] getSign(String country, String signName) {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31797 r31799  
    4141 *
    4242 */
    43 public class MapillaryUtils {
    44 
    45   private static double MIN_ZOOM_SQUARE_SIDE = 0.002;
     43public final class MapillaryUtils {
     44
     45  private static final double MIN_ZOOM_SQUARE_SIDE = 0.002;
     46
     47  private MapillaryUtils() {
     48    // Private constructor to avoid instantiation
     49  }
    4650
    4751  /**
    4852   * Open the default browser in the given URL.
    4953   *
    50    * @param url
    51    *          The URL that is going to be opened.
    52    */
    53   public static void browse(URL url) {
     54   * @param url The (not-null) URL that is going to be opened.
     55   * @throws IOException when the URL could not be opened
     56   */
     57  public static void browse(URL url) throws IOException {
     58    if (url == null) {
     59      throw new IllegalArgumentException();
     60    }
    5461    Desktop desktop = Desktop.getDesktop();
    5562    if (desktop.isSupported(Desktop.Action.BROWSE)) {
    5663      try {
    5764        desktop.browse(url.toURI());
    58       } catch (IOException | URISyntaxException e1) {
    59         Main.error(e1);
     65      } catch (URISyntaxException e1) {
     66        throw new IOException(e1);
    6067      }
    6168    } else {
    6269      Runtime runtime = Runtime.getRuntime();
    63       try {
    64         runtime.exec("xdg-open " + url);
    65       } catch (IOException exc) {
    66         exc.printStackTrace();
    67       }
     70      runtime.exec("xdg-open " + url);
    6871    }
    6972  }
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/io/download/MapillarySequenceDownloadThreadTest.java

    r31797 r31799  
    1515import org.openstreetmap.josm.plugins.mapillary.AbstractTest;
    1616import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
     17import org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin;
    1718import org.openstreetmap.josm.plugins.mapillary.io.download.MapillaryDownloader;
    1819import org.openstreetmap.josm.plugins.mapillary.io.download.MapillarySequenceDownloadThread;
     
    4748            "?max_lat=%.8f&max_lon=%.8f&min_lat=%.8f&min_lon=%.8f&limit=10&client_id=%s",
    4849            maxLatLon.lat(), maxLatLon.lon(), minLatLon.lat(), minLatLon.lon(),
    49             MapillaryDownloader.CLIENT_ID);
     50            MapillaryPlugin.CLIENT_ID);
    5051    MapillaryLayer.getInstance().getData().bounds.add(new Bounds(minLatLon,
    5152        maxLatLon));
  • applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtilsTest.java

    r31460 r31799  
    1515 */
    1616public class MapillaryUtilsTest {
     17
     18  @Test
     19  public void testUtilityClass() {
     20    TestUtil.testUtilityClass(MapillaryUtils.class);
     21  }
    1722
    1823  /**
Note: See TracChangeset for help on using the changeset viewer.