Changeset 31983 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-01-13T16:35:59+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Simplify paint() in MapillaryLayer

Parts of the paint()-method are now in a new utility-class, which reduces complexity of paint() and allows for easier unit testing of that part.
Some code style improvements are also bundled in this commit.

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

Legend:

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

    r31972 r31983  
    196196  /**
    197197   * If the MapillaryImage belongs to a MapillarySequence, returns the next
    198    * MapillarySequence in it.
     198   * image in the sequence.
    199199   *
    200200   * @return The following MapillaryImage, or null if there is none.
     
    210210  /**
    211211   * If the MapillaryImage belongs to a MapillarySequence, returns the previous
    212    * MapillarySequence in it.
     212   * image in the sequence.
    213213   *
    214214   * @return The previous MapillaryImage, or null if there is none.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

    r31974 r31983  
    33
    44import java.util.Collections;
     5import java.util.HashSet;
    56import java.util.List;
    67import java.util.Set;
     
    219220
    220221  /**
    221    * Returns a List containing all images.
    222    *
    223    * @return A List object containing all images.
     222   * Returns a Set containing all images.
     223   *
     224   * @return A Set object containing all images.
    224225   */
    225226  public synchronized Set<MapillaryAbstractImage> getImages() {
    226227    return this.images;
     228  }
     229
     230  /**
     231   * Returns a Set of all sequences, that the images are part of.
     232   * @return
     233   */
     234  public synchronized Set<MapillarySequence> getSequences() {
     235    Set<MapillarySequence> result = new HashSet<>();
     236    for (MapillaryAbstractImage img : getImages()) {
     237      result.add(img.getSequence());
     238    }
     239    return result;
    227240  }
    228241
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java

    r31974 r31983  
    66
    77import java.awt.AlphaComposite;
     8import java.awt.BasicStroke;
    89import java.awt.Color;
    910import java.awt.Composite;
     
    1213import java.awt.Point;
    1314import java.awt.Rectangle;
     15import java.awt.RenderingHints;
     16import java.awt.Shape;
    1417import java.awt.TexturePaint;
    1518import java.awt.event.ActionEvent;
    1619import java.awt.geom.AffineTransform;
    17 import java.awt.geom.Area;
     20import java.awt.geom.Line2D;
    1821import java.awt.image.AffineTransformOp;
    1922import java.awt.image.BufferedImage;
     
    5962import org.openstreetmap.josm.plugins.mapillary.mode.JoinMode;
    6063import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
     64import org.openstreetmap.josm.plugins.mapillary.utils.MapViewGeometryUtil;
    6165import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils;
    6266
     
    230234  @Override
    231235  public boolean isModified() {
    232     for (MapillaryAbstractImage image : this.data.getImages())
     236    for (MapillaryAbstractImage image : this.data.getImages()) {
    233237      if (image.isModified())
    234238        return true;
     239    }
    235240    return false;
    236241  }
     
    280285
    281286  @Override
    282   public synchronized void paint(Graphics2D g, MapView mv, Bounds box) {
     287  public synchronized void paint(final Graphics2D g, final MapView mv, final Bounds box) {
     288    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    283289    if (Main.map.mapView.getActiveLayer() == this) {
    284       Rectangle b = mv.getBounds();
    285       // on some platforms viewport bounds seem to be offset from the left,
    286       // over-grow it just to be sure
    287       b.grow(100, 100);
    288       Area a = new Area(b);
    289       // now successively subtract downloaded areas
    290       for (Bounds bounds : this.data.bounds) {
    291         Point p1 = mv.getPoint(bounds.getMin());
    292         Point p2 = mv.getPoint(bounds.getMax());
    293         Rectangle r = new Rectangle(Math.min(p1.x, p2.x), Math.min(p1.y, p2.y),
    294             Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
    295         a.subtract(new Area(r));
    296       }
    297290      // paint remainder
    298291      g.setPaint(this.hatched);
    299       g.fill(a);
     292      g.fill(MapViewGeometryUtil.getNonDownloadedArea(mv, this.data.bounds));
    300293    }
    301294
    302295    // Draw colored lines
     296    MapillaryMainDialog.getInstance().blueButton.setEnabled(false);
     297    MapillaryMainDialog.getInstance().redButton.setEnabled(false);
    303298    blue = null;
    304299    red = null;
    305     MapillaryMainDialog.getInstance().blueButton.setEnabled(false);
    306     MapillaryMainDialog.getInstance().redButton.setEnabled(false);
    307 
    308     // Sets blue and red lines and enables/disables the buttons
     300
     301    // Draw the blue and red line and enable/disable the buttons
    309302    if (this.data.getSelectedImage() != null) {
    310303      MapillaryImage[] closestImages = getClosestImagesFromDifferentSequences();
     
    313306        blue = closestImages[0];
    314307        g.setColor(Color.BLUE);
    315         g.drawLine(mv.getPoint(closestImages[0].getLatLon()).x,
    316             mv.getPoint(closestImages[0].getLatLon()).y, selected.x, selected.y);
     308        final Point p = mv.getPoint(closestImages[0].getLatLon());
     309        g.draw(new Line2D.Double(p.getX(), p.getY(), selected.getX(), selected.getY()));
    317310        MapillaryMainDialog.getInstance().blueButton.setEnabled(true);
    318311      }
     
    320313        red = closestImages[1];
    321314        g.setColor(Color.RED);
    322         g.drawLine(mv.getPoint(closestImages[1].getLatLon()).x,
    323             mv.getPoint(closestImages[1].getLatLon()).y, selected.x, selected.y);
     315        final Point p = mv.getPoint(closestImages[1].getLatLon());
     316        g.draw(new Line2D.Double(p.getX(), p.getY(), selected.getX(), selected.getY()));
    324317        MapillaryMainDialog.getInstance().redButton.setEnabled(true);
    325318      }
    326319    }
     320    // Draw sequence line
    327321    g.setColor(Color.WHITE);
     322    g.setStroke(new BasicStroke(this == Main.map.mapView.getActiveLayer() ? 3 : 1));
     323    for (MapillarySequence seq : getData().getSequences()) {
     324      g.draw(MapViewGeometryUtil.getSequencePath(mv, seq));
     325    }
    328326    for (MapillaryAbstractImage imageAbs : this.data.getImages()) {
    329       if (!imageAbs.isVisible())
    330         continue;
    331       Point p = mv.getPoint(imageAbs.getLatLon());
    332       Point nextp = null;
    333       // Draw sequence line
    334       if (imageAbs.getSequence() != null) {
    335         MapillaryAbstractImage tempImage = imageAbs.next();
    336         while (tempImage != null) {
    337           if (tempImage.isVisible()) {
    338             nextp = mv.getPoint(tempImage.getLatLon());
    339             break;
    340           }
    341           tempImage = tempImage.next();
     327      if (imageAbs.isVisible()) {
     328        final Point p = mv.getPoint(imageAbs.getLatLon());
     329        if (getData().getMultiSelectedImages().contains(imageAbs)) {
     330          draw(g, imageAbs, MapillaryPlugin.MAP_ICON_SELECTED, p);
     331        } else {
     332          draw(g, imageAbs, imageAbs instanceof MapillaryImage ? MapillaryPlugin.MAP_ICON : MapillaryPlugin.MAP_ICON_IMPORTED, p);
    342333        }
    343         if (nextp != null)
    344           g.drawLine(p.x, p.y, nextp.x, nextp.y);
    345       }
    346       // Draws icons
    347       if (imageAbs instanceof MapillaryImage) {
    348         MapillaryImage image = (MapillaryImage) imageAbs;
    349         ImageIcon icon;
    350         icon = this.data.getMultiSelectedImages().contains(image) ? MapillaryPlugin.MAP_ICON_SELECTED : MapillaryPlugin.MAP_ICON;
    351         draw(g, image, icon, p);
    352         if (!image.getSigns().isEmpty()) {
    353           g.drawImage(MapillaryPlugin.MAP_SIGN.getImage(),
    354               p.x + icon.getIconWidth() / 2, p.y - icon.getIconHeight() / 2,
    355               Main.map.mapView);
     334        if (imageAbs instanceof MapillaryImage && !((MapillaryImage) imageAbs).getSigns().isEmpty()) {
     335          g.drawImage(
     336              MapillaryPlugin.MAP_SIGN.getImage(),
     337              p.x - MapillaryPlugin.MAP_SIGN.getIconWidth() / 2,
     338              p.y - MapillaryPlugin.MAP_SIGN.getIconHeight() / 2,
     339              Main.map.mapView
     340          );
    356341        }
    357       } else if (imageAbs instanceof MapillaryImportedImage) {
    358         MapillaryImportedImage image = (MapillaryImportedImage) imageAbs;
    359         ImageIcon icon = this.data.getMultiSelectedImages().contains(image)
    360             ? MapillaryPlugin.MAP_ICON_SELECTED
    361             : MapillaryPlugin.MAP_ICON_IMPORTED;
    362         draw(g, image, icon, p);
    363342      }
    364343    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryPlugin.java

    r31976 r31983  
    9797
    9898  static {
    99     if (Main.main != null) {
     99    if (Main.main == null) {
     100      exportMenu = null;
     101      downloadMenu = null;
     102      importMenu = null;
     103      zoomMenu = null;
     104      downloadViewMenu = null;
     105      importIntoSequenceMenu = null;
     106      joinMenu = null;
     107      walkMenu = null;
     108      uploadMenu = null;
     109    } else {
    100110      exportMenu = MainMenu.add(Main.main.menu.fileMenu, exportAction, false, 14);
    101111      exportMenu.setEnabled(false);
     
    116126      uploadMenu = MainMenu.add(Main.main.menu.fileMenu, uploadAction, false, 14);
    117127      uploadMenu.setEnabled(false);
    118     } else {
    119       exportMenu = null;
    120       downloadMenu = null;
    121       importMenu = null;
    122       zoomMenu = null;
    123       downloadViewMenu = null;
    124       importIntoSequenceMenu = null;
    125       joinMenu = null;
    126       walkMenu = null;
    127       uploadMenu = null;
    128128    }
    129129  }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31974 r31983  
    5656 */
    5757public class UploadUtils {
     58  /**
     59   * Required keys for POST
     60   */
     61  private static final String[] keys = {"key", "AWSAccessKeyId", "acl", "policy", "signature", "Content-Type"};
     62
     63  /**
     64   * Mapillary upload URL
     65   */
     66  private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
     67
     68  /**
     69   * Count to name temporal files.
     70   */
     71  private static int c;
    5872
    5973  private UploadUtils() {
    6074    // Private constructor to avoid instantiation.
    6175  }
    62 
    63   /**
    64    * Required keys for POST
    65    */
    66   private static final String[] keys = {"key", "AWSAccessKeyId", "acl",
    67           "policy", "signature", "Content-Type"};
    68 
    69   /**
    70    * Mapillary upload URL
    71    */
    72   private static final String UPLOAD_URL = "https://s3-eu-west-1.amazonaws.com/mapillary.uploads.manual.images";
    73 
    74   /**
    75    * Count to name temporal files.
    76    */
    77   private static int c;
    7876
    7977  private static class SequenceUploadThread extends Thread {
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31974 r31983  
    55
    66import java.awt.Desktop;
     7import java.awt.Point;
     8import java.awt.Rectangle;
     9import java.awt.geom.Area;
    710import java.io.File;
    811import java.io.IOException;
     
    1114import java.text.ParseException;
    1215import java.text.SimpleDateFormat;
    13 import java.util.*;
     16import java.util.ArrayList;
     17import java.util.Calendar;
     18import java.util.Locale;
     19import java.util.Set;
    1420
    1521import javax.swing.SwingUtilities;
     
    2632import org.openstreetmap.josm.data.Bounds;
    2733import org.openstreetmap.josm.data.coor.LatLon;
     34import org.openstreetmap.josm.gui.MapView;
    2835import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
    2936import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     
    129136      throw new IllegalArgumentException("Array's length must be 3.");
    130137    }
    131     for (int i = 0; i < 3; i++)
     138    for (int i = 0; i < 3; i++) {
    132139      if (degMinSec[i] == null)
    133140        throw new IllegalArgumentException("Null value in array.");
     141    }
    134142
    135143    switch (ref) {
Note: See TracChangeset for help on using the changeset viewer.