Changeset 31815 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-12-12T14:35:46+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix issues reported by static code analysis

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

Legend:

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

    r31799 r31815  
    187187   * @return A List object containing all images.
    188188   */
    189   public List<MapillaryAbstractImage> getImages() {
     189  public synchronized List<MapillaryAbstractImage> getImages() {
    190190    return this.images;
    191191  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31812 r31815  
    5959
    6060  /** Cache that stores the pictures the downloaded pictures. */
    61   public static CacheAccess<String, BufferedImageCacheEntry> CACHE;
     61  public static CacheAccess<String, BufferedImageCacheEntry> cache;
    6262
    6363  private static final MapillaryDownloadAction downloadAction = new MapillaryDownloadAction();
     
    125125
    126126    try {
    127       CACHE = JCSCacheManager.getCache("mapillary", 10, 10000, this.getPluginDir() + "/cache/");
     127      cache = JCSCacheManager.getCache("mapillary", 10, 10000, this.getPluginDir() + "/cache/");
    128128    } catch (IOException e) {
    129129      Main.error(e);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillarySequence.java

    r31787 r31815  
    1818  private String key;
    1919  /** Epoch time when the sequence was created */
    20   private long created_at;
     20  private long createdAt;
    2121
    2222  /**
     
    3333   * @param key
    3434   *          The unique identifier of the sequence.
    35    * @param created_at
     35   * @param createdAt
    3636   *          The date the sequence was created.
    3737   */
    38   public MapillarySequence(String key, long created_at) {
     38  public MapillarySequence(String key, long createdAt) {
    3939    this.images = new ArrayList<>();
    4040    this.key = key;
    41     this.created_at = created_at;
     41    this.createdAt = createdAt;
    4242  }
    4343
     
    6161   */
    6262  public long getCreatedAt() {
    63     return this.created_at;
     63    return this.createdAt;
    6464  }
    6565
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/cache/MapillaryCache.java

    r31797 r31815  
    4444   */
    4545  public MapillaryCache(String key, Type type) {
    46     super(MapillaryPlugin.CACHE, 50000, 50000, new HashMap<String, String>());
     46    super(MapillaryPlugin.cache, 50000, 50000, new HashMap<String, String>());
    4747    String k = null;
    4848    URL u = null;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/HyperlinkLabel.java

    r31811 r31815  
    77import java.awt.Cursor;
    88import java.awt.Toolkit;
    9 import java.awt.datatransfer.Clipboard;
    109import java.awt.datatransfer.StringSelection;
    1110import java.awt.event.ActionEvent;
     
    2221
    2322import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
    2523import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    2624
     
    5452  @Override
    5553  public void setText(String text) {
    56     super
    57         .setText("<html><font color=\"#0000CF\" size=\"2\">" + text + "</font></html>"); //$NON-NLS-1$ //$NON-NLS-2$
     54    super.setText("<html><a style=\"color:#0000CF;font-size:8px\">" + text + "</a></html>"); //$NON-NLS-1$ //$NON-NLS-2$
    5855    this.text = text;
    5956  }
     
    6461   * @param key
    6562   *          The key of the image that the hyperlink will point to.
     63   * @throws MalformedURLException
    6664   */
    67   public void setURL(String key) {
     65  public void setURL(String key) throws MalformedURLException {
    6866    this.key = key;
    6967    if (key == null) {
     
    7169      return;
    7270    }
    73     try {
    74       this.url = new URL("http://www.mapillary.com/map/im/" + key);
    75     } catch (MalformedURLException e) {
    76       Main.error(e);
    77     }
     71    this.url = new URL("http://www.mapillary.com/map/im/" + key);
    7872  }
    7973
     
    9892            getNormalText()));
    9993      if (e.getButton() == MouseEvent.BUTTON3) {
    100         LinkPopUp menu = new LinkPopUp();
     94        LinkPopUp menu = new LinkPopUp(key);
    10195        menu.show(e.getComponent(), e.getX(), e.getY());
    10296      }
     
    118112    private final JMenuItem edit;
    119113
    120     public LinkPopUp() {
     114    public LinkPopUp(final String key) {
    121115      this.copy = new JMenuItem(tr("Copy key"));
    122       this.copy.addActionListener(new copyAction());
     116      this.copy.addActionListener(new ActionListener() {
     117        @Override
     118        public void actionPerformed(ActionEvent paramActionEvent) {
     119          Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(key), null);
     120        }
     121      });
    123122      add(this.copy);
    124123
    125124      this.copyTag = new JMenuItem(tr("Copy key tag"));
    126       this.copyTag.addActionListener(new copyTagAction());
     125      this.copyTag.addActionListener(new ActionListener() {
     126        @Override
     127        public void actionPerformed(ActionEvent paramActionEvent) {
     128          Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection("mapillary=" + key), null);
     129        }
     130      });
    127131      add(this.copyTag);
    128132
    129133      this.edit = new JMenuItem(tr("Edit on website"));
    130       this.edit.addActionListener(new editAction());
     134      this.edit.addActionListener(new ActionListener() {
     135        @Override
     136        public void actionPerformed(ActionEvent paramActionEvent) {
     137          try {
     138            MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/" + key));
     139          } catch (IOException e) {
     140            Main.error(e);
     141          }
     142        }
     143      });
    131144      add(this.edit);
    132     }
    133 
    134     private class copyAction implements ActionListener {
    135 
    136       @Override
    137       public void actionPerformed(ActionEvent arg0) {
    138         StringSelection stringSelection = new StringSelection(
    139             ((MapillaryImage) MapillaryMainDialog.getInstance().getImage())
    140                 .getKey());
    141         Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    142         clpbrd.setContents(stringSelection, null);
    143       }
    144     }
    145 
    146     private class copyTagAction implements ActionListener {
    147 
    148       @Override
    149       public void actionPerformed(ActionEvent arg0) {
    150         StringSelection stringSelection = new StringSelection(
    151             "mapillary="
    152                 + ((MapillaryImage) MapillaryMainDialog.getInstance()
    153                     .getImage()).getKey());
    154         Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
    155         clpbrd.setContents(stringSelection, null);
    156       }
    157     }
    158 
    159     private class editAction implements ActionListener {
    160 
    161       @Override
    162       public void actionPerformed(ActionEvent arg0) {
    163         try {
    164           MapillaryUtils.browse(new URL("http://www.mapillary.com/map/e/" + HyperlinkLabel.this.key));
    165         } catch (IOException e) {
    166           Main.error(e);
    167         }
    168       }
    169145    }
    170146  }
     
    201177    for (int i = 0; i < listeners.length; i += 2) {
    202178      if (listeners[i] == ActionListener.class) {
    203         ActionListener listener = (ActionListener) listeners[i + 1];
    204         listener.actionPerformed(evt);
     179        ((ActionListener) listeners[i + 1]).actionPerformed(evt);
    205180      }
    206181    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryImageDisplay.java

    r31797 r31815  
    4444
    4545  /** The image currently displayed */
    46   private transient BufferedImage image = null;
     46  private transient BufferedImage image;
    4747
    4848  /**
     
    5050   * rectangle is calculated each time the zoom is modified
    5151   */
    52   private Rectangle visibleRect = null;
     52  private Rectangle visibleRect;
    5353
    5454  /**
     
    5656   * coordinates)
    5757   */
    58   private Rectangle selectedRect = null;
     58  private Rectangle selectedRect;
    5959
    6060  /** HyperlinkLabel shown in the bottom right corner. */
     
    6363  private class ImgDisplayMouseListener implements MouseListener,
    6464      MouseWheelListener, MouseMotionListener {
    65     private boolean mouseIsDragging = false;
    66     private long lastTimeForMousePoint = 0L;
    67     private Point mousePointInImg = null;
     65    private boolean mouseIsDragging;
     66    private long lastTimeForMousePoint;
     67    private Point mousePointInImg;
    6868
    6969    /**
     
    302302    @Override
    303303    public void mouseEntered(MouseEvent e) {
     304      // Do nothing, method is enforced by MouseListener
    304305    }
    305306
    306307    @Override
    307308    public void mouseExited(MouseEvent e) {
     309      // Do nothing, method is enforced by MouseListener
    308310    }
    309311
    310312    @Override
    311313    public void mouseMoved(MouseEvent e) {
     314      // Do nothing, method is enforced by MouseListener
    312315    }
    313316
     
    449452   * @return the part of compRect with the same width/height ratio as the image
    450453   */
    451   static Rectangle calculateDrawImageRectangle(Rectangle imgRect,
    452       Rectangle compRect) {
    453     int x, y, w, h;
    454     x = 0;
    455     y = 0;
    456     w = compRect.width;
    457     h = compRect.height;
     454  static Rectangle calculateDrawImageRectangle(Rectangle imgRect, Rectangle compRect) {
     455    int x = 0;
     456    int y = 0;
     457    int w = compRect.width;
     458    int h = compRect.height;
    458459    int wFact = w * imgRect.height;
    459460    int hFact = h * imgRect.width;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryMainDialog.java

    r31799 r31815  
    1515import java.io.ByteArrayInputStream;
    1616import java.io.IOException;
     17import java.net.MalformedURLException;
    1718import java.util.Arrays;
    1819import java.util.List;
     
    106107    createLayout(
    107108        this.mapillaryImageDisplay,
    108         Arrays.asList(new SideButton[] { this.blueButton, this.previousButton,
    109             this.nextButton, this.redButton }),
     109        Arrays.asList(new SideButton[] {this.blueButton, this.previousButton, this.nextButton, this.redButton}),
    110110        Main.pref.getBoolean("mapillary.reverse-buttons"));
    111111    disableAllButtons();
     
    137137   * @return The unique instance of the class.
    138138   */
    139   public static MapillaryMainDialog getInstance() {
     139  public static synchronized MapillaryMainDialog getInstance() {
    140140    if (instance == null)
    141141      instance = new MapillaryMainDialog();
     
    154154        createLayout(
    155155            this.mapillaryImageDisplay,
    156             Arrays.asList(new SideButton[] { playButton, pauseButton, stopButton }),
     156            Arrays.asList(new SideButton[] {playButton, pauseButton, stopButton}),
    157157            Main.pref.getBoolean("mapillary.reverse-buttons"));
    158158        break;
     
    161161        createLayout(
    162162            this.mapillaryImageDisplay,
    163             Arrays.asList(new SideButton[] { blueButton, previousButton, nextButton, redButton }),
     163            Arrays.asList(new SideButton[] {blueButton, previousButton, nextButton, redButton}),
    164164            Main.pref.getBoolean("mapillary.reverse-buttons"));
    165165        break;
     
    238238        this.mapillaryImageDisplay.hyperlink.setVisible(true);
    239239        MapillaryImage mapillaryImage = (MapillaryImage) this.image;
    240         this.mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
     240        try {
     241          this.mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
     242        } catch (MalformedURLException e1) {
     243          Main.error(e1);
     244        }
    241245        // Downloads the thumbnail.
    242246        this.mapillaryImageDisplay.setImage(null);
     
    265269      } else if (this.image instanceof MapillaryImportedImage) {
    266270        this.mapillaryImageDisplay.hyperlink.setVisible(false);
    267         this.mapillaryImageDisplay.hyperlink.setURL(null);
     271        try {
     272          this.mapillaryImageDisplay.hyperlink.setURL(null);
     273        } catch (MalformedURLException e1) {
     274          Main.error(e1);
     275        }
    268276        MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image;
    269277        try {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java

    r31811 r31815  
    33
    44import java.util.ArrayList;
    5 import java.util.List;
    65
    76import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
Note: See TracChangeset for help on using the changeset viewer.