    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.gui.imageinfo;
    003
    004import java.awt.event.ActionEvent;
    005import java.io.IOException;
    006import java.net.URL;
    007
    008import javax.swing.AbstractAction;
    009import javax.swing.JOptionPane;
    010
    011import org.openstreetmap.josm.gui.Notification;
    012import org.openstreetmap.josm.plugins.streetside.utils.StreetsideUtils;
    013import org.openstreetmap.josm.tools.I18n;
    014import org.openstreetmap.josm.tools.ImageProvider;
    015import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    016import org.openstreetmap.josm.tools.Logging;
    017
    018public class WebLinkAction extends AbstractAction {
    019
    020  private static final long serialVersionUID = -8168227661356480455L;
    021
    022  private URL url;
    023
    024  public WebLinkAction(final String name, final URL url) {
    025    super(name, ImageProvider.get("link", ImageSizes.SMALLICON));
    026    setURL(url);
    027  }
    028
    029  /**
    030   * @param url the url to set
    031   */
    032  public final void setURL(URL url) {
    033    this.url = url;
    034    setEnabled(url != null);
    035  }
    036
    037  /* (non-Javadoc)
    038   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    039   */
    040  @Override
    041  public void actionPerformed(ActionEvent e) {
    042    try {
    043      StreetsideUtils.browse(url);
    044    } catch (IOException e1) {
    045      String msg = I18n.tr("Could not open the URL {0} in a browser", url == null ? "‹null›" : url);
    046      Logging.log(Logging.LEVEL_WARN, msg, e1);
    047      new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show();
    048    }
    049  }
    050}