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