    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.apache.log4j.Logger;
    012import org.openstreetmap.josm.gui.Notification;
    013import org.openstreetmap.josm.plugins.streetside.utils.StreetsideUtils;
    014import org.openstreetmap.josm.tools.I18n;
    015import org.openstreetmap.josm.tools.ImageProvider;
    016import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    017
    018public class WebLinkAction extends AbstractAction {
    019
    020  private static final long serialVersionUID = -8168227661356480455L;
    021
    022  final static Logger logger = Logger.getLogger(WebLinkAction.class);
    023
    024  private URL url;
    025
    026  public WebLinkAction(final String name, final URL url) {
    027    super(name, ImageProvider.get("link", ImageSizes.SMALLICON));
    028    setURL(url);
    029  }
    030
    031  /**
    032   * @param url the url to set
    033   */
    034  public final void setURL(URL url) {
    035    this.url = url;
    036    setEnabled(url != null);
    037  }
    038
    039  /* (non-Javadoc)
    040   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
    041   */
    042  @Override
    043  public void actionPerformed(ActionEvent e) {
    044    try {
    045      StreetsideUtils.browse(url);
    046    } catch (IOException e1) {
    047      String msg = "Could not open the URL " + url == null ? "‹null›" : url + " in a browser";
    048      logger.warn(msg, e1);
    049      new Notification(msg).setIcon(JOptionPane.WARNING_MESSAGE).show();
    050    }
    051  }
    052}