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