1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
6 |
|
---|
7 | import java.awt.AlphaComposite;
|
---|
8 | import java.awt.BasicStroke;
|
---|
9 | import java.awt.Color;
|
---|
10 | import java.awt.Composite;
|
---|
11 | import java.awt.Dimension;
|
---|
12 | import java.awt.Graphics2D;
|
---|
13 | import java.awt.Image;
|
---|
14 | import java.awt.Point;
|
---|
15 | import java.awt.Rectangle;
|
---|
16 | import java.awt.RenderingHints;
|
---|
17 | import java.awt.event.MouseAdapter;
|
---|
18 | import java.awt.event.MouseEvent;
|
---|
19 | import java.awt.event.MouseMotionAdapter;
|
---|
20 | import java.awt.image.BufferedImage;
|
---|
21 | import java.io.File;
|
---|
22 | import java.io.IOException;
|
---|
23 | import java.util.ArrayList;
|
---|
24 | import java.util.Arrays;
|
---|
25 | import java.util.Collection;
|
---|
26 | import java.util.Collections;
|
---|
27 | import java.util.HashSet;
|
---|
28 | import java.util.LinkedHashSet;
|
---|
29 | import java.util.LinkedList;
|
---|
30 | import java.util.List;
|
---|
31 | import java.util.Set;
|
---|
32 | import java.util.concurrent.ExecutorService;
|
---|
33 | import java.util.concurrent.Executors;
|
---|
34 |
|
---|
35 | import javax.swing.Action;
|
---|
36 | import javax.swing.Icon;
|
---|
37 | import javax.swing.JLabel;
|
---|
38 | import javax.swing.JOptionPane;
|
---|
39 | import javax.swing.SwingConstants;
|
---|
40 |
|
---|
41 | import org.openstreetmap.josm.Main;
|
---|
42 | import org.openstreetmap.josm.actions.LassoModeAction;
|
---|
43 | import org.openstreetmap.josm.actions.RenameLayerAction;
|
---|
44 | import org.openstreetmap.josm.actions.mapmode.MapMode;
|
---|
45 | import org.openstreetmap.josm.actions.mapmode.SelectAction;
|
---|
46 | import org.openstreetmap.josm.data.Bounds;
|
---|
47 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
---|
48 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
49 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
50 | import org.openstreetmap.josm.gui.MapFrame.MapModeChangeListener;
|
---|
51 | import org.openstreetmap.josm.gui.MapView;
|
---|
52 | import org.openstreetmap.josm.gui.NavigatableComponent;
|
---|
53 | import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
---|
54 | import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
|
---|
55 | import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
|
---|
56 | import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
|
---|
57 | import org.openstreetmap.josm.gui.layer.AbstractModifiableLayer;
|
---|
58 | import org.openstreetmap.josm.gui.layer.GpxLayer;
|
---|
59 | import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToMarkerLayer;
|
---|
60 | import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToNextMarker;
|
---|
61 | import org.openstreetmap.josm.gui.layer.JumpToMarkerActions.JumpToPreviousMarker;
|
---|
62 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
63 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
|
---|
64 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
|
---|
65 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
|
---|
66 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
|
---|
67 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
68 | import org.openstreetmap.josm.io.JpgImporter;
|
---|
69 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
70 | import org.openstreetmap.josm.tools.Utils;
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Layer displaying geottaged pictures.
|
---|
74 | */
|
---|
75 | public class GeoImageLayer extends AbstractModifiableLayer implements
|
---|
76 | JumpToMarkerLayer, NavigatableComponent.ZoomChangeListener {
|
---|
77 |
|
---|
78 | private static List<Action> menuAdditions = new LinkedList<>();
|
---|
79 |
|
---|
80 | private static volatile List<MapMode> supportedMapModes;
|
---|
81 |
|
---|
82 | List<ImageEntry> data;
|
---|
83 | GpxLayer gpxLayer;
|
---|
84 |
|
---|
85 | private final Icon icon = ImageProvider.get("dialogs/geoimage/photo-marker");
|
---|
86 | private final Icon selectedIcon = ImageProvider.get("dialogs/geoimage/photo-marker-selected");
|
---|
87 |
|
---|
88 | private int currentPhoto = -1;
|
---|
89 |
|
---|
90 | boolean useThumbs;
|
---|
91 | private final ExecutorService thumbsLoaderExecutor =
|
---|
92 | Executors.newSingleThreadExecutor(Utils.newThreadFactory("thumbnail-loader-%d", Thread.MIN_PRIORITY));
|
---|
93 | private ThumbsLoader thumbsloader;
|
---|
94 | private boolean thumbsLoaderRunning;
|
---|
95 | volatile boolean thumbsLoaded;
|
---|
96 | private BufferedImage offscreenBuffer;
|
---|
97 | boolean updateOffscreenBuffer = true;
|
---|
98 |
|
---|
99 | private MouseAdapter mouseAdapter;
|
---|
100 | private MouseMotionAdapter mouseMotionAdapter;
|
---|
101 | private MapModeChangeListener mapModeListener;
|
---|
102 |
|
---|
103 | /** Mouse position where the last image was selected. */
|
---|
104 | private Point lastSelPos;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Image cycle mode flag.
|
---|
108 | * It is possible that a mouse button release triggers multiple mouseReleased() events.
|
---|
109 | * To prevent the cycling in such a case we wait for the next mouse button press event
|
---|
110 | * before it is cycled to the next image.
|
---|
111 | */
|
---|
112 | private boolean cycleModeArmed;
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Constructs a new {@code GeoImageLayer}.
|
---|
116 | * @param data The list of images to display
|
---|
117 | * @param gpxLayer The associated GPX layer
|
---|
118 | */
|
---|
119 | public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer) {
|
---|
120 | this(data, gpxLayer, null, false);
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Constructs a new {@code GeoImageLayer}.
|
---|
125 | * @param data The list of images to display
|
---|
126 | * @param gpxLayer The associated GPX layer
|
---|
127 | * @param name Layer name
|
---|
128 | * @since 6392
|
---|
129 | */
|
---|
130 | public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name) {
|
---|
131 | this(data, gpxLayer, name, false);
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Constructs a new {@code GeoImageLayer}.
|
---|
136 | * @param data The list of images to display
|
---|
137 | * @param gpxLayer The associated GPX layer
|
---|
138 | * @param useThumbs Thumbnail display flag
|
---|
139 | * @since 6392
|
---|
140 | */
|
---|
141 | public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, boolean useThumbs) {
|
---|
142 | this(data, gpxLayer, null, useThumbs);
|
---|
143 | }
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Constructs a new {@code GeoImageLayer}.
|
---|
147 | * @param data The list of images to display
|
---|
148 | * @param gpxLayer The associated GPX layer
|
---|
149 | * @param name Layer name
|
---|
150 | * @param useThumbs Thumbnail display flag
|
---|
151 | * @since 6392
|
---|
152 | */
|
---|
153 | public GeoImageLayer(final List<ImageEntry> data, GpxLayer gpxLayer, final String name, boolean useThumbs) {
|
---|
154 | super(name != null ? name : tr("Geotagged Images"));
|
---|
155 | if (data != null) {
|
---|
156 | Collections.sort(data);
|
---|
157 | }
|
---|
158 | this.data = data;
|
---|
159 | this.gpxLayer = gpxLayer;
|
---|
160 | this.useThumbs = useThumbs;
|
---|
161 | }
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Loads a set of images, while displaying a dialog that indicates what the plugin is currently doing.
|
---|
165 | * In facts, this object is instantiated with a list of files. These files may be JPEG files or
|
---|
166 | * directories. In case of directories, they are scanned to find all the images they contain.
|
---|
167 | * Then all the images that have be found are loaded as ImageEntry instances.
|
---|
168 | */
|
---|
169 | static final class Loader extends PleaseWaitRunnable {
|
---|
170 |
|
---|
171 | private boolean canceled;
|
---|
172 | private GeoImageLayer layer;
|
---|
173 | private final Collection<File> selection;
|
---|
174 | private final Set<String> loadedDirectories = new HashSet<>();
|
---|
175 | private final Set<String> errorMessages;
|
---|
176 | private final GpxLayer gpxLayer;
|
---|
177 |
|
---|
178 | Loader(Collection<File> selection, GpxLayer gpxLayer) {
|
---|
179 | super(tr("Extracting GPS locations from EXIF"));
|
---|
180 | this.selection = selection;
|
---|
181 | this.gpxLayer = gpxLayer;
|
---|
182 | errorMessages = new LinkedHashSet<>();
|
---|
183 | }
|
---|
184 |
|
---|
185 | private void rememberError(String message) {
|
---|
186 | this.errorMessages.add(message);
|
---|
187 | }
|
---|
188 |
|
---|
189 | @Override
|
---|
190 | protected void realRun() throws IOException {
|
---|
191 |
|
---|
192 | progressMonitor.subTask(tr("Starting directory scan"));
|
---|
193 | Collection<File> files = new ArrayList<>();
|
---|
194 | try {
|
---|
195 | addRecursiveFiles(files, selection);
|
---|
196 | } catch (IllegalStateException e) {
|
---|
197 | Main.debug(e);
|
---|
198 | rememberError(e.getMessage());
|
---|
199 | }
|
---|
200 |
|
---|
201 | if (canceled)
|
---|
202 | return;
|
---|
203 | progressMonitor.subTask(tr("Read photos..."));
|
---|
204 | progressMonitor.setTicksCount(files.size());
|
---|
205 |
|
---|
206 | // read the image files
|
---|
207 | List<ImageEntry> entries = new ArrayList<>(files.size());
|
---|
208 |
|
---|
209 | for (File f : files) {
|
---|
210 |
|
---|
211 | if (canceled) {
|
---|
212 | break;
|
---|
213 | }
|
---|
214 |
|
---|
215 | progressMonitor.subTask(tr("Reading {0}...", f.getName()));
|
---|
216 | progressMonitor.worked(1);
|
---|
217 |
|
---|
218 | ImageEntry e = new ImageEntry(f);
|
---|
219 | e.extractExif();
|
---|
220 | entries.add(e);
|
---|
221 | }
|
---|
222 | layer = new GeoImageLayer(entries, gpxLayer);
|
---|
223 | files.clear();
|
---|
224 | }
|
---|
225 |
|
---|
226 | private void addRecursiveFiles(Collection<File> files, Collection<File> sel) {
|
---|
227 | boolean nullFile = false;
|
---|
228 |
|
---|
229 | for (File f : sel) {
|
---|
230 |
|
---|
231 | if (canceled) {
|
---|
232 | break;
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (f == null) {
|
---|
236 | nullFile = true;
|
---|
237 |
|
---|
238 | } else if (f.isDirectory()) {
|
---|
239 | String canonical = null;
|
---|
240 | try {
|
---|
241 | canonical = f.getCanonicalPath();
|
---|
242 | } catch (IOException e) {
|
---|
243 | Main.error(e);
|
---|
244 | rememberError(tr("Unable to get canonical path for directory {0}\n",
|
---|
245 | f.getAbsolutePath()));
|
---|
246 | }
|
---|
247 |
|
---|
248 | if (canonical == null || loadedDirectories.contains(canonical)) {
|
---|
249 | continue;
|
---|
250 | } else {
|
---|
251 | loadedDirectories.add(canonical);
|
---|
252 | }
|
---|
253 |
|
---|
254 | File[] children = f.listFiles(JpgImporter.FILE_FILTER_WITH_FOLDERS);
|
---|
255 | if (children != null) {
|
---|
256 | progressMonitor.subTask(tr("Scanning directory {0}", f.getPath()));
|
---|
257 | addRecursiveFiles(files, Arrays.asList(children));
|
---|
258 | } else {
|
---|
259 | rememberError(tr("Error while getting files from directory {0}\n", f.getPath()));
|
---|
260 | }
|
---|
261 |
|
---|
262 | } else {
|
---|
263 | files.add(f);
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | if (nullFile) {
|
---|
268 | throw new IllegalStateException(tr("One of the selected files was null"));
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | private String formatErrorMessages() {
|
---|
273 | StringBuilder sb = new StringBuilder();
|
---|
274 | sb.append("<html>");
|
---|
275 | if (errorMessages.size() == 1) {
|
---|
276 | sb.append(Utils.escapeReservedCharactersHTML(errorMessages.iterator().next()));
|
---|
277 | } else {
|
---|
278 | sb.append(Utils.joinAsHtmlUnorderedList(errorMessages));
|
---|
279 | }
|
---|
280 | sb.append("</html>");
|
---|
281 | return sb.toString();
|
---|
282 | }
|
---|
283 |
|
---|
284 | @Override protected void finish() {
|
---|
285 | if (!errorMessages.isEmpty()) {
|
---|
286 | JOptionPane.showMessageDialog(
|
---|
287 | Main.parent,
|
---|
288 | formatErrorMessages(),
|
---|
289 | tr("Error"),
|
---|
290 | JOptionPane.ERROR_MESSAGE
|
---|
291 | );
|
---|
292 | }
|
---|
293 | if (layer != null) {
|
---|
294 | Main.getLayerManager().addLayer(layer);
|
---|
295 |
|
---|
296 | if (!canceled && layer.data != null && !layer.data.isEmpty()) {
|
---|
297 | boolean noGeotagFound = true;
|
---|
298 | for (ImageEntry e : layer.data) {
|
---|
299 | if (e.getPos() != null) {
|
---|
300 | noGeotagFound = false;
|
---|
301 | }
|
---|
302 | }
|
---|
303 | if (noGeotagFound) {
|
---|
304 | new CorrelateGpxWithImages(layer).actionPerformed(null);
|
---|
305 | }
|
---|
306 | }
|
---|
307 | }
|
---|
308 | }
|
---|
309 |
|
---|
310 | @Override protected void cancel() {
|
---|
311 | canceled = true;
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | public static void create(Collection<File> files, GpxLayer gpxLayer) {
|
---|
316 | Main.worker.execute(new Loader(files, gpxLayer));
|
---|
317 | }
|
---|
318 |
|
---|
319 | @Override
|
---|
320 | public Icon getIcon() {
|
---|
321 | return ImageProvider.get("dialogs/geoimage");
|
---|
322 | }
|
---|
323 |
|
---|
324 | public static void registerMenuAddition(Action addition) {
|
---|
325 | menuAdditions.add(addition);
|
---|
326 | }
|
---|
327 |
|
---|
328 | @Override
|
---|
329 | public Action[] getMenuEntries() {
|
---|
330 |
|
---|
331 | List<Action> entries = new ArrayList<>();
|
---|
332 | entries.add(LayerListDialog.getInstance().createShowHideLayerAction());
|
---|
333 | entries.add(LayerListDialog.getInstance().createDeleteLayerAction());
|
---|
334 | entries.add(LayerListDialog.getInstance().createMergeLayerAction(this));
|
---|
335 | entries.add(new RenameLayerAction(null, this));
|
---|
336 | entries.add(SeparatorLayerAction.INSTANCE);
|
---|
337 | entries.add(new CorrelateGpxWithImages(this));
|
---|
338 | entries.add(new ShowThumbnailAction(this));
|
---|
339 | if (!menuAdditions.isEmpty()) {
|
---|
340 | entries.add(SeparatorLayerAction.INSTANCE);
|
---|
341 | entries.addAll(menuAdditions);
|
---|
342 | }
|
---|
343 | entries.add(SeparatorLayerAction.INSTANCE);
|
---|
344 | entries.add(new JumpToNextMarker(this));
|
---|
345 | entries.add(new JumpToPreviousMarker(this));
|
---|
346 | entries.add(SeparatorLayerAction.INSTANCE);
|
---|
347 | entries.add(new LayerListPopup.InfoAction(this));
|
---|
348 |
|
---|
349 | return entries.toArray(new Action[entries.size()]);
|
---|
350 |
|
---|
351 | }
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Prepare the string that is displayed if layer information is requested.
|
---|
355 | * @return String with layer information
|
---|
356 | */
|
---|
357 | private String infoText() {
|
---|
358 | int tagged = 0;
|
---|
359 | int newdata = 0;
|
---|
360 | int n = 0;
|
---|
361 | if (data != null) {
|
---|
362 | n = data.size();
|
---|
363 | for (ImageEntry e : data) {
|
---|
364 | if (e.getPos() != null) {
|
---|
365 | tagged++;
|
---|
366 | }
|
---|
367 | if (e.hasNewGpsData()) {
|
---|
368 | newdata++;
|
---|
369 | }
|
---|
370 | }
|
---|
371 | }
|
---|
372 | return "<html>"
|
---|
373 | + trn("{0} image loaded.", "{0} images loaded.", n, n)
|
---|
374 | + ' ' + trn("{0} was found to be GPS tagged.", "{0} were found to be GPS tagged.", tagged, tagged)
|
---|
375 | + (newdata > 0 ? "<br>" + trn("{0} has updated GPS data.", "{0} have updated GPS data.", newdata, newdata) : "")
|
---|
376 | + "</html>";
|
---|
377 | }
|
---|
378 |
|
---|
379 | @Override public Object getInfoComponent() {
|
---|
380 | return infoText();
|
---|
381 | }
|
---|
382 |
|
---|
383 | @Override
|
---|
384 | public String getToolTipText() {
|
---|
385 | return infoText();
|
---|
386 | }
|
---|
387 |
|
---|
388 | /**
|
---|
389 | * Determines if data managed by this layer has been modified. That is
|
---|
390 | * the case if one image has modified GPS data.
|
---|
391 | * @return {@code true} if data has been modified; {@code false}, otherwise
|
---|
392 | */
|
---|
393 | @Override
|
---|
394 | public boolean isModified() {
|
---|
395 | if (data != null) {
|
---|
396 | for (ImageEntry e : data) {
|
---|
397 | if (e.hasNewGpsData()) {
|
---|
398 | return true;
|
---|
399 | }
|
---|
400 | }
|
---|
401 | }
|
---|
402 | return false;
|
---|
403 | }
|
---|
404 |
|
---|
405 | @Override
|
---|
406 | public boolean isMergable(Layer other) {
|
---|
407 | return other instanceof GeoImageLayer;
|
---|
408 | }
|
---|
409 |
|
---|
410 | @Override
|
---|
411 | public void mergeFrom(Layer from) {
|
---|
412 | if (!(from instanceof GeoImageLayer))
|
---|
413 | throw new IllegalArgumentException("not a GeoImageLayer: " + from);
|
---|
414 | GeoImageLayer l = (GeoImageLayer) from;
|
---|
415 |
|
---|
416 | // Stop to load thumbnails on both layers. Thumbnail loading will continue the next time
|
---|
417 | // the layer is painted.
|
---|
418 | stopLoadThumbs();
|
---|
419 | l.stopLoadThumbs();
|
---|
420 |
|
---|
421 | final ImageEntry selected = l.data != null && l.currentPhoto >= 0 ? l.data.get(l.currentPhoto) : null;
|
---|
422 |
|
---|
423 | if (l.data != null) {
|
---|
424 | data.addAll(l.data);
|
---|
425 | }
|
---|
426 | Collections.sort(data);
|
---|
427 |
|
---|
428 | // Supress the double photos.
|
---|
429 | if (data.size() > 1) {
|
---|
430 | ImageEntry cur;
|
---|
431 | ImageEntry prev = data.get(data.size() - 1);
|
---|
432 | for (int i = data.size() - 2; i >= 0; i--) {
|
---|
433 | cur = data.get(i);
|
---|
434 | if (cur.getFile().equals(prev.getFile())) {
|
---|
435 | data.remove(i);
|
---|
436 | } else {
|
---|
437 | prev = cur;
|
---|
438 | }
|
---|
439 | }
|
---|
440 | }
|
---|
441 |
|
---|
442 | if (selected != null && !data.isEmpty()) {
|
---|
443 | GuiHelper.runInEDTAndWait(() -> {
|
---|
444 | for (int i = 0; i < data.size(); i++) {
|
---|
445 | if (selected.equals(data.get(i))) {
|
---|
446 | currentPhoto = i;
|
---|
447 | ImageViewerDialog.showImage(this, data.get(i));
|
---|
448 | break;
|
---|
449 | }
|
---|
450 | }
|
---|
451 | });
|
---|
452 | }
|
---|
453 |
|
---|
454 | setName(l.getName());
|
---|
455 | thumbsLoaded &= l.thumbsLoaded;
|
---|
456 | }
|
---|
457 |
|
---|
458 | private static Dimension scaledDimension(Image thumb) {
|
---|
459 | final double d = Main.map.mapView.getDist100Pixel();
|
---|
460 | final double size = 10 /*meter*/; /* size of the photo on the map */
|
---|
461 | double s = size * 100 /*px*/ / d;
|
---|
462 |
|
---|
463 | final double sMin = ThumbsLoader.minSize;
|
---|
464 | final double sMax = ThumbsLoader.maxSize;
|
---|
465 |
|
---|
466 | if (s < sMin) {
|
---|
467 | s = sMin;
|
---|
468 | }
|
---|
469 | if (s > sMax) {
|
---|
470 | s = sMax;
|
---|
471 | }
|
---|
472 | final double f = s / sMax; /* scale factor */
|
---|
473 |
|
---|
474 | if (thumb == null)
|
---|
475 | return null;
|
---|
476 |
|
---|
477 | return new Dimension(
|
---|
478 | (int) Math.round(f * thumb.getWidth(null)),
|
---|
479 | (int) Math.round(f * thumb.getHeight(null)));
|
---|
480 | }
|
---|
481 |
|
---|
482 | /**
|
---|
483 | * Paint one image.
|
---|
484 | * @param e Image to be painted
|
---|
485 | * @param mv Map view
|
---|
486 | * @param clip Bounding rectangle of the current clipping area
|
---|
487 | * @param tempG Temporary offscreen buffer
|
---|
488 | */
|
---|
489 | private void paintImage(ImageEntry e, MapView mv, Rectangle clip, Graphics2D tempG) {
|
---|
490 | if (e.getPos() == null) {
|
---|
491 | return;
|
---|
492 | }
|
---|
493 | Point p = mv.getPoint(e.getPos());
|
---|
494 | if (e.hasThumbnail()) {
|
---|
495 | Dimension d = scaledDimension(e.getThumbnail());
|
---|
496 | if (d != null) {
|
---|
497 | Rectangle target = new Rectangle(p.x - d.width / 2, p.y - d.height / 2, d.width, d.height);
|
---|
498 | if (clip.intersects(target)) {
|
---|
499 | tempG.drawImage(e.getThumbnail(), target.x, target.y, target.width, target.height, null);
|
---|
500 | }
|
---|
501 | }
|
---|
502 | } else { // thumbnail not loaded yet
|
---|
503 | icon.paintIcon(mv, tempG,
|
---|
504 | p.x - icon.getIconWidth() / 2,
|
---|
505 | p.y - icon.getIconHeight() / 2);
|
---|
506 | }
|
---|
507 | }
|
---|
508 |
|
---|
509 | @Override
|
---|
510 | public void paint(Graphics2D g, MapView mv, Bounds bounds) {
|
---|
511 | int width = mv.getWidth();
|
---|
512 | int height = mv.getHeight();
|
---|
513 | Rectangle clip = g.getClipBounds();
|
---|
514 | if (useThumbs) {
|
---|
515 | if (!thumbsLoaded) {
|
---|
516 | startLoadThumbs();
|
---|
517 | }
|
---|
518 |
|
---|
519 | if (null == offscreenBuffer || offscreenBuffer.getWidth() != width // reuse the old buffer if possible
|
---|
520 | || offscreenBuffer.getHeight() != height) {
|
---|
521 | offscreenBuffer = new BufferedImage(width, height,
|
---|
522 | BufferedImage.TYPE_INT_ARGB);
|
---|
523 | updateOffscreenBuffer = true;
|
---|
524 | }
|
---|
525 |
|
---|
526 | if (updateOffscreenBuffer) {
|
---|
527 | Graphics2D tempG = offscreenBuffer.createGraphics();
|
---|
528 | tempG.setColor(new Color(0, 0, 0, 0));
|
---|
529 | Composite saveComp = tempG.getComposite();
|
---|
530 | tempG.setComposite(AlphaComposite.Clear); // remove the old images
|
---|
531 | tempG.fillRect(0, 0, width, height);
|
---|
532 | tempG.setComposite(saveComp);
|
---|
533 |
|
---|
534 | if (data != null) {
|
---|
535 | for (ImageEntry e : data) {
|
---|
536 | paintImage(e, mv, clip, tempG);
|
---|
537 | }
|
---|
538 | if (currentPhoto >= 0 && currentPhoto < data.size()) {
|
---|
539 | // Make sure the selected image is on top in case multiple images overlap.
|
---|
540 | paintImage(data.get(currentPhoto), mv, clip, tempG);
|
---|
541 | }
|
---|
542 | }
|
---|
543 | updateOffscreenBuffer = false;
|
---|
544 | }
|
---|
545 | g.drawImage(offscreenBuffer, 0, 0, null);
|
---|
546 | } else if (data != null) {
|
---|
547 | for (ImageEntry e : data) {
|
---|
548 | if (e.getPos() == null) {
|
---|
549 | continue;
|
---|
550 | }
|
---|
551 | Point p = mv.getPoint(e.getPos());
|
---|
552 | icon.paintIcon(mv, g,
|
---|
553 | p.x - icon.getIconWidth() / 2,
|
---|
554 | p.y - icon.getIconHeight() / 2);
|
---|
555 | }
|
---|
556 | }
|
---|
557 |
|
---|
558 | if (currentPhoto >= 0 && currentPhoto < data.size()) {
|
---|
559 | ImageEntry e = data.get(currentPhoto);
|
---|
560 |
|
---|
561 | if (e.getPos() != null) {
|
---|
562 | Point p = mv.getPoint(e.getPos());
|
---|
563 |
|
---|
564 | int imgWidth;
|
---|
565 | int imgHeight;
|
---|
566 | if (useThumbs && e.hasThumbnail()) {
|
---|
567 | Dimension d = scaledDimension(e.getThumbnail());
|
---|
568 | if (d != null) {
|
---|
569 | imgWidth = d.width;
|
---|
570 | imgHeight = d.height;
|
---|
571 | } else {
|
---|
572 | imgWidth = -1;
|
---|
573 | imgHeight = -1;
|
---|
574 | }
|
---|
575 | } else {
|
---|
576 | imgWidth = selectedIcon.getIconWidth();
|
---|
577 | imgHeight = selectedIcon.getIconHeight();
|
---|
578 | }
|
---|
579 |
|
---|
580 | if (e.getExifImgDir() != null) {
|
---|
581 | // Multiplier must be larger than sqrt(2)/2=0.71.
|
---|
582 | double arrowlength = Math.max(25, Math.max(imgWidth, imgHeight) * 0.85);
|
---|
583 | double arrowwidth = arrowlength / 1.4;
|
---|
584 |
|
---|
585 | double dir = e.getExifImgDir();
|
---|
586 | // Rotate 90 degrees CCW
|
---|
587 | double headdir = (dir < 90) ? dir + 270 : dir - 90;
|
---|
588 | double leftdir = (headdir < 90) ? headdir + 270 : headdir - 90;
|
---|
589 | double rightdir = (headdir > 270) ? headdir - 270 : headdir + 90;
|
---|
590 |
|
---|
591 | double ptx = p.x + Math.cos(Utils.toRadians(headdir)) * arrowlength;
|
---|
592 | double pty = p.y + Math.sin(Utils.toRadians(headdir)) * arrowlength;
|
---|
593 |
|
---|
594 | double ltx = p.x + Math.cos(Utils.toRadians(leftdir)) * arrowwidth/2;
|
---|
595 | double lty = p.y + Math.sin(Utils.toRadians(leftdir)) * arrowwidth/2;
|
---|
596 |
|
---|
597 | double rtx = p.x + Math.cos(Utils.toRadians(rightdir)) * arrowwidth/2;
|
---|
598 | double rty = p.y + Math.sin(Utils.toRadians(rightdir)) * arrowwidth/2;
|
---|
599 |
|
---|
600 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
---|
601 | g.setColor(new Color(255, 255, 255, 192));
|
---|
602 | int[] xar = {(int) ltx, (int) ptx, (int) rtx, (int) ltx};
|
---|
603 | int[] yar = {(int) lty, (int) pty, (int) rty, (int) lty};
|
---|
604 | g.fillPolygon(xar, yar, 4);
|
---|
605 | g.setColor(Color.black);
|
---|
606 | g.setStroke(new BasicStroke(1.2f));
|
---|
607 | g.drawPolyline(xar, yar, 3);
|
---|
608 | }
|
---|
609 |
|
---|
610 | if (useThumbs && e.hasThumbnail()) {
|
---|
611 | g.setColor(new Color(128, 0, 0, 122));
|
---|
612 | g.fillRect(p.x - imgWidth / 2, p.y - imgHeight / 2, imgWidth, imgHeight);
|
---|
613 | } else {
|
---|
614 | selectedIcon.paintIcon(mv, g,
|
---|
615 | p.x - imgWidth / 2,
|
---|
616 | p.y - imgHeight / 2);
|
---|
617 |
|
---|
618 | }
|
---|
619 | }
|
---|
620 | }
|
---|
621 | }
|
---|
622 |
|
---|
623 | @Override
|
---|
624 | public void visitBoundingBox(BoundingXYVisitor v) {
|
---|
625 | for (ImageEntry e : data) {
|
---|
626 | v.visit(e.getPos());
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | /**
|
---|
631 | * Show current photo on map and in image viewer.
|
---|
632 | */
|
---|
633 | public void showCurrentPhoto() {
|
---|
634 | clearOtherCurrentPhotos();
|
---|
635 | if (currentPhoto >= 0) {
|
---|
636 | ImageViewerDialog.showImage(this, data.get(currentPhoto));
|
---|
637 | } else {
|
---|
638 | ImageViewerDialog.showImage(this, null);
|
---|
639 | }
|
---|
640 | updateOffscreenBuffer = true;
|
---|
641 | Main.map.repaint();
|
---|
642 | }
|
---|
643 |
|
---|
644 | /**
|
---|
645 | * Shows next photo.
|
---|
646 | */
|
---|
647 | public void showNextPhoto() {
|
---|
648 | if (data != null && !data.isEmpty()) {
|
---|
649 | currentPhoto++;
|
---|
650 | if (currentPhoto >= data.size()) {
|
---|
651 | currentPhoto = data.size() - 1;
|
---|
652 | }
|
---|
653 | } else {
|
---|
654 | currentPhoto = -1;
|
---|
655 | }
|
---|
656 | showCurrentPhoto();
|
---|
657 | }
|
---|
658 |
|
---|
659 | /**
|
---|
660 | * Shows previous photo.
|
---|
661 | */
|
---|
662 | public void showPreviousPhoto() {
|
---|
663 | if (data != null && !data.isEmpty()) {
|
---|
664 | currentPhoto--;
|
---|
665 | if (currentPhoto < 0) {
|
---|
666 | currentPhoto = 0;
|
---|
667 | }
|
---|
668 | } else {
|
---|
669 | currentPhoto = -1;
|
---|
670 | }
|
---|
671 | showCurrentPhoto();
|
---|
672 | }
|
---|
673 |
|
---|
674 | /**
|
---|
675 | * Shows first photo.
|
---|
676 | */
|
---|
677 | public void showFirstPhoto() {
|
---|
678 | if (data != null && !data.isEmpty()) {
|
---|
679 | currentPhoto = 0;
|
---|
680 | } else {
|
---|
681 | currentPhoto = -1;
|
---|
682 | }
|
---|
683 | showCurrentPhoto();
|
---|
684 | }
|
---|
685 |
|
---|
686 | /**
|
---|
687 | * Shows last photo.
|
---|
688 | */
|
---|
689 | public void showLastPhoto() {
|
---|
690 | if (data != null && !data.isEmpty()) {
|
---|
691 | currentPhoto = data.size() - 1;
|
---|
692 | } else {
|
---|
693 | currentPhoto = -1;
|
---|
694 | }
|
---|
695 | showCurrentPhoto();
|
---|
696 | }
|
---|
697 |
|
---|
698 | public void checkPreviousNextButtons() {
|
---|
699 | ImageViewerDialog.setNextEnabled(data != null && currentPhoto < data.size() - 1);
|
---|
700 | ImageViewerDialog.setPreviousEnabled(currentPhoto > 0);
|
---|
701 | }
|
---|
702 |
|
---|
703 | public void removeCurrentPhoto() {
|
---|
704 | if (data != null && !data.isEmpty() && currentPhoto >= 0 && currentPhoto < data.size()) {
|
---|
705 | data.remove(currentPhoto);
|
---|
706 | if (currentPhoto >= data.size()) {
|
---|
707 | currentPhoto = data.size() - 1;
|
---|
708 | }
|
---|
709 | showCurrentPhoto();
|
---|
710 | }
|
---|
711 | }
|
---|
712 |
|
---|
713 | public void removeCurrentPhotoFromDisk() {
|
---|
714 | ImageEntry toDelete;
|
---|
715 | if (data != null && !data.isEmpty() && currentPhoto >= 0 && currentPhoto < data.size()) {
|
---|
716 | toDelete = data.get(currentPhoto);
|
---|
717 |
|
---|
718 | int result = new ExtendedDialog(
|
---|
719 | Main.parent,
|
---|
720 | tr("Delete image file from disk"),
|
---|
721 | tr("Cancel"), tr("Delete"))
|
---|
722 | .setButtonIcons("cancel", "dialogs/delete")
|
---|
723 | .setContent(new JLabel(tr("<html><h3>Delete the file {0} from disk?<p>The image file will be permanently lost!</h3></html>",
|
---|
724 | toDelete.getFile().getName()), ImageProvider.get("dialogs/geoimage/deletefromdisk"), SwingConstants.LEFT))
|
---|
725 | .toggleEnable("geoimage.deleteimagefromdisk")
|
---|
726 | .setCancelButton(1)
|
---|
727 | .setDefaultButton(2)
|
---|
728 | .showDialog()
|
---|
729 | .getValue();
|
---|
730 |
|
---|
731 | if (result == 2) {
|
---|
732 | data.remove(currentPhoto);
|
---|
733 | if (currentPhoto >= data.size()) {
|
---|
734 | currentPhoto = data.size() - 1;
|
---|
735 | }
|
---|
736 |
|
---|
737 | if (Utils.deleteFile(toDelete.getFile())) {
|
---|
738 | Main.info("File "+toDelete.getFile()+" deleted. ");
|
---|
739 | } else {
|
---|
740 | JOptionPane.showMessageDialog(
|
---|
741 | Main.parent,
|
---|
742 | tr("Image file could not be deleted."),
|
---|
743 | tr("Error"),
|
---|
744 | JOptionPane.ERROR_MESSAGE
|
---|
745 | );
|
---|
746 | }
|
---|
747 |
|
---|
748 | showCurrentPhoto();
|
---|
749 | }
|
---|
750 | }
|
---|
751 | }
|
---|
752 |
|
---|
753 | public void copyCurrentPhotoPath() {
|
---|
754 | if (data != null && !data.isEmpty() && currentPhoto >= 0 && currentPhoto < data.size()) {
|
---|
755 | ClipboardUtils.copyString(data.get(currentPhoto).getFile().toString());
|
---|
756 | }
|
---|
757 | }
|
---|
758 |
|
---|
759 | /**
|
---|
760 | * Removes a photo from the list of images by index.
|
---|
761 | * @param idx Image index
|
---|
762 | * @since 6392
|
---|
763 | */
|
---|
764 | public void removePhotoByIdx(int idx) {
|
---|
765 | if (idx >= 0 && data != null && idx < data.size()) {
|
---|
766 | data.remove(idx);
|
---|
767 | }
|
---|
768 | }
|
---|
769 |
|
---|
770 | /**
|
---|
771 | * Check if the position of the mouse event is within the rectangle of the photo icon or thumbnail.
|
---|
772 | * @param idx Image index, range 0 .. size-1
|
---|
773 | * @param evt Mouse event
|
---|
774 | * @return {@code true} if the photo matches the mouse position, {@code false} otherwise
|
---|
775 | */
|
---|
776 | private boolean isPhotoIdxUnderMouse(int idx, MouseEvent evt) {
|
---|
777 | if (idx >= 0 && data != null && idx < data.size()) {
|
---|
778 | ImageEntry img = data.get(idx);
|
---|
779 | if (img.getPos() != null) {
|
---|
780 | Point imgCenter = Main.map.mapView.getPoint(img.getPos());
|
---|
781 | Rectangle imgRect;
|
---|
782 | if (useThumbs && img.hasThumbnail()) {
|
---|
783 | Dimension imgDim = scaledDimension(img.getThumbnail());
|
---|
784 | if (imgDim != null) {
|
---|
785 | imgRect = new Rectangle(imgCenter.x - imgDim.width / 2,
|
---|
786 | imgCenter.y - imgDim.height / 2,
|
---|
787 | imgDim.width, imgDim.height);
|
---|
788 | } else {
|
---|
789 | imgRect = null;
|
---|
790 | }
|
---|
791 | } else {
|
---|
792 | imgRect = new Rectangle(imgCenter.x - icon.getIconWidth() / 2,
|
---|
793 | imgCenter.y - icon.getIconHeight() / 2,
|
---|
794 | icon.getIconWidth(), icon.getIconHeight());
|
---|
795 | }
|
---|
796 | if (imgRect != null && imgRect.contains(evt.getPoint())) {
|
---|
797 | return true;
|
---|
798 | }
|
---|
799 | }
|
---|
800 | }
|
---|
801 | return false;
|
---|
802 | }
|
---|
803 |
|
---|
804 | /**
|
---|
805 | * Returns index of the image that matches the position of the mouse event.
|
---|
806 | * @param evt Mouse event
|
---|
807 | * @param cycle Set to {@code true} to cycle through the photos at the
|
---|
808 | * current mouse position if multiple icons or thumbnails overlap.
|
---|
809 | * If set to {@code false} the topmost photo will be used.
|
---|
810 | * @return Image index at mouse position, range 0 .. size-1,
|
---|
811 | * or {@code -1} if there is no image at the mouse position
|
---|
812 | */
|
---|
813 | private int getPhotoIdxUnderMouse(MouseEvent evt, boolean cycle) {
|
---|
814 | if (data != null) {
|
---|
815 | if (cycle && currentPhoto >= 0) {
|
---|
816 | // Cycle loop is forward as that is the natural order.
|
---|
817 | // Loop 1: One after current photo up to last one.
|
---|
818 | for (int idx = currentPhoto + 1; idx < data.size(); ++idx) {
|
---|
819 | if (isPhotoIdxUnderMouse(idx, evt)) {
|
---|
820 | return idx;
|
---|
821 | }
|
---|
822 | }
|
---|
823 | // Loop 2: First photo up to current one.
|
---|
824 | for (int idx = 0; idx <= currentPhoto; ++idx) {
|
---|
825 | if (isPhotoIdxUnderMouse(idx, evt)) {
|
---|
826 | return idx;
|
---|
827 | }
|
---|
828 | }
|
---|
829 | } else {
|
---|
830 | // Check for current photo first, i.e. keep it selected if it is under the mouse.
|
---|
831 | if (currentPhoto >= 0 && isPhotoIdxUnderMouse(currentPhoto, evt)) {
|
---|
832 | return currentPhoto;
|
---|
833 | }
|
---|
834 | // Loop from last to first to prefer topmost image.
|
---|
835 | for (int idx = data.size() - 1; idx >= 0; --idx) {
|
---|
836 | if (isPhotoIdxUnderMouse(idx, evt)) {
|
---|
837 | return idx;
|
---|
838 | }
|
---|
839 | }
|
---|
840 | }
|
---|
841 | }
|
---|
842 | return -1;
|
---|
843 | }
|
---|
844 |
|
---|
845 | /**
|
---|
846 | * Returns index of the image that matches the position of the mouse event.
|
---|
847 | * The topmost photo is picked if multiple icons or thumbnails overlap.
|
---|
848 | * @param evt Mouse event
|
---|
849 | * @return Image index at mouse position, range 0 .. size-1,
|
---|
850 | * or {@code -1} if there is no image at the mouse position
|
---|
851 | */
|
---|
852 | private int getPhotoIdxUnderMouse(MouseEvent evt) {
|
---|
853 | return getPhotoIdxUnderMouse(evt, false);
|
---|
854 | }
|
---|
855 |
|
---|
856 | /**
|
---|
857 | * Returns the image that matches the position of the mouse event.
|
---|
858 | * The topmost photo is picked of multiple icons or thumbnails overlap.
|
---|
859 | * @param evt Mouse event
|
---|
860 | * @return Image at mouse position, or {@code null} if there is no image at the mouse position
|
---|
861 | * @since 6392
|
---|
862 | */
|
---|
863 | public ImageEntry getPhotoUnderMouse(MouseEvent evt) {
|
---|
864 | int idx = getPhotoIdxUnderMouse(evt);
|
---|
865 | if (idx >= 0) {
|
---|
866 | return data.get(idx);
|
---|
867 | } else {
|
---|
868 | return null;
|
---|
869 | }
|
---|
870 | }
|
---|
871 |
|
---|
872 | /**
|
---|
873 | * Clears the currentPhoto, i.e. remove select marker, and optionally repaint.
|
---|
874 | * @param repaint Repaint flag
|
---|
875 | * @since 6392
|
---|
876 | */
|
---|
877 | public void clearCurrentPhoto(boolean repaint) {
|
---|
878 | currentPhoto = -1;
|
---|
879 | if (repaint) {
|
---|
880 | updateBufferAndRepaint();
|
---|
881 | }
|
---|
882 | }
|
---|
883 |
|
---|
884 | /**
|
---|
885 | * Clears the currentPhoto of the other GeoImageLayer's. Otherwise there could be multiple selected photos.
|
---|
886 | */
|
---|
887 | private void clearOtherCurrentPhotos() {
|
---|
888 | for (GeoImageLayer layer:
|
---|
889 | Main.getLayerManager().getLayersOfType(GeoImageLayer.class)) {
|
---|
890 | if (layer != this) {
|
---|
891 | layer.clearCurrentPhoto(false);
|
---|
892 | }
|
---|
893 | }
|
---|
894 | }
|
---|
895 |
|
---|
896 | /**
|
---|
897 | * Registers a map mode for which the functionality of this layer should be available.
|
---|
898 | * @param mapMode Map mode to be registered
|
---|
899 | * @since 6392
|
---|
900 | */
|
---|
901 | public static void registerSupportedMapMode(MapMode mapMode) {
|
---|
902 | if (supportedMapModes == null) {
|
---|
903 | supportedMapModes = new ArrayList<>();
|
---|
904 | }
|
---|
905 | supportedMapModes.add(mapMode);
|
---|
906 | }
|
---|
907 |
|
---|
908 | /**
|
---|
909 | * Determines if the functionality of this layer is available in
|
---|
910 | * the specified map mode. {@link SelectAction} and {@link LassoModeAction} are supported by default,
|
---|
911 | * other map modes can be registered.
|
---|
912 | * @param mapMode Map mode to be checked
|
---|
913 | * @return {@code true} if the map mode is supported,
|
---|
914 | * {@code false} otherwise
|
---|
915 | */
|
---|
916 | private static boolean isSupportedMapMode(MapMode mapMode) {
|
---|
917 | if (mapMode instanceof SelectAction || mapMode instanceof LassoModeAction) {
|
---|
918 | return true;
|
---|
919 | }
|
---|
920 | if (supportedMapModes != null) {
|
---|
921 | for (MapMode supmmode: supportedMapModes) {
|
---|
922 | if (mapMode == supmmode) {
|
---|
923 | return true;
|
---|
924 | }
|
---|
925 | }
|
---|
926 | }
|
---|
927 | return false;
|
---|
928 | }
|
---|
929 |
|
---|
930 | @Override
|
---|
931 | public void hookUpMapView() {
|
---|
932 | mouseAdapter = new MouseAdapter() {
|
---|
933 | private boolean isMapModeOk() {
|
---|
934 | return Main.map.mapMode == null || isSupportedMapMode(Main.map.mapMode);
|
---|
935 | }
|
---|
936 |
|
---|
937 | @Override
|
---|
938 | public void mousePressed(MouseEvent e) {
|
---|
939 | if (e.getButton() != MouseEvent.BUTTON1)
|
---|
940 | return;
|
---|
941 | if (isVisible() && isMapModeOk()) {
|
---|
942 | Main.map.mapView.repaint();
|
---|
943 | cycleModeArmed = true;
|
---|
944 | }
|
---|
945 | }
|
---|
946 |
|
---|
947 | @Override
|
---|
948 | public void mouseReleased(MouseEvent ev) {
|
---|
949 | if (ev.getButton() != MouseEvent.BUTTON1)
|
---|
950 | return;
|
---|
951 | if (data == null || !isVisible() || !isMapModeOk())
|
---|
952 | return;
|
---|
953 |
|
---|
954 | Point mousePos = ev.getPoint();
|
---|
955 | boolean cycle = cycleModeArmed && lastSelPos != null && lastSelPos.equals(mousePos);
|
---|
956 | int idx = getPhotoIdxUnderMouse(ev, cycle);
|
---|
957 | if (idx >= 0) {
|
---|
958 | lastSelPos = mousePos;
|
---|
959 | cycleModeArmed = false;
|
---|
960 | currentPhoto = idx;
|
---|
961 | showCurrentPhoto();
|
---|
962 | }
|
---|
963 | }
|
---|
964 | };
|
---|
965 |
|
---|
966 | mouseMotionAdapter = new MouseMotionAdapter() {
|
---|
967 | @Override
|
---|
968 | public void mouseMoved(MouseEvent evt) {
|
---|
969 | lastSelPos = null;
|
---|
970 | }
|
---|
971 |
|
---|
972 | @Override
|
---|
973 | public void mouseDragged(MouseEvent evt) {
|
---|
974 | lastSelPos = null;
|
---|
975 | }
|
---|
976 | };
|
---|
977 |
|
---|
978 | mapModeListener = (oldMapMode, newMapMode) -> {
|
---|
979 | if (newMapMode == null || isSupportedMapMode(newMapMode)) {
|
---|
980 | Main.map.mapView.addMouseListener(mouseAdapter);
|
---|
981 | Main.map.mapView.addMouseMotionListener(mouseMotionAdapter);
|
---|
982 | } else {
|
---|
983 | Main.map.mapView.removeMouseListener(mouseAdapter);
|
---|
984 | Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
|
---|
985 | }
|
---|
986 | };
|
---|
987 |
|
---|
988 | MapFrame.addMapModeChangeListener(mapModeListener);
|
---|
989 | mapModeListener.mapModeChange(null, Main.map.mapMode);
|
---|
990 |
|
---|
991 | Main.getLayerManager().addActiveLayerChangeListener(e -> {
|
---|
992 | if (Main.getLayerManager().getActiveLayer() == this) {
|
---|
993 | // only in select mode it is possible to click the images
|
---|
994 | Main.map.selectSelectTool(false);
|
---|
995 | }
|
---|
996 | });
|
---|
997 |
|
---|
998 | Main.getLayerManager().addLayerChangeListener(new LayerChangeListener() {
|
---|
999 | @Override
|
---|
1000 | public void layerAdded(LayerAddEvent e) {
|
---|
1001 | // Do nothing
|
---|
1002 | }
|
---|
1003 |
|
---|
1004 | @Override
|
---|
1005 | public void layerRemoving(LayerRemoveEvent e) {
|
---|
1006 | if (e.getRemovedLayer() == GeoImageLayer.this) {
|
---|
1007 | stopLoadThumbs();
|
---|
1008 | Main.map.mapView.removeMouseListener(mouseAdapter);
|
---|
1009 | Main.map.mapView.removeMouseMotionListener(mouseMotionAdapter);
|
---|
1010 | MapFrame.removeMapModeChangeListener(mapModeListener);
|
---|
1011 | currentPhoto = -1;
|
---|
1012 | if (data != null) {
|
---|
1013 | data.clear();
|
---|
1014 | }
|
---|
1015 | data = null;
|
---|
1016 | // stop listening to layer change events
|
---|
1017 | Main.getLayerManager().removeLayerChangeListener(this);
|
---|
1018 | }
|
---|
1019 | }
|
---|
1020 |
|
---|
1021 | @Override
|
---|
1022 | public void layerOrderChanged(LayerOrderChangeEvent e) {
|
---|
1023 | // Do nothing
|
---|
1024 | }
|
---|
1025 | });
|
---|
1026 |
|
---|
1027 | if (Main.map.getToggleDialog(ImageViewerDialog.class) == null) {
|
---|
1028 | ImageViewerDialog.newInstance();
|
---|
1029 | Main.map.addToggleDialog(ImageViewerDialog.getInstance());
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 |
|
---|
1033 | @Override
|
---|
1034 | public LayerPainter attachToMapView(MapViewEvent event) {
|
---|
1035 | MapView.addZoomChangeListener(this);
|
---|
1036 | return super.attachToMapView(event);
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | @Override
|
---|
1040 | public void zoomChanged() {
|
---|
1041 | updateOffscreenBuffer = true;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | /**
|
---|
1045 | * Start to load thumbnails.
|
---|
1046 | */
|
---|
1047 | public synchronized void startLoadThumbs() {
|
---|
1048 | if (useThumbs && !thumbsLoaded && !thumbsLoaderRunning) {
|
---|
1049 | stopLoadThumbs();
|
---|
1050 | thumbsloader = new ThumbsLoader(this);
|
---|
1051 | thumbsLoaderExecutor.submit(thumbsloader);
|
---|
1052 | thumbsLoaderRunning = true;
|
---|
1053 | }
|
---|
1054 | }
|
---|
1055 |
|
---|
1056 | /**
|
---|
1057 | * Stop to load thumbnails.
|
---|
1058 | *
|
---|
1059 | * Can be called at any time to make sure that the
|
---|
1060 | * thumbnail loader is stopped.
|
---|
1061 | */
|
---|
1062 | public synchronized void stopLoadThumbs() {
|
---|
1063 | if (thumbsloader != null) {
|
---|
1064 | thumbsloader.stop = true;
|
---|
1065 | }
|
---|
1066 | thumbsLoaderRunning = false;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Called to signal that the loading of thumbnails has finished.
|
---|
1071 | *
|
---|
1072 | * Usually called from {@link ThumbsLoader} in another thread.
|
---|
1073 | */
|
---|
1074 | public void thumbsLoaded() {
|
---|
1075 | thumbsLoaded = true;
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | public void updateBufferAndRepaint() {
|
---|
1079 | updateOffscreenBuffer = true;
|
---|
1080 | invalidate();
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | /**
|
---|
1084 | * Get list of images in layer.
|
---|
1085 | * @return List of images in layer
|
---|
1086 | */
|
---|
1087 | public List<ImageEntry> getImages() {
|
---|
1088 | return data == null ? Collections.<ImageEntry>emptyList() : new ArrayList<>(data);
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 | /**
|
---|
1092 | * Returns the associated GPX layer.
|
---|
1093 | * @return The associated GPX layer
|
---|
1094 | */
|
---|
1095 | public GpxLayer getGpxLayer() {
|
---|
1096 | return gpxLayer;
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | @Override
|
---|
1100 | public void jumpToNextMarker() {
|
---|
1101 | showNextPhoto();
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | @Override
|
---|
1105 | public void jumpToPreviousMarker() {
|
---|
1106 | showPreviousPhoto();
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 | /**
|
---|
1110 | * Returns the current thumbnail display status.
|
---|
1111 | * {@code true}: thumbnails are displayed, {@code false}: an icon is displayed instead of thumbnails.
|
---|
1112 | * @return Current thumbnail display status
|
---|
1113 | * @since 6392
|
---|
1114 | */
|
---|
1115 | public boolean isUseThumbs() {
|
---|
1116 | return useThumbs;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | /**
|
---|
1120 | * Enables or disables the display of thumbnails. Does not update the display.
|
---|
1121 | * @param useThumbs New thumbnail display status
|
---|
1122 | * @since 6392
|
---|
1123 | */
|
---|
1124 | public void setUseThumbs(boolean useThumbs) {
|
---|
1125 | this.useThumbs = useThumbs;
|
---|
1126 | if (useThumbs && !thumbsLoaded) {
|
---|
1127 | startLoadThumbs();
|
---|
1128 | } else if (!useThumbs) {
|
---|
1129 | stopLoadThumbs();
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 | }
|
---|