Skip to content

Commit

Permalink
Add shortcuts to actions in 'Image info' dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <tsmock@meta.com>
  • Loading branch information
tsmock committed Jul 9, 2024
1 parent 7616a87 commit 3ab8956
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.Serial;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import org.openstreetmap.josm.command.ChangePropertyCommand;
Expand All @@ -14,11 +17,13 @@
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.geoimage.ImageViewerDialog;
import org.openstreetmap.josm.plugins.mapillary.gui.layer.geoimage.MapillaryImageEntry;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
import org.openstreetmap.josm.tools.Shortcut;

public class AddTagToPrimitiveAction extends AbstractAction {
/**
* Add the mapillary tag to a primitive
*/
public class AddTagToPrimitiveAction extends MapillaryAction {
@Serial
private static final long serialVersionUID = 4834918715956633953L;

private Tag tag;
Expand All @@ -30,7 +35,10 @@ public class AddTagToPrimitiveAction extends AbstractAction {
* @param name The name to use
*/
public AddTagToPrimitiveAction(final String name) {
super(name, ImageProvider.get("dialogs/add", ImageSizes.SMALLICON));
super(name, "dialogs/add", tr("Add the mapillary source tag to the selected primitive"),
Shortcut.registerShortcut("mapillary:add_tag_to_primitive", tr("Mapillary: Add Tag to Primitive"),
KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
false, "mapillary:add_tag_to_primitive", false);
this.updateEnabled();
}

Expand Down Expand Up @@ -63,21 +71,17 @@ public void actionPerformed(ActionEvent e) {
if (target != null && tag != null) {
int conflictResolution = JOptionPane.YES_OPTION;
if (target.hasKey(tag.getKey()) && !target.hasTag(tag.getKey(), tag.getValue())) {
conflictResolution = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(),
"<html>"
+ I18n.tr(
"A tag with key <i>{0}</i> is already present on the selected OSM object.", tag.getKey())
+ "<br>"
+ I18n.tr(
"Do you really want to replace the current value <i>{0}</i> with the new value <i>{1}</i>?",
target.get(tag.getKey()), tag.getValue())
+ "</html>",
I18n.tr("Tag conflict"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
conflictResolution = JOptionPane.showConfirmDialog(MainApplication.getMainFrame(), "<html>"
+ tr("A tag with key <i>{0}</i> is already present on the selected OSM object.", tag.getKey())
+ "<br>"
+ tr("Do you really want to replace the current value <i>{0}</i> with the new value <i>{1}</i>?",
target.get(tag.getKey()), tag.getValue())
+ "</html>", tr("Tag conflict"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
}
if (JOptionPane.YES_OPTION == conflictResolution) {
if (target instanceof OsmPrimitive) {
if (target instanceof OsmPrimitive primitive) {
UndoRedoHandler.getInstance()
.add(new ChangePropertyCommand((OsmPrimitive) target, tag.getKey(), tag.getValue()));
.add(new ChangePropertyCommand(primitive, tag.getKey(), tag.getValue()));
} else {
target.put(tag);
target.setModified(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.Serial;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Popup;
import javax.swing.PopupFactory;

import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryColorScheme;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
import org.openstreetmap.josm.tools.Shortcut;

public class ClipboardAction extends AbstractAction {
/**
* An action for copying items to the clipboard
*/
public class ClipboardAction extends MapillaryAction {
@Serial
private static final long serialVersionUID = 3323536079627210533L;
/**
* The duration in milliseconds for which the popup will be shown
Expand All @@ -48,8 +54,18 @@ public class ClipboardAction extends AbstractAction {
*/
private Transferable contents;

/**
* Create a new action for clipboards
*
* @param name The name of the action (use {@link org.openstreetmap.josm.tools.I18n#marktr(String)})
* @param successMessage The message for success
* @param contents The initial contents to use
*/
public ClipboardAction(final String name, final String successMessage, final Transferable contents) {
super(name, ImageProvider.get("copy", ImageSizes.SMALLICON));
super(tr(name), "copy", tr("Copy {0} to clipboard", tr(name)),
Shortcut.registerShortcut("mapillary:copy_to_clipboard_" + name.replace(' ', '_'),
tr("Mapillary: {0}", tr(name)), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
false, "mapillary:copy_to_clipboard_" + name.replace(' ', '_'), false);
this.contents = contents;

// Init popup
Expand Down Expand Up @@ -88,7 +104,7 @@ public void setPopupParent(Component popupParent) {
@Override
public void actionPerformed(ActionEvent e) {
if (contents != null) {
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
ClipboardUtils.copy(contents);
if (popupParent != null && lastCopyTime + POPUP_DURATION < System.currentTimeMillis()) {
final PopupFactory popupFactory = new PopupFactory();
final Popup popup = popupFactory.getPopup(popupParent, popupContent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import static org.openstreetmap.josm.tools.I18n.marktr;
import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.Font;
Expand Down Expand Up @@ -119,13 +120,13 @@ private ImageInfoPanel() {

imgKeyValue = new HtmlPanel();

imgLinkAction = new WebLinkAction(tr("View in browser"), null);
imgLinkAction = new WebLinkAction(marktr("View in browser"), null);

copyImgUrlAction = new ClipboardAction(tr("Copy URL"), tr("Copied URL to clipboard …"), null);
copyImgUrlAction = new ClipboardAction(marktr("Copy URL"), tr("Copied URL to clipboard …"), null);
final var copyUrlButton = new MapillaryButton(copyImgUrlAction, true);
copyImgUrlAction.setPopupParent(copyUrlButton);

copyImgKeyAction = new ClipboardAction(tr("Copy key"), tr("Copied key to clipboard …"), null);
copyImgKeyAction = new ClipboardAction(marktr("Copy key"), tr("Copied key to clipboard …"), null);
final var copyKeyButton = new MapillaryButton(copyImgKeyAction, true);
copyImgKeyAction.setPopupParent(copyKeyButton);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import javax.swing.Action;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.tools.Shortcut;

/**
* A common class for Mapillary actions
*/
abstract class MapillaryAction extends JosmAction {
MapillaryAction(String name, String icon, String tooltip, Shortcut shortcut, boolean registerInToolbar,
String toolbarId, boolean installAdapters) {
super(name, icon, tooltip, shortcut, registerInToolbar, toolbarId, installAdapters);
// We don't need the large icon, and it messes with spacing in buttons
this.putValue(Action.LARGE_ICON_KEY, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapillary.gui.imageinfo;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.io.Serial;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.OpenBrowser;
import org.openstreetmap.josm.tools.Shortcut;

/**
* An action to open web links
*/
public class WebLinkAction extends AbstractAction {
public class WebLinkAction extends MapillaryAction {
@Serial
private static final long serialVersionUID = 2397830510179013823L;

private URI uri;

/**
* Create a new action
*
* @param name The name to show users
* @param name The name to show users (use {@link I18n#marktr(String)})
* @param uri The original URI to open
*/
public WebLinkAction(final String name, final URI uri) {
super(name, ImageProvider.get("link", ImageSizes.SMALLICON));
super(tr(name), "link", tr("Open in browser"),
Shortcut.registerShortcut("mapillary:open_in_browser_" + name.replace(' ', '_'),
tr("Mapillary: Open {0} in browser", tr(name)), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE),
false, "mapillary:open_in_browser_" + name.replace(' ', '_'), false);
setURI(uri);
}

Expand Down

0 comments on commit 3ab8956

Please sign in to comment.