Changeset 35108 in osm for applications/editors/josm/plugins/photoadjust/src
- Timestamp:
- 2019-09-09T20:35:38+02:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustMapMode.java
r33757 r35108 84 84 public String getModeHelpText() { 85 85 if (hasLayersToAdjust()) { 86 return tr("Click+drag photo, shift+click to position photo, control+click to set direction.");86 return tr("Click+drag photo, control+alt+click to position photo, control+click to set direction."); 87 87 } else { 88 88 return tr("Please load some photos."); -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
r34786 r35108 2 2 package org.openstreetmap.josm.plugins.photoadjust; 3 3 4 import java.awt.event.InputEvent;5 4 import java.awt.event.MouseEvent; 6 import java.awt.geom.Point2D;7 5 import java.util.List; 8 6 9 7 import org.openstreetmap.josm.data.ImageData; 8 import org.openstreetmap.josm.data.coor.EastNorth; 10 9 import org.openstreetmap.josm.data.coor.LatLon; 10 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 11 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; … … 24 24 // clicked. This must be in pixels to maintain the same offset if 25 25 // the photo is moved very far. 26 private Point2DdragOffset;26 private EastNorth dragOffset; 27 27 private boolean centerViewIsDisabled = false; 28 28 private boolean centerViewNeedsEnable = false; … … 34 34 dragPhoto = null; 35 35 dragData = null; 36 dragOffset = null;36 dragOffset = EastNorth.ZERO; 37 37 } 38 38 … … 66 66 /** 67 67 * Mouse click handler. Control+click changes the image direction if 68 * there is a photo selected on the map. Shift+click positions the photo69 * from the ImageViewerDialog. Click without shift or control checks if70 * there is a photo under the mouse.68 * there is a photo selected on the map. Control+alt+click positions the 69 * selected photo. Click without shift or control checks if there is a 70 * photo under the mouse and uses it for dragging. 71 71 * 72 72 * @param evt Mouse event from MouseAdapter mousePressed(). … … 81 81 // Check if modifier key is pressed and change to 82 82 // image viewer photo if it is. 83 final boolean isShift = (evt.getModifiers() & InputEvent.SHIFT_MASK) != 0; 84 final boolean isCtrl = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; 85 if (isShift || isCtrl) { 83 final boolean isAlt = (evt.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) == MouseEvent.ALT_DOWN_MASK; 84 final boolean isCtrl = (evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK; 85 final boolean isShift = (evt.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK; 86 // ignore key press with shift, to not conflict with selection 87 if (isShift) { 88 return; 89 } 90 if (isAlt || isCtrl) { 86 91 for (GeoImageLayer layer: imageLayers) { 87 92 if (layer.isVisible()) { 88 final ImageEntry img = layer.getImageData().getSelectedImage();89 if ( img != null) {93 final List<ImageEntry> entries = layer.getImageData().getSelectedImages(); 94 if (!entries.isEmpty()) { 90 95 // Change direction if control is pressed, position 91 // otherwise. Shift+control changes direction, similar to 92 // rotate in select mode. 96 // with control+alt. 93 97 // 94 98 // Combinations: 95 // S ... shift pressed99 // A ... alt pressed 96 100 // C ... control pressed 97 101 // pos ... photo has a position set == is displayed on the map 98 102 // nopos ... photo has no position set 99 103 // 100 // S+ pos: position at mouse101 // S+ nopos: position at mouse104 // C + A + pos: position at mouse 105 // C + A + nopos: position at mouse 102 106 // C + pos: change orientation 103 107 // C + nopos: ignored 104 // S + C + pos: change orientation 105 // S + C + nopos: ignore 106 if (isCtrl) { 107 if (img.getPos() != null) { 108 changeDirection(img, layer.getImageData(), evt); 108 for (ImageEntry img: entries) { 109 if (isCtrl && !isAlt) { 110 if (img.getPos() != null) { 111 changeDirection(img, layer.getImageData(), evt); 112 } 113 } else if (isCtrl && isAlt) { 114 movePhoto(img, layer.getImageData(), evt); 109 115 } 110 } else { // shift pressed 111 movePhoto(img, layer.getImageData(), evt); 116 dragPhoto = img; 112 117 } 113 dragPhoto = img;114 118 dragData = layer.getImageData(); 115 119 break; … … 141 145 public void doMouseReleased(MouseEvent evt) { 142 146 restoreCenterView(); 143 //if (dragLayer != null && dragPhoto != null) {144 // // Re-display the photo to update the OSD.145 // ImageViewerDialog.showImage(dragLayer, dragPhoto);146 //}147 147 } 148 148 … … 154 154 public void doMouseDragged(MouseEvent evt) { 155 155 if (dragData != null && dragPhoto != null) { 156 if ((evt.getModifiers() & InputEvent.CTRL_MASK) != 0) { 157 changeDirection(dragPhoto, dragData, evt); 156 if ((evt.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK) { 157 if (dragData.isImageSelected(dragPhoto)) { 158 for (ImageEntry photo: dragData.getSelectedImages()) { 159 changeDirection(photo, dragData, evt); 160 } 161 } else { 162 changeDirection(dragPhoto, dragData, evt); 163 } 158 164 } else { 159 165 disableCenterView(); 160 movePhoto(dragPhoto, dragData, evt); 166 final EastNorth startEN = dragPhoto.getPos().getEastNorth(ProjectionRegistry.getProjection()).subtract(dragOffset); 167 final EastNorth currentEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY()); 168 final EastNorth translation = currentEN.subtract(startEN); 169 170 if (dragData.isImageSelected(dragPhoto)) { 171 for (ImageEntry photo: dragData.getSelectedImages()) { 172 translatePhoto(photo, translation); 173 } 174 } else { 175 translatePhoto(dragPhoto, translation); 176 } 177 dragData.notifyImageUpdate(); 161 178 } 162 179 } … … 170 187 */ 171 188 private void setDragOffset(ImageEntry photo, MouseEvent evt) { 172 final Point2D centerPoint = MainApplication.getMap().mapView.getPoint2D(photo.getPos());173 dragOffset = new Point2D.Double(centerPoint.getX() - evt.getX(),174 centerPoint.getY() - evt.getY());189 final EastNorth centerEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection()); 190 final EastNorth offsetEN = MainApplication.getMap().mapView.getEastNorth(evt.getX(), evt.getY()); 191 dragOffset = centerEN.subtract(offsetEN); 175 192 } 176 193 … … 182 199 * @param evt Mouse event from one of the mouse adapters. 183 200 */ 184 private void movePhoto(ImageEntry photo, ImageData data, 185 MouseEvent evt) { 186 LatLon newPos; 187 if (dragOffset != null) { 188 newPos = MainApplication.getMap().mapView.getLatLon( 189 dragOffset.getX() + evt.getX(), 190 dragOffset.getY() + evt.getY()); 191 } else { 192 newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 193 } 201 private void movePhoto(ImageEntry photo, ImageData data, MouseEvent evt) { 202 LatLon newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 194 203 data.updateImagePosition(photo, newPos); 195 // Re-display the photo because the OSD data might change (new 196 // coordinates). Or do that in doMouseReleased(). 197 //ImageViewerDialog.showImage(layer, photo); 204 } 205 206 /** 207 * Apply the given translation to the photo 208 * @param photo The photo to move 209 * @param translation the translation to apply 210 */ 211 private void translatePhoto(ImageEntry photo, EastNorth translation) { 212 final EastNorth startEN = photo.getPos().getEastNorth(ProjectionRegistry.getProjection()); 213 final EastNorth newPosEN = startEN.add(translation); 214 final LatLon newPos = MainApplication.getMap().mapView.getProjection().eastNorth2latlon(newPosEN); 215 photo.setPos(newPos); 216 photo.flagNewGpsData(); 198 217 } 199 218 -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java
r34799 r35108 87 87 @Override 88 88 public void actionPerformed(ActionEvent evt) { 89 final ImageData data = getLayerWith SelectedImage().get().getImageData();90 final ImageEntry photo = data.getSelectedImage ();89 final ImageData data = getLayerWithOneSelectedImage().get().getImageData(); 90 final ImageEntry photo = data.getSelectedImages().get(0); 91 91 92 92 StringBuilder title = … … 117 117 */ 118 118 private static boolean enabled() { 119 return getLayerWith SelectedImage().isPresent();120 } 121 122 private static Optional<GeoImageLayer> getLayerWith SelectedImage() {119 return getLayerWithOneSelectedImage().isPresent(); 120 } 121 122 private static Optional<GeoImageLayer> getLayerWithOneSelectedImage() { 123 123 List<GeoImageLayer> list = MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class); 124 return list.stream().filter(l -> l.getImageData().getSelectedImage () != null).findFirst();124 return list.stream().filter(l -> l.getImageData().getSelectedImages().size() == 1).findFirst(); 125 125 } 126 126
Note:
See TracChangeset
for help on using the changeset viewer.