Changeset 31356 in osm for applications/editors
- Timestamp:
- 2015-07-09T11:57:16+02:00 (9 years ago)
- 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 10 10 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryFilterDialog; 11 11 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog; 12 import org.openstreetmap.josm.plugins.mapillary.mode.SelectMode; 12 13 import org.openstreetmap.josm.Main; 13 14 import org.openstreetmap.josm.gui.layer.Layer; … … 75 76 public ArrayList<Bounds> bounds; 76 77 77 private MouseAdapter mo useAdapter;78 private MouseAdapter mode; 78 79 79 80 private int highlightPointRadius = Main.pref.getInteger( … … 94 95 */ 95 96 private void init() { 96 mo useAdapter = new MapillaryMouseAdapter();97 mode = new SelectMode(); 97 98 try { 98 99 CACHE = JCSCacheManager.getCache("Mapillary"); … … 101 102 } 102 103 if (Main.map != null && Main.map.mapView != null) { 103 Main.map.mapView.addMouseListener(mo useAdapter);104 Main.map.mapView.addMouseMotionListener(mo useAdapter);104 Main.map.mapView.addMouseListener(mode); 105 Main.map.mapView.addMouseMotionListener(mode); 105 106 Main.map.mapView.addLayer(this); 106 107 MapView.addEditLayerChangeListener(this, false); … … 118 119 createHatchTexture(); 119 120 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); 120 129 } 121 130 … … 186 195 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.EXPORT_MENU, false); 187 196 MapillaryPlugin.setMenuEnabled(MapillaryPlugin.ZOOM_MENU, false); 188 Main.map.mapView.removeMouseListener(mo useAdapter);189 Main.map.mapView.removeMouseMotionListener(mo useAdapter);197 Main.map.mapView.removeMouseListener(mode); 198 Main.map.mapView.removeMouseMotionListener(mode); 190 199 MapView.removeEditLayerChangeListener(this); 191 200 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 ;1 package org.openstreetmap.josm.plugins.mapillary.mode; 2 2 3 3 import java.awt.Point; 4 import java.awt.event.MouseAdapter;5 4 import java.awt.event.MouseEvent; 6 5 import java.util.ArrayList; … … 10 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 10 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 11 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage; 15 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 12 16 import org.openstreetmap.josm.plugins.mapillary.commands.CommandMoveImage; 13 17 import org.openstreetmap.josm.plugins.mapillary.commands.CommandTurnImage; … … 21 25 * 22 26 */ 23 public class MapillaryMouseAdapter extends MouseAdapter{27 public class SelectMode extends AbstractMode { 24 28 private Point start; 25 29 private int lastButton; 26 30 private MapillaryAbstractImage closest; 27 31 private MapillaryAbstractImage lastClicked; 28 private MapillaryData mapillaryData;29 32 private MapillaryRecord record; 30 33 … … 32 35 private boolean imageHighlighted = false; 33 36 34 public MapillaryMouseAdapter() {35 mapillaryData = MapillaryData.getInstance();37 public SelectMode() { 38 data = MapillaryData.getInstance(); 36 39 record = MapillaryRecord.getInstance(); 37 40 } … … 53 56 MapillaryImage closest = (MapillaryImage) closestTemp; 54 57 // Doube click 55 if (e.getClickCount() == 2 && mapillaryData.getSelectedImage() != null && closest != null) {58 if (e.getClickCount() == 2 && data.getSelectedImage() != null && closest != null) { 56 59 for (MapillaryAbstractImage img : closest.getSequence().getImages()) { 57 mapillaryData.addMultiSelectedImage(img);60 data.addMultiSelectedImage(img); 58 61 } 59 62 } … … 61 64 this.lastClicked = this.closest; 62 65 this.closest = closest; 63 if ( mapillaryData.getMultiSelectedImages().contains(closest))66 if (data.getMultiSelectedImages().contains(closest)) 64 67 return; 65 68 // ctrl+click 66 69 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) && closest != null) 67 mapillaryData.addMultiSelectedImage(closest);70 data.addMultiSelectedImage(closest); 68 71 // shift + click 69 72 else if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK) … … 74 77 int j = ((MapillaryImage) this.lastClicked).getSequence().getImages().indexOf(this.lastClicked); 75 78 if (i < j) 76 mapillaryData.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()79 data.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence() 77 80 .getImages().subList(i, j + 1))); 78 81 else 79 mapillaryData.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence()82 data.addMultiSelectedImage(new ArrayList<>(((MapillaryImage) this.closest).getSequence() 80 83 .getImages().subList(j, i + 1))); 81 84 } 82 85 // click 83 86 } else 84 mapillaryData.setSelectedImage(closest);87 data.setSelectedImage(closest); 85 88 // If you select an imported image 86 89 } else if (closestTemp instanceof MapillaryImportedImage) { … … 89 92 this.lastClicked = this.closest; 90 93 this.closest = closest; 91 if ( mapillaryData.getMultiSelectedImages().contains(closest))94 if (data.getMultiSelectedImages().contains(closest)) 92 95 return; 93 96 if (e.getModifiers() == (MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK) && closest != null) 94 mapillaryData.addMultiSelectedImage(closest);97 data.addMultiSelectedImage(closest); 95 98 else 96 mapillaryData.setSelectedImage(closest);99 data.setSelectedImage(closest); 97 100 } 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;114 101 } 115 102 … … 146 133 @Override 147 134 public void mouseReleased(MouseEvent e) { 148 if ( mapillaryData.getSelectedImage() == null)135 if (data.getSelectedImage() == null) 149 136 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() 158 145 - from.getY())); 159 146 } 160 for (MapillaryAbstractImage img : mapillaryData.getMultiSelectedImages()) {147 for (MapillaryAbstractImage img : data.getMultiSelectedImages()) { 161 148 if (img != null) 162 149 img.stopMoving();
Note:
See TracChangeset
for help on using the changeset viewer.