Ignore:
Timestamp:
2016-07-06T15:40:30+02:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Fix NPE when shift dragging an image

Fixes #10.

File:
1 edited

Legend:

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

    r32572 r32589  
    99import java.awt.event.MouseEvent;
    1010import java.util.concurrent.ConcurrentSkipListSet;
     11
     12import javax.swing.SwingUtilities;
    1113
    1214import org.openstreetmap.josm.Main;
     
    3234public class SelectMode extends AbstractMode {
    3335  private Point start;
    34   private int lastButton;
    3536  private MapillaryAbstractImage closest;
    3637  private MapillaryAbstractImage lastClicked;
     
    4849  @Override
    4950  public void mousePressed(MouseEvent e) {
    50     this.lastButton = e.getButton();
    5151    if (e.getButton() != MouseEvent.BUTTON1) {
    5252      return;
     
    9999  @Override
    100100  public void mouseDragged(MouseEvent e) {
    101     if (Main.getLayerManager().getActiveLayer() != MapillaryLayer.getInstance()) {
    102       return;
    103     }
    104 
    105     if (!Main.pref.getBoolean("mapillary.developer")) {
    106       for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    107         if (img instanceof MapillaryImage) {
    108           return;
     101    MapillaryAbstractImage highlightImg = data.getHighlightedImage();
     102    if (
     103      Main.getLayerManager().getActiveLayer() == MapillaryLayer.getInstance()
     104      && SwingUtilities.isLeftMouseButton(e)
     105      && highlightImg != null && highlightImg.getLatLon() != null
     106    ) {
     107      Point highlightImgPoint = Main.map.mapView.getPoint(highlightImg.getTempLatLon());
     108      if (e.isShiftDown()) { // turn
     109        for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
     110          if (Main.pref.getBoolean("mapillary.developer") || !(img instanceof MapillaryImage)) {
     111            img.turn(Math.toDegrees(Math.atan2((e.getX() - highlightImgPoint.getX()), -(e.getY() - highlightImgPoint.getY()))) - highlightImg.getTempCa());
     112          }
    109113        }
    110       }
    111     }
    112     if (this.data.getSelectedImage() != null) {
    113       if (this.lastButton == MouseEvent.BUTTON1 && !e.isShiftDown()) {
    114         LatLon to = Main.map.mapView.getLatLon(e.getX(), e.getY());
    115         LatLon from = Main.map.mapView.getLatLon(this.start.getX(), this.start.getY());
     114      } else { // move
    116115        for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    117           img.move(to.getX() - from.getX(), to.getY() - from.getY());
     116          if (Main.pref.getBoolean("mapillary.developer") || !(img instanceof MapillaryImage)) {
     117            LatLon eventLatLon = Main.map.mapView.getLatLon(e.getX(), e.getY());
     118            LatLon imgLatLon = Main.map.mapView.getLatLon(highlightImgPoint.getX(), highlightImgPoint.getY());
     119            img.move(eventLatLon.getX() - imgLatLon.getX(), eventLatLon.getY() - imgLatLon.getY());
     120          }
    118121        }
    119         Main.map.repaint();
    120       } else if (this.lastButton == MouseEvent.BUTTON1 && e.isShiftDown()) {
    121         this.closest.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x),
    122                 -(e.getY() - this.start.y)))
    123                 - this.closest.getTempCa());
    124         for (MapillaryAbstractImage img : this.data.getMultiSelectedImages()) {
    125           img.turn(Math.toDegrees(Math.atan2((e.getX() - this.start.x),
    126                   -(e.getY() - this.start.y))) - this.closest.getTempCa());
    127         }
    128         Main.map.repaint();
    129       }
     122      }
     123      Main.map.repaint();
    130124    }
    131125  }
Note: See TracChangeset for help on using the changeset viewer.