Changeset 34786 in osm for applications/editors
- Timestamp:
- 2018-12-22T22:01:03+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/photoadjust
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/photoadjust/build.xml
r34611 r34786 5 5 <property name="commit.message" value="Commit message"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="14 205"/>7 <property name="plugin.main.version" value="14590"/> 8 8 9 9 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoAdjustWorker.java
r33757 r34786 7 7 import java.util.List; 8 8 9 import org.openstreetmap.josm.data.ImageData; 9 10 import org.openstreetmap.josm.data.coor.LatLon; 10 11 import org.openstreetmap.josm.gui.MainApplication; … … 19 20 20 21 private ImageEntry dragPhoto; 21 private GeoImageLayer dragLayer;22 private ImageData dragData; 22 23 // Offset between center of the photo and point where it is 23 24 // clicked. This must be in pixels to maintain the same offset if … … 32 33 public void reset() { 33 34 dragPhoto = null; 34 drag Layer= null;35 dragData = null; 35 36 dragOffset = null; 36 37 } … … 73 74 */ 74 75 public void doMousePressed(MouseEvent evt, 75 76 List<GeoImageLayer> imageLayers) { 76 77 reset(); 77 78 78 79 if (evt.getButton() == MouseEvent.BUTTON1 79 && imageLayers != null && !imageLayers.isEmpty()) {80 && imageLayers != null && !imageLayers.isEmpty()) { 80 81 // Check if modifier key is pressed and change to 81 82 // image viewer photo if it is. … … 83 84 final boolean isCtrl = (evt.getModifiers() & InputEvent.CTRL_MASK) != 0; 84 85 if (isShift || isCtrl) { 85 final GeoImageLayer viewerLayer = ImageViewerDialog.getCurrentLayer(); 86 final ImageEntry img = ImageViewerDialog.getCurrentImage(); 87 if (img != null && viewerLayer != null 88 && viewerLayer.isVisible() 89 && imageLayers.contains(viewerLayer)) { 90 // Change direction if control is pressed, position 91 // otherwise. Shift+control changes direction, similar to 92 // rotate in select mode. 93 // 94 // Combinations: 95 // S ... shift pressed 96 // C ... control pressed 97 // pos ... photo has a position set == is displayed on the map 98 // nopos ... photo has no position set 99 // 100 // S + pos: position at mouse 101 // S + nopos: position at mouse 102 // C + pos: change orientation 103 // 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, viewerLayer, evt); 86 for (GeoImageLayer layer: imageLayers) { 87 if (layer.isVisible()) { 88 final ImageEntry img = layer.getImageData().getSelectedImage(); 89 if (img != null) { 90 // Change direction if control is pressed, position 91 // otherwise. Shift+control changes direction, similar to 92 // rotate in select mode. 93 // 94 // Combinations: 95 // S ... shift pressed 96 // C ... control pressed 97 // pos ... photo has a position set == is displayed on the map 98 // nopos ... photo has no position set 99 // 100 // S + pos: position at mouse 101 // S + nopos: position at mouse 102 // C + pos: change orientation 103 // 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); 109 } 110 } else { // shift pressed 111 movePhoto(img, layer.getImageData(), evt); 112 } 113 dragPhoto = img; 114 dragData = layer.getImageData(); 115 break; 109 116 } 110 } else { // shift pressed111 movePhoto(img, viewerLayer, evt);112 117 } 113 dragPhoto = img;114 dragLayer = viewerLayer;115 118 } 116 119 } else { … … 120 123 dragPhoto = layer.getPhotoUnderMouse(evt); 121 124 if (dragPhoto != null) { 122 drag Layer = layer;125 dragData = layer.getImageData(); 123 126 setDragOffset(dragPhoto, evt); 124 127 disableCenterView(); … … 150 153 */ 151 154 public void doMouseDragged(MouseEvent evt) { 152 if (dragLayer != null && dragLayer.isVisible() 153 && dragPhoto != null) { 155 if (dragData != null && dragPhoto != null) { 154 156 if ((evt.getModifiers() & InputEvent.CTRL_MASK) != 0) { 155 changeDirection(dragPhoto, drag Layer, evt);157 changeDirection(dragPhoto, dragData, evt); 156 158 } else { 157 159 disableCenterView(); 158 movePhoto(dragPhoto, drag Layer, evt);160 movePhoto(dragPhoto, dragData, evt); 159 161 } 160 162 } … … 177 179 * 178 180 * @param photo The photo to move. 179 * @param layer GeoImageLayerof the photo.181 * @param data ImageData of the photo. 180 182 * @param evt Mouse event from one of the mouse adapters. 181 183 */ 182 private void movePhoto(ImageEntry photo, GeoImageLayer layer,183 184 private void movePhoto(ImageEntry photo, ImageData data, 185 MouseEvent evt) { 184 186 LatLon newPos; 185 187 if (dragOffset != null) { … … 190 192 newPos = MainApplication.getMap().mapView.getLatLon(evt.getX(), evt.getY()); 191 193 } 192 photo.setPos(newPos); 193 photo.flagNewGpsData(); 194 layer.updateBufferAndRepaint(); 194 data.updateImagePosition(photo, newPos); 195 195 // Re-display the photo because the OSD data might change (new 196 196 // coordinates). Or do that in doMouseReleased(). … … 202 202 * 203 203 * @param photo The photo to move. 204 * @param layer GeoImageLayerof the photo.204 * @param data ImageData of the photo. 205 205 * @param evt Mouse event from one of the mouse adapters. 206 206 */ 207 private void changeDirection(ImageEntry photo, GeoImageLayer layer,208 207 private void changeDirection(ImageEntry photo, ImageData data, 208 MouseEvent evt) { 209 209 final LatLon photoLL = photo.getPos(); 210 210 if (photoLL == null) { … … 220 220 direction -= 360.0; 221 221 } 222 photo.setExifImgDir(direction); 223 photo.flagNewGpsData(); 224 layer.updateBufferAndRepaint(); 225 ImageViewerDialog.showImage(layer, photo); 222 data.updateImageDirection(photo, direction); 226 223 setDragOffset(photo, evt); 227 224 } -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/PhotoPropertyEditor.java
r34684 r34786 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.event.ActionEvent; 9 import java.util.List; 10 import java.util.Optional; 9 11 10 12 import javax.swing.AbstractAction; 11 import javax.swing.Action;12 13 import javax.swing.BorderFactory; 13 14 import javax.swing.ImageIcon; 14 15 import javax.swing.JButton; 15 16 import javax.swing.JLabel; 16 import javax.swing.JOptionPane;17 17 import javax.swing.JPanel; 18 18 import javax.swing.JSeparator; … … 22 22 23 23 import org.openstreetmap.josm.actions.JosmAction; 24 import org.openstreetmap.josm.data.ImageData; 25 import org.openstreetmap.josm.data.ImageData.ImageDataUpdateListener; 24 26 import org.openstreetmap.josm.data.coor.LatLon; 25 27 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; … … 30 32 import org.openstreetmap.josm.gui.MainMenu; 31 33 import org.openstreetmap.josm.gui.dialogs.LatLonDialog; 34 import org.openstreetmap.josm.gui.layer.Layer; 35 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; 36 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener; 37 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 38 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 32 39 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 33 40 import org.openstreetmap.josm.gui.layer.geoimage.ImageEntry; 34 import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;35 41 import org.openstreetmap.josm.gui.widgets.JosmTextField; 36 42 import org.openstreetmap.josm.tools.GBC; … … 58 64 59 65 /** 60 * Update the geo image layer and the image viewer.61 *62 * @param layer GeoImageLayer of the photo.63 * @param photo The photo that is updated.64 */65 private static void updateLayer(GeoImageLayer layer, ImageEntry photo) {66 layer.updateBufferAndRepaint();67 ImageViewerDialog.showImage(layer, photo);68 }69 70 /**71 66 * Action if the menu entry is selected. 72 67 */ 73 private static class PropertyEditorAction extends JosmAction {68 private static class PropertyEditorAction extends JosmAction implements LayerChangeListener, ImageDataUpdateListener { 74 69 public PropertyEditorAction() { 75 70 super(tr("Edit photo GPS data"), // String name 76 (String)null, // String iconName 77 tr("Edit GPS data of selected photo."), // String tooltip 78 null, // Shortcut shortcut 79 true, // boolean registerInToolbar 80 "photoadjust/propertyeditor", // String toolbarId 81 true // boolean installAdapters 82 ); 71 (String)null, // String iconName 72 tr("Edit GPS data of selected photo."), // String tooltip 73 null, // Shortcut shortcut 74 true, // boolean registerInToolbar 75 "photoadjust/propertyeditor", // String toolbarId 76 false // boolean installAdapters 77 ); 78 this.installAdapters(); 79 } 80 81 @Override 82 protected void installAdapters() { 83 MainApplication.getLayerManager().addLayerChangeListener(this); 84 initEnabledState(); 83 85 } 84 86 85 87 @Override 86 88 public void actionPerformed(ActionEvent evt) { 87 try { 88 final ImageEntry photo = ImageViewerDialog.getCurrentImage(); 89 final GeoImageLayer layer = ImageViewerDialog.getCurrentLayer(); 90 if (photo == null) { 91 throw new AssertionError("No image selected."); 92 } 93 StringBuilder title = 89 final ImageData data = getLayerWithSelectedImage().get().getImageData(); 90 final ImageEntry photo = data.getSelectedImage(); 91 92 StringBuilder title = 94 93 new StringBuilder(tr("Edit Photo GPS Data")); 95 if (photo.getFile() != null) { 96 title.append(" - "); 97 title.append(photo.getFile().getName()); 98 } 99 PropertyEditorDialog dialog = 100 new PropertyEditorDialog(title.toString(), photo, layer); 101 if (dialog.getValue() == 1) { 102 dialog.updateImageTmp(); 103 // There are cases where isNewGpsData is not set but there 104 // is still new data, e.g. if the EXIF data was re-read 105 // from the image file. 106 photo.applyTmp(); 107 } else { 108 photo.discardTmp(); 109 } 110 updateLayer(layer, photo); 111 } catch (AssertionError err) { 112 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 113 tr("Please select an image first."), 114 tr("No image selected"), 115 JOptionPane.INFORMATION_MESSAGE); 116 return; 117 } 118 } 94 if (photo.getFile() != null) { 95 title.append(" - "); 96 title.append(photo.getFile().getName()); 97 } 98 PropertyEditorDialog dialog = 99 new PropertyEditorDialog(title.toString(), photo, data); 100 if (dialog.getValue() == 1) { 101 dialog.updateImageTmp(); 102 // There are cases where isNewGpsData is not set but there 103 // is still new data, e.g. if the EXIF data was re-read 104 // from the image file. 105 photo.applyTmp(); 106 } else { 107 photo.discardTmp(); 108 } 109 data.notifyImageUpdate(); 110 } 119 111 120 112 /** … … 125 117 */ 126 118 private static boolean enabled() { 127 try { 128 //return ImageViewerDialog.getInstance().hasImage(); 129 ImageViewerDialog.getInstance().hasImage(); 130 return true; 131 } catch (AssertionError err) { 132 return false; 133 } 119 return getLayerWithSelectedImage().isPresent(); 120 } 121 122 private static Optional<GeoImageLayer> getLayerWithSelectedImage() { 123 List<GeoImageLayer> list = MainApplication.getLayerManager().getLayersOfType(GeoImageLayer.class); 124 return list.stream().filter(l -> l.getImageData().getSelectedImage() != null).findFirst(); 134 125 } 135 126 … … 137 128 protected void updateEnabledState() { 138 129 setEnabled(enabled()); 130 } 131 132 @Override 133 public void layerAdded(LayerAddEvent e) { 134 Layer layer = e.getAddedLayer(); 135 if (layer instanceof GeoImageLayer) { 136 ((GeoImageLayer) layer).getImageData().addImageDataUpdateListener(this); 137 } 138 } 139 140 @Override 141 public void layerRemoving(LayerRemoveEvent e) { 142 Layer layer = e.getRemovedLayer(); 143 144 if (layer instanceof GeoImageLayer) { 145 ((GeoImageLayer) layer).getImageData().removeImageDataUpdateListener(this); 146 } 147 this.updateEnabledState(); 148 } 149 150 @Override 151 public void layerOrderChanged(LayerOrderChangeEvent e) { 152 // ignored 153 } 154 155 @Override 156 public void imageDataUpdated(ImageData data) { 157 // ignored 158 } 159 160 @Override 161 public void selectedImageChanged(ImageData data) { 162 this.updateEnabledState(); 139 163 } 140 164 } … … 150 174 // Image that is to be updated. 151 175 private final ImageEntry image; 152 private final GeoImageLayer layer;176 private final ImageData data; 153 177 // Image as it was when the dialog was opened. 154 178 private final GpxImageEntry imgOrig; … … 156 180 157 181 public PropertyEditorDialog(String title, final ImageEntry image, 158 final GeoImageLayer layer) {182 final ImageData data) { 159 183 super(MainApplication.getMainFrame(), title, tr("Ok"), tr("Cancel")); 160 184 this.image = image; 161 this. layer = layer;185 this.data = data; 162 186 imgOrig = image.clone(); 163 187 setButtonIcons("ok", "cancel"); … … 200 224 @Override public void updateValue(Double value) { 201 225 image.getTmp().setElevation(value); 202 updateLayer(layer, image);226 data.notifyImageUpdate(); 203 227 } 204 228 }; … … 214 238 @Override public void updateValue(Double value) { 215 239 image.getTmp().setSpeed(value); 216 updateLayer(layer, image);240 data.notifyImageUpdate(); 217 241 } 218 242 }; … … 230 254 @Override public void updateValue(Double value) { 231 255 image.getTmp().setExifImgDir(value); 232 updateLayer(layer, image);256 data.notifyImageUpdate(); 233 257 } 234 258 }; … … 573 597 public void updateLatLon(LatLon latLon) { 574 598 image.getTmp().setPos(latLon); 575 updateLayer(layer, image);599 data.notifyImageUpdate(); 576 600 } 577 601 -
applications/editors/josm/plugins/photoadjust/src/org/openstreetmap/josm/plugins/photoadjust/UntaggedGeoImageLayerAction.java
r34683 r34786 54 54 // from the original layer. 55 55 untagged.add(img); 56 layer. removePhotoByIdx(idx);56 layer.getImageData().removeImage(img); 57 57 } 58 58 }
Note:
See TracChangeset
for help on using the changeset viewer.