Skip to content

Commit

Permalink
see #16472 - allow to open geoimages into external viewer, useful for…
Browse files Browse the repository at this point in the history
… 360 images until we can display them in full resolution

git-svn-id: https://josm.openstreetmap.de/svn/trunk@18300 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
don-vip committed Nov 1, 2021
1 parent 242640a commit f77e9ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/images/external-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.Serializable;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.openstreetmap.josm.gui.util.imagery.Vector3D;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.PlatformManager;
import org.openstreetmap.josm.tools.Shortcut;
import org.openstreetmap.josm.tools.date.DateUtils;

Expand All @@ -79,6 +81,7 @@ public final class ImageViewerDialog extends ToggleDialog implements LayerChange
private final ImageFirstAction imageFirstAction = new ImageFirstAction();
private final ImageLastAction imageLastAction = new ImageLastAction();
private final ImageCopyPathAction imageCopyPathAction = new ImageCopyPathAction();
private final ImageOpenExternalAction imageOpenExternalAction = new ImageOpenExternalAction();
private final LayerVisibilityAction visibilityAction = new LayerVisibilityAction(Collections::emptyList,
() -> Collections.singleton(imageryFilterSettings));

Expand Down Expand Up @@ -114,6 +117,7 @@ public static ImageViewerDialog getInstance() {
private JButton btnCollapse;
private JButton btnDelete;
private JButton btnCopyPath;
private JButton btnOpenExternal;
private JButton btnDeleteFromDisk;
private JToggleButton tbCentre;

Expand Down Expand Up @@ -159,6 +163,7 @@ private void build() {
btnDelete = createButton(imageRemoveAction, buttonDim);
btnDeleteFromDisk = createButton(imageRemoveFromDiskAction, buttonDim);
btnCopyPath = createButton(imageCopyPathAction, buttonDim);
btnOpenExternal = createButton(imageOpenExternalAction, buttonDim);

btnNext = createNavigationButton(imageNextAction, buttonDim);
btnLast = createNavigationButton(imageLastAction, buttonDim);
Expand All @@ -185,6 +190,7 @@ private void build() {
buttons.add(btnDeleteFromDisk);
buttons.add(Box.createRigidArea(new Dimension(7, 0)));
buttons.add(btnCopyPath);
buttons.add(btnOpenExternal);
buttons.add(Box.createRigidArea(new Dimension(7, 0)));
buttons.add(createButton(visibilityAction, buttonDim));

Expand Down Expand Up @@ -219,6 +225,7 @@ public void destroy() {
imageCenterViewAction.destroy();
imageCollapseAction.destroy();
imageCopyPathAction.destroy();
imageOpenExternalAction.destroy();
imageRemoveAction.destroy();
imageRemoveFromDiskAction.destroy();
imageZoomAction.destroy();
Expand All @@ -229,6 +236,7 @@ public void destroy() {

/**
* This literally exists to silence sonarlint complaints.
* @param <I> the type of the operand and result of the operator
*/
@FunctionalInterface
private interface SerializableUnaryOperator<I> extends UnaryOperator<I>, Serializable {
Expand Down Expand Up @@ -493,6 +501,23 @@ public void actionPerformed(ActionEvent e) {
}
}

private class ImageOpenExternalAction extends JosmAction {
ImageOpenExternalAction() {
super(null, new ImageProvider("external-link"), tr("Open image in external viewer"), null, false, null, false);
}

@Override
public void actionPerformed(ActionEvent e) {
if (currentEntry != null) {
try {
PlatformManager.getPlatform().openUrl(currentEntry.getFile().toURI().toURL().toExternalForm());
} catch (IOException ex) {
Logging.error(ex);
}
}
}
}

/**
* Enables (or disables) the "Previous" button.
* @param value {@code true} to enable the button, {@code false} otherwise
Expand Down Expand Up @@ -604,6 +629,7 @@ private void updateButtonsNullEntry(List<IImageEntry<?>> entries) {
btnDelete.setEnabled(hasMultipleImages);
btnDeleteFromDisk.setEnabled(hasMultipleImages);
btnCopyPath.setEnabled(false);
btnOpenExternal.setEnabled(false);
if (hasMultipleImages) {
imgDisplay.setEmptyText(tr("Multiple images selected"));
btnFirst.setEnabled(!isFirstImageSelected(entries));
Expand Down Expand Up @@ -632,6 +658,7 @@ private void updateButtonsNonNullEntry(IImageEntry<?> entry, boolean imageChange
btnDelete.setEnabled(entry.isRemoveSupported());
btnDeleteFromDisk.setEnabled(entry.isDeleteSupported() && entry.isRemoveSupported());
btnCopyPath.setEnabled(true);
btnOpenExternal.setEnabled(true);

setTitle(tr("Geotagged Images") + (!entry.getDisplayName().isEmpty() ? " - " + entry.getDisplayName() : ""));
StringBuilder osd = new StringBuilder(entry.getDisplayName());
Expand Down

0 comments on commit f77e9ba

Please sign in to comment.