Changeset 31356 in osm for applications/editors


Ignore:
Timestamp:
2015-07-09T11:57:16+02:00 (9 years ago)
Author:
nokutu
Message:

Started working on map modes for MapillaryLayer. Atm I'm working with join mode, that allows the user to join images to make sequences.

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

Legend:

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

    r31355 r31356  
    1010import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog;
    1111import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
     12import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode;
    1213import org.openstreetmap.josm.Main;
    1314import org.openstreetmap.josm.gui.layer.Layer;
     
    7576  public ArrayList<Bounds> bounds;
    7677
    77   private MouseAdapter mouseAdapter;
     78  private MouseAdapter mode;
    7879
    7980  private int highlightPointRadius = Main.pref.getInteger(
     
    9495   */
    9596  private void init() {
    96     mouseAdapter = new MapillaryMouseAdapter();
     97    mode = new SelectMode();
    9798    try {
    9899      CACHE = JCSCacheManager.getCache("Mapillary");
     
    101102    }
    102103    if (Main.map != null && Main.map.mapView != null) {
    103       Main.map.mapView.addMouseListener(mouseAdapter);
    104       Main.map.mapView.addMouseMotionListener(mouseAdapter);
     104      Main.map.mapView.addMouseListener(mode);
     105      Main.map.mapView.addMouseMotionListener(mode);
    105106      Main.map.mapView.addLayer(this);
    106107      MapView.addEditLayerChangeListener(this, false);
     
    118119    createHatchTexture();
    119120    data.dataUpdated();
     121  }
     122 
     123  public void setMode(MouseAdapter mode) {
     124    Main.map.mapView.removeMouseListener(this.mode);
     125    Main.map.mapView.removeMouseMotionListener(this.mode);
     126    this.mode = mode;
     127    Main.map.mapView.addMouseListener(mode);
     128    Main.map.mapView.addMouseMotionListener(mode);
    120129  }
    121130
     
    186195    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false);
    187196    MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false);
    188     Main.map.mapView.removeMouseListener(mouseAdapter);
    189     Main.map.mapView.removeMouseMotionListener(mouseAdapter);
     197    Main.map.mapView.removeMouseListener(mode);
     198    Main.map.mapView.removeMouseMotionListener(mode);
    190199    MapView.removeEditLayerChangeListener(this);
    191200    if (Main.map.mapView.getEditLayer() != null)
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/mode/SelectMode.java

    r31355 r31356  
    1 package org.openstreetmap.josm.plugins.mapillary;
     1package org.openstreetmap.josm.plugins.mapillary.mode;
    22
    33import java.awt.Point;
    4 import java.awt.event.MouseAdapter;
    54import java.awt.event.MouseEvent;
    65import java.util.ArrayList;
     
    109import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1110import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     11import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage;
     12import org.openstreetmap.josm.plugins.mapillary.MapillaryData;
     13import org.openstreetmap.josm.plugins.mapillary.MapillaryImage;
     14import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;
     15import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer;
    1216import org.openstreetmap.josm.plugins.mapillary.commands.CommandMoveImage;
    1317import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage;
     
    2125 *
    2226 */
    23 public class MapillaryMouseAdapter extends MouseAdapter {
     27public class SelectMode extends AbstractMode {
    2428  private Point start;
    2529  private int lastButton;
    2630  private MapillaryAbstractImage closest;
    2731  private MapillaryAbstractImage lastClicked;
    28   private MapillaryData mapillaryData;
    2932  private MapillaryRecord record;
    3033
     
    3235  private boolean imageHighlighted = false;
    3336
    34   public MapillaryMouseAdapter() {
    35     mapillaryData = MapillaryData.getInstance();
     37  public SelectMode() {
     38    data = MapillaryData.getInstance();
    3639    record = MapillaryRecord.getInstance();
    3740  }
     
    5356      MapillaryImage closest = (MapillaryImage) closestTemp;
    5457      // Doube click
    55       if (e.getClickCount() == 2 && mapillaryData.getSelectedImage() != null && closest != null) {
     58      if (e.getClickCount() == 2 && data.getSelectedImage() != null && closest != null) {
    5659        for (MapillaryAbstractImage img : closest.getSequence().getImages()) {
    57           mapillaryData.addMultiSelectedImage(img);
     60          data.addMultiSelectedImage(img);
    5861        }
    5962      }
     
    6164      this.lastClicked = this.closest;
    6265      this.closest = closest;
    63       if (mapillaryData.getMultiSelectedImages().contains(closest))
     66      if (data.getMultiSelectedImages().contains(closest))
    6467        return;
    6568      // ctrl+click
    6669      if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) && closest != null)
    67         mapillaryData.addMultiSelectedImage(closest);
     70        data.addMultiSelectedImage(closest);
    6871      // shift + click
    6972      else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)
     
    7477          int j = ((MapillaryImage) this.lastClicked).getSequence().getImages().indexOf(this.lastClicked);
    7578          if (i < j)
    76             mapillaryData.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()
     79            data.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()
    7780                .getImages().subList(i, j + 1)));
    7881          else
    79             mapillaryData.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()
     82            data.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()
    8083                .getImages().subList(j, i + 1)));
    8184        }
    8285        // click
    8386      } else
    84         mapillaryData.setSelectedImage(closest);
     87        data.setSelectedImage(closest);
    8588      // If you select an imported image
    8689    } else if (closestTemp instanceof MapillaryImportedImage) {
     
    8992      this.lastClicked = this.closest;
    9093      this.closest = closest;
    91       if (mapillaryData.getMultiSelectedImages().contains(closest))
     94      if (data.getMultiSelectedImages().contains(closest))
    9295        return;
    9396      if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) && closest != null)
    94         mapillaryData.addMultiSelectedImage(closest);
     97        data.addMultiSelectedImage(closest);
    9598      else
    96         mapillaryData.setSelectedImage(closest);
     99        data.setSelectedImage(closest);
    97100    }
    98   }
    99 
    100   private MapillaryAbstractImage getClosest(Point clickPoint) {
    101     double snapDistance = 10;
    102     double minDistance = Double.MAX_VALUE;
    103     MapillaryAbstractImage closest = null;
    104     for (MapillaryAbstractImage image : mapillaryData.getImages()) {
    105       Point imagePoint = Main.map.mapView.getPoint(image.getLatLon());
    106       imagePoint.setLocation(imagePoint.getX(), imagePoint.getY());
    107       double dist = clickPoint.distanceSq(imagePoint);
    108       if (minDistance > dist && clickPoint.distance(imagePoint) < snapDistance && image.isVisible()) {
    109         minDistance = dist;
    110         closest = image;
    111       }
    112     }
    113     return closest;
    114101  }
    115102
     
    146133  @Override
    147134  public void mouseReleased(MouseEvent e) {
    148     if (mapillaryData.getSelectedImage() == null)
     135    if (data.getSelectedImage() == null)
    149136      return;
    150     if (mapillaryData.getSelectedImage().getTempCa() != mapillaryData.getSelectedImage().getCa()) {
    151       double from = mapillaryData.getSelectedImage().getTempCa();
    152       double to = mapillaryData.getSelectedImage().getCa();
    153       record.addCommand(new CommandTurnImage(mapillaryData.getMultiSelectedImages(), to - from));
    154     } else if (mapillaryData.getSelectedImage().getTempLatLon() != mapillaryData.getSelectedImage().getLatLon()) {
    155       LatLon from = mapillaryData.getSelectedImage().getTempLatLon();
    156       LatLon to = mapillaryData.getSelectedImage().getLatLon();
    157       record.addCommand(new CommandMoveImage(mapillaryData.getMultiSelectedImages(), to.getX() - from.getX(), to.getY()
     137    if (data.getSelectedImage().getTempCa() != data.getSelectedImage().getCa()) {
     138      double from = data.getSelectedImage().getTempCa();
     139      double to = data.getSelectedImage().getCa();
     140      record.addCommand(new CommandTurnImage(data.getMultiSelectedImages(), to - from));
     141    } else if (data.getSelectedImage().getTempLatLon() != data.getSelectedImage().getLatLon()) {
     142      LatLon from = data.getSelectedImage().getTempLatLon();
     143      LatLon to = data.getSelectedImage().getLatLon();
     144      record.addCommand(new CommandMoveImage(data.getMultiSelectedImages(), to.getX() - from.getX(), to.getY()
    158145          - from.getY()));
    159146    }
    160     for (MapillaryAbstractImage img : mapillaryData.getMultiSelectedImages()) {
     147    for (MapillaryAbstractImage img : data.getMultiSelectedImages()) {
    161148      if (img != null)
    162149        img.stopMoving();
Note: See TracChangeset for help on using the changeset viewer.