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 |
|
---|
6 | import java.awt.BorderLayout;
|
---|
7 | import java.awt.Component;
|
---|
8 | import java.awt.Dimension;
|
---|
9 | import java.awt.GridBagConstraints;
|
---|
10 | import java.awt.GridBagLayout;
|
---|
11 | import java.awt.event.ActionEvent;
|
---|
12 | import java.awt.event.KeyEvent;
|
---|
13 | import java.awt.event.WindowEvent;
|
---|
14 | import java.text.DateFormat;
|
---|
15 | import java.text.SimpleDateFormat;
|
---|
16 |
|
---|
17 | import javax.swing.Box;
|
---|
18 | import javax.swing.JButton;
|
---|
19 | import javax.swing.JPanel;
|
---|
20 | import javax.swing.JToggleButton;
|
---|
21 |
|
---|
22 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
23 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
24 | import org.openstreetmap.josm.gui.dialogs.DialogsPanel.Action;
|
---|
25 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
---|
26 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
27 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
|
---|
28 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
|
---|
29 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
|
---|
30 | import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
|
---|
31 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
|
---|
32 | import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
|
---|
33 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
34 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
35 | import org.openstreetmap.josm.tools.date.DateUtils;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Dialog to view and manipulate geo-tagged images from a {@link GeoImageLayer}.
|
---|
39 | */
|
---|
40 | public final class ImageViewerDialog extends ToggleDialog implements LayerChangeListener, ActiveLayerChangeListener {
|
---|
41 |
|
---|
42 | private final ImageZoomAction imageZoomAction = new ImageZoomAction();
|
---|
43 | private final ImageCenterViewAction imageCenterViewAction = new ImageCenterViewAction();
|
---|
44 | private final ImageNextAction imageNextAction = new ImageNextAction();
|
---|
45 | private final ImageRemoveAction imageRemoveAction = new ImageRemoveAction();
|
---|
46 | private final ImageRemoveFromDiskAction imageRemoveFromDiskAction = new ImageRemoveFromDiskAction();
|
---|
47 | private final ImagePreviousAction imagePreviousAction = new ImagePreviousAction();
|
---|
48 | private final ImageCollapseAction imageCollapseAction = new ImageCollapseAction();
|
---|
49 | private final ImageFirstAction imageFirstAction = new ImageFirstAction();
|
---|
50 | private final ImageLastAction imageLastAction = new ImageLastAction();
|
---|
51 | private final ImageCopyPathAction imageCopyPathAction = new ImageCopyPathAction();
|
---|
52 |
|
---|
53 | private final ImageDisplay imgDisplay = new ImageDisplay();
|
---|
54 | private boolean centerView;
|
---|
55 |
|
---|
56 | // Only one instance of that class is present at one time
|
---|
57 | private static volatile ImageViewerDialog dialog;
|
---|
58 |
|
---|
59 | private boolean collapseButtonClicked;
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Replies the unique instance of this dialog
|
---|
63 | * @return the unique instance
|
---|
64 | */
|
---|
65 | public static ImageViewerDialog getInstance() {
|
---|
66 | if (dialog == null)
|
---|
67 | dialog = new ImageViewerDialog();
|
---|
68 | return dialog;
|
---|
69 | }
|
---|
70 |
|
---|
71 | private JButton btnNext;
|
---|
72 | private JButton btnPrevious;
|
---|
73 | private JButton btnCollapse;
|
---|
74 | private JToggleButton tbCentre;
|
---|
75 |
|
---|
76 | private ImageViewerDialog() {
|
---|
77 | super(tr("Geotagged Images"), "geoimage", tr("Display geotagged images"), Shortcut.registerShortcut("tools:geotagged",
|
---|
78 | tr("Tool: {0}", tr("Display geotagged images")), KeyEvent.VK_Y, Shortcut.DIRECT), 200);
|
---|
79 | build();
|
---|
80 | MainApplication.getLayerManager().addActiveLayerChangeListener(this);
|
---|
81 | MainApplication.getLayerManager().addLayerChangeListener(this);
|
---|
82 | }
|
---|
83 |
|
---|
84 | private void build() {
|
---|
85 | JPanel content = new JPanel(new BorderLayout());
|
---|
86 |
|
---|
87 | content.add(imgDisplay, BorderLayout.CENTER);
|
---|
88 |
|
---|
89 | Dimension buttonDim = new Dimension(26, 26);
|
---|
90 |
|
---|
91 | btnPrevious = new JButton(imagePreviousAction);
|
---|
92 | btnPrevious.setPreferredSize(buttonDim);
|
---|
93 | btnPrevious.setEnabled(false);
|
---|
94 |
|
---|
95 | JButton btnDelete = new JButton(imageRemoveAction);
|
---|
96 | btnDelete.setPreferredSize(buttonDim);
|
---|
97 |
|
---|
98 | JButton btnDeleteFromDisk = new JButton(imageRemoveFromDiskAction);
|
---|
99 | btnDeleteFromDisk.setPreferredSize(buttonDim);
|
---|
100 |
|
---|
101 | JButton btnCopyPath = new JButton(imageCopyPathAction);
|
---|
102 | btnCopyPath.setPreferredSize(buttonDim);
|
---|
103 |
|
---|
104 | btnNext = new JButton(imageNextAction);
|
---|
105 | btnNext.setPreferredSize(buttonDim);
|
---|
106 | btnNext.setEnabled(false);
|
---|
107 |
|
---|
108 | tbCentre = new JToggleButton(imageCenterViewAction);
|
---|
109 | tbCentre.setPreferredSize(buttonDim);
|
---|
110 |
|
---|
111 | JButton btnZoomBestFit = new JButton(imageZoomAction);
|
---|
112 | btnZoomBestFit.setPreferredSize(buttonDim);
|
---|
113 |
|
---|
114 | btnCollapse = new JButton(imageCollapseAction);
|
---|
115 | btnCollapse.setPreferredSize(new Dimension(20, 20));
|
---|
116 | btnCollapse.setAlignmentY(Component.TOP_ALIGNMENT);
|
---|
117 |
|
---|
118 | JPanel buttons = new JPanel();
|
---|
119 | buttons.add(btnPrevious);
|
---|
120 | buttons.add(btnNext);
|
---|
121 | buttons.add(Box.createRigidArea(new Dimension(7, 0)));
|
---|
122 | buttons.add(tbCentre);
|
---|
123 | buttons.add(btnZoomBestFit);
|
---|
124 | buttons.add(Box.createRigidArea(new Dimension(7, 0)));
|
---|
125 | buttons.add(btnDelete);
|
---|
126 | buttons.add(btnDeleteFromDisk);
|
---|
127 | buttons.add(Box.createRigidArea(new Dimension(7, 0)));
|
---|
128 | buttons.add(btnCopyPath);
|
---|
129 |
|
---|
130 | JPanel bottomPane = new JPanel(new GridBagLayout());
|
---|
131 | GridBagConstraints gc = new GridBagConstraints();
|
---|
132 | gc.gridx = 0;
|
---|
133 | gc.gridy = 0;
|
---|
134 | gc.anchor = GridBagConstraints.CENTER;
|
---|
135 | gc.weightx = 1;
|
---|
136 | bottomPane.add(buttons, gc);
|
---|
137 |
|
---|
138 | gc.gridx = 1;
|
---|
139 | gc.gridy = 0;
|
---|
140 | gc.anchor = GridBagConstraints.PAGE_END;
|
---|
141 | gc.weightx = 0;
|
---|
142 | bottomPane.add(btnCollapse, gc);
|
---|
143 |
|
---|
144 | content.add(bottomPane, BorderLayout.SOUTH);
|
---|
145 |
|
---|
146 | createLayout(content, false, null);
|
---|
147 | }
|
---|
148 |
|
---|
149 | @Override
|
---|
150 | public void destroy() {
|
---|
151 | MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
|
---|
152 | MainApplication.getLayerManager().removeLayerChangeListener(this);
|
---|
153 | // Manually destroy actions until JButtons are replaced by standard SideButtons
|
---|
154 | imageFirstAction.destroy();
|
---|
155 | imageLastAction.destroy();
|
---|
156 | imagePreviousAction.destroy();
|
---|
157 | imageNextAction.destroy();
|
---|
158 | imageCenterViewAction.destroy();
|
---|
159 | imageCollapseAction.destroy();
|
---|
160 | imageCopyPathAction.destroy();
|
---|
161 | imageRemoveAction.destroy();
|
---|
162 | imageRemoveFromDiskAction.destroy();
|
---|
163 | imageZoomAction.destroy();
|
---|
164 | super.destroy();
|
---|
165 | dialog = null;
|
---|
166 | }
|
---|
167 |
|
---|
168 | private class ImageNextAction extends JosmAction {
|
---|
169 | ImageNextAction() {
|
---|
170 | super(null, new ImageProvider("dialogs", "next"), tr("Next"), Shortcut.registerShortcut(
|
---|
171 | "geoimage:next", tr("Geoimage: {0}", tr("Show next Image")), KeyEvent.VK_PAGE_DOWN, Shortcut.DIRECT),
|
---|
172 | false, null, false);
|
---|
173 | }
|
---|
174 |
|
---|
175 | @Override
|
---|
176 | public void actionPerformed(ActionEvent e) {
|
---|
177 | if (currentLayer != null) {
|
---|
178 | currentLayer.showNextPhoto();
|
---|
179 | }
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | private class ImagePreviousAction extends JosmAction {
|
---|
184 | ImagePreviousAction() {
|
---|
185 | super(null, new ImageProvider("dialogs", "previous"), tr("Previous"), Shortcut.registerShortcut(
|
---|
186 | "geoimage:previous", tr("Geoimage: {0}", tr("Show previous Image")), KeyEvent.VK_PAGE_UP, Shortcut.DIRECT),
|
---|
187 | false, null, false);
|
---|
188 | }
|
---|
189 |
|
---|
190 | @Override
|
---|
191 | public void actionPerformed(ActionEvent e) {
|
---|
192 | if (currentLayer != null) {
|
---|
193 | currentLayer.showPreviousPhoto();
|
---|
194 | }
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | private class ImageFirstAction extends JosmAction {
|
---|
199 | ImageFirstAction() {
|
---|
200 | super(null, (ImageProvider) null, null, Shortcut.registerShortcut(
|
---|
201 | "geoimage:first", tr("Geoimage: {0}", tr("Show first Image")), KeyEvent.VK_HOME, Shortcut.DIRECT),
|
---|
202 | false, null, false);
|
---|
203 | }
|
---|
204 |
|
---|
205 | @Override
|
---|
206 | public void actionPerformed(ActionEvent e) {
|
---|
207 | if (currentLayer != null) {
|
---|
208 | currentLayer.showFirstPhoto();
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|
212 |
|
---|
213 | private class ImageLastAction extends JosmAction {
|
---|
214 | ImageLastAction() {
|
---|
215 | super(null, (ImageProvider) null, null, Shortcut.registerShortcut(
|
---|
216 | "geoimage:last", tr("Geoimage: {0}", tr("Show last Image")), KeyEvent.VK_END, Shortcut.DIRECT),
|
---|
217 | false, null, false);
|
---|
218 | }
|
---|
219 |
|
---|
220 | @Override
|
---|
221 | public void actionPerformed(ActionEvent e) {
|
---|
222 | if (currentLayer != null) {
|
---|
223 | currentLayer.showLastPhoto();
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | private class ImageCenterViewAction extends JosmAction {
|
---|
229 | ImageCenterViewAction() {
|
---|
230 | super(null, new ImageProvider("dialogs", "centreview"), tr("Center view"), null,
|
---|
231 | false, null, false);
|
---|
232 | }
|
---|
233 |
|
---|
234 | @Override
|
---|
235 | public void actionPerformed(ActionEvent e) {
|
---|
236 | final JToggleButton button = (JToggleButton) e.getSource();
|
---|
237 | centerView = button.isEnabled() && button.isSelected();
|
---|
238 | if (centerView && currentEntry != null && currentEntry.getPos() != null) {
|
---|
239 | MainApplication.getMap().mapView.zoomTo(currentEntry.getPos());
|
---|
240 | }
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | private class ImageZoomAction extends JosmAction {
|
---|
245 | ImageZoomAction() {
|
---|
246 | super(null, new ImageProvider("dialogs", "zoom-best-fit"), tr("Zoom best fit and 1:1"), null,
|
---|
247 | false, null, false);
|
---|
248 | }
|
---|
249 |
|
---|
250 | @Override
|
---|
251 | public void actionPerformed(ActionEvent e) {
|
---|
252 | imgDisplay.zoomBestFitOrOne();
|
---|
253 | }
|
---|
254 | }
|
---|
255 |
|
---|
256 | private class ImageRemoveAction extends JosmAction {
|
---|
257 | ImageRemoveAction() {
|
---|
258 | super(null, new ImageProvider("dialogs", "delete"), tr("Remove photo from layer"), Shortcut.registerShortcut(
|
---|
259 | "geoimage:deleteimagefromlayer", tr("Geoimage: {0}", tr("Remove photo from layer")), KeyEvent.VK_DELETE, Shortcut.SHIFT),
|
---|
260 | false, null, false);
|
---|
261 | }
|
---|
262 |
|
---|
263 | @Override
|
---|
264 | public void actionPerformed(ActionEvent e) {
|
---|
265 | if (currentLayer != null) {
|
---|
266 | currentLayer.removeCurrentPhoto();
|
---|
267 | }
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | private class ImageRemoveFromDiskAction extends JosmAction {
|
---|
272 | ImageRemoveFromDiskAction() {
|
---|
273 | super(null, new ImageProvider("dialogs", "geoimage/deletefromdisk"), tr("Delete image file from disk"),
|
---|
274 | Shortcut.registerShortcut(
|
---|
275 | "geoimage:deletefilefromdisk", tr("Geoimage: {0}", tr("Delete File from disk")), KeyEvent.VK_DELETE, Shortcut.CTRL_SHIFT),
|
---|
276 | false, null, false);
|
---|
277 | }
|
---|
278 |
|
---|
279 | @Override
|
---|
280 | public void actionPerformed(ActionEvent e) {
|
---|
281 | if (currentLayer != null) {
|
---|
282 | currentLayer.removeCurrentPhotoFromDisk();
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | private class ImageCopyPathAction extends JosmAction {
|
---|
288 | ImageCopyPathAction() {
|
---|
289 | super(null, new ImageProvider("copy"), tr("Copy image path"), Shortcut.registerShortcut(
|
---|
290 | "geoimage:copypath", tr("Geoimage: {0}", tr("Copy image path")), KeyEvent.VK_C, Shortcut.ALT_CTRL_SHIFT),
|
---|
291 | false, null, false);
|
---|
292 | }
|
---|
293 |
|
---|
294 | @Override
|
---|
295 | public void actionPerformed(ActionEvent e) {
|
---|
296 | if (currentLayer != null) {
|
---|
297 | currentLayer.copyCurrentPhotoPath();
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | private class ImageCollapseAction extends JosmAction {
|
---|
303 | ImageCollapseAction() {
|
---|
304 | super(null, new ImageProvider("dialogs", "collapse"), tr("Move dialog to the side pane"), null,
|
---|
305 | false, null, false);
|
---|
306 | }
|
---|
307 |
|
---|
308 | @Override
|
---|
309 | public void actionPerformed(ActionEvent e) {
|
---|
310 | collapseButtonClicked = true;
|
---|
311 | detachedDialog.getToolkit().getSystemEventQueue().postEvent(new WindowEvent(detachedDialog, WindowEvent.WINDOW_CLOSING));
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | public static void showImage(GeoImageLayer layer, ImageEntry entry) {
|
---|
316 | getInstance().displayImage(layer, entry);
|
---|
317 | if (layer != null) {
|
---|
318 | layer.checkPreviousNextButtons();
|
---|
319 | } else {
|
---|
320 | setPreviousEnabled(false);
|
---|
321 | setNextEnabled(false);
|
---|
322 | }
|
---|
323 | }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Enables (or disables) the "Previous" button.
|
---|
327 | * @param value {@code true} to enable the button, {@code false} otherwise
|
---|
328 | */
|
---|
329 | public static void setPreviousEnabled(boolean value) {
|
---|
330 | getInstance().btnPrevious.setEnabled(value);
|
---|
331 | }
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Enables (or disables) the "Next" button.
|
---|
335 | * @param value {@code true} to enable the button, {@code false} otherwise
|
---|
336 | */
|
---|
337 | public static void setNextEnabled(boolean value) {
|
---|
338 | getInstance().btnNext.setEnabled(value);
|
---|
339 | }
|
---|
340 |
|
---|
341 | /**
|
---|
342 | * Enables (or disables) the "Center view" button.
|
---|
343 | * @param value {@code true} to enable the button, {@code false} otherwise
|
---|
344 | * @return the old enabled value. Can be used to restore the original enable state
|
---|
345 | */
|
---|
346 | public static synchronized boolean setCentreEnabled(boolean value) {
|
---|
347 | final ImageViewerDialog instance = getInstance();
|
---|
348 | final boolean wasEnabled = instance.tbCentre.isEnabled();
|
---|
349 | instance.tbCentre.setEnabled(value);
|
---|
350 | instance.tbCentre.getAction().actionPerformed(new ActionEvent(instance.tbCentre, 0, null));
|
---|
351 | return wasEnabled;
|
---|
352 | }
|
---|
353 |
|
---|
354 | private transient GeoImageLayer currentLayer;
|
---|
355 | private transient ImageEntry currentEntry;
|
---|
356 |
|
---|
357 | public void displayImage(GeoImageLayer layer, ImageEntry entry) {
|
---|
358 | boolean imageChanged;
|
---|
359 |
|
---|
360 | synchronized (this) {
|
---|
361 | // TODO: pop up image dialog but don't load image again
|
---|
362 |
|
---|
363 | imageChanged = currentEntry != entry;
|
---|
364 |
|
---|
365 | if (centerView && entry != null && MainApplication.isDisplayingMapView() && entry.getPos() != null) {
|
---|
366 | MainApplication.getMap().mapView.zoomTo(entry.getPos());
|
---|
367 | }
|
---|
368 |
|
---|
369 | currentLayer = layer;
|
---|
370 | currentEntry = entry;
|
---|
371 | }
|
---|
372 |
|
---|
373 | if (entry != null) {
|
---|
374 | if (imageChanged) {
|
---|
375 | // Set only if the image is new to preserve zoom and position if the same image is redisplayed
|
---|
376 | // (e.g. to update the OSD).
|
---|
377 | imgDisplay.setImage(entry);
|
---|
378 | }
|
---|
379 | setTitle(tr("Geotagged Images") + (entry.getFile() != null ? " - " + entry.getFile().getName() : ""));
|
---|
380 | StringBuilder osd = new StringBuilder(entry.getFile() != null ? entry.getFile().getName() : "");
|
---|
381 | if (entry.getElevation() != null) {
|
---|
382 | osd.append(tr("\nAltitude: {0} m", Math.round(entry.getElevation())));
|
---|
383 | }
|
---|
384 | if (entry.getSpeed() != null) {
|
---|
385 | osd.append(tr("\nSpeed: {0} km/h", Math.round(entry.getSpeed())));
|
---|
386 | }
|
---|
387 | if (entry.getExifImgDir() != null) {
|
---|
388 | osd.append(tr("\nDirection {0}\u00b0", Math.round(entry.getExifImgDir())));
|
---|
389 | }
|
---|
390 | DateFormat dtf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM);
|
---|
391 | // Make sure date/time format includes milliseconds
|
---|
392 | if (dtf instanceof SimpleDateFormat) {
|
---|
393 | String pattern = ((SimpleDateFormat) dtf).toPattern();
|
---|
394 | if (!pattern.contains(".SSS")) {
|
---|
395 | dtf = new SimpleDateFormat(pattern.replace(":ss", ":ss.SSS"));
|
---|
396 | }
|
---|
397 | }
|
---|
398 | if (entry.hasExifTime()) {
|
---|
399 | osd.append(tr("\nEXIF time: {0}", dtf.format(entry.getExifTime())));
|
---|
400 | }
|
---|
401 | if (entry.hasGpsTime()) {
|
---|
402 | osd.append(tr("\nGPS time: {0}", dtf.format(entry.getGpsTime())));
|
---|
403 | }
|
---|
404 |
|
---|
405 | imgDisplay.setOsdText(osd.toString());
|
---|
406 | } else {
|
---|
407 | // if this method is called to reinitialize dialog content with a blank image,
|
---|
408 | // do not actually show the dialog again with a blank image if currently hidden (fix #10672)
|
---|
409 | setTitle(tr("Geotagged Images"));
|
---|
410 | imgDisplay.setImage(null);
|
---|
411 | imgDisplay.setOsdText("");
|
---|
412 | return;
|
---|
413 | }
|
---|
414 | if (!isDialogShowing()) {
|
---|
415 | setIsDocked(false); // always open a detached window when an image is clicked and dialog is closed
|
---|
416 | showDialog();
|
---|
417 | } else {
|
---|
418 | if (isDocked && isCollapsed) {
|
---|
419 | expand();
|
---|
420 | dialogsPanel.reconstruct(Action.COLLAPSED_TO_DEFAULT, this);
|
---|
421 | }
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | /**
|
---|
426 | * When an image is closed, really close it and do not pop
|
---|
427 | * up the side dialog.
|
---|
428 | */
|
---|
429 | @Override
|
---|
430 | protected boolean dockWhenClosingDetachedDlg() {
|
---|
431 | if (collapseButtonClicked) {
|
---|
432 | collapseButtonClicked = false;
|
---|
433 | return true;
|
---|
434 | }
|
---|
435 | return false;
|
---|
436 | }
|
---|
437 |
|
---|
438 | @Override
|
---|
439 | protected void stateChanged() {
|
---|
440 | super.stateChanged();
|
---|
441 | if (btnCollapse != null) {
|
---|
442 | btnCollapse.setVisible(!isDocked);
|
---|
443 | }
|
---|
444 | }
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * Returns whether an image is currently displayed
|
---|
448 | * @return If image is currently displayed
|
---|
449 | */
|
---|
450 | public boolean hasImage() {
|
---|
451 | return currentEntry != null;
|
---|
452 | }
|
---|
453 |
|
---|
454 | /**
|
---|
455 | * Returns the currently displayed image.
|
---|
456 | * @return Currently displayed image or {@code null}
|
---|
457 | * @since 6392
|
---|
458 | */
|
---|
459 | public static ImageEntry getCurrentImage() {
|
---|
460 | return getInstance().currentEntry;
|
---|
461 | }
|
---|
462 |
|
---|
463 | /**
|
---|
464 | * Returns the layer associated with the image.
|
---|
465 | * @return Layer associated with the image
|
---|
466 | * @since 6392
|
---|
467 | */
|
---|
468 | public static GeoImageLayer getCurrentLayer() {
|
---|
469 | return getInstance().currentLayer;
|
---|
470 | }
|
---|
471 |
|
---|
472 | /**
|
---|
473 | * Returns whether the center view is currently active.
|
---|
474 | * @return {@code true} if the center view is active, {@code false} otherwise
|
---|
475 | * @since 9416
|
---|
476 | */
|
---|
477 | public static boolean isCenterView() {
|
---|
478 | return getInstance().centerView;
|
---|
479 | }
|
---|
480 |
|
---|
481 | @Override
|
---|
482 | public void layerAdded(LayerAddEvent e) {
|
---|
483 | showLayer(e.getAddedLayer());
|
---|
484 | }
|
---|
485 |
|
---|
486 | @Override
|
---|
487 | public void layerRemoving(LayerRemoveEvent e) {
|
---|
488 | // Clear current image and layer if current layer is deleted
|
---|
489 | if (currentLayer != null && currentLayer.equals(e.getRemovedLayer())) {
|
---|
490 | showImage(null, null);
|
---|
491 | }
|
---|
492 | // Check buttons state in case of layer merging
|
---|
493 | if (currentLayer != null && e.getRemovedLayer() instanceof GeoImageLayer) {
|
---|
494 | currentLayer.checkPreviousNextButtons();
|
---|
495 | }
|
---|
496 | }
|
---|
497 |
|
---|
498 | @Override
|
---|
499 | public void layerOrderChanged(LayerOrderChangeEvent e) {
|
---|
500 | // ignored
|
---|
501 | }
|
---|
502 |
|
---|
503 | @Override
|
---|
504 | public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
|
---|
505 | showLayer(e.getSource().getActiveLayer());
|
---|
506 | }
|
---|
507 |
|
---|
508 | private void showLayer(Layer newLayer) {
|
---|
509 | if (currentLayer == null && newLayer instanceof GeoImageLayer) {
|
---|
510 | ((GeoImageLayer) newLayer).showFirstPhoto();
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|