    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.actions;
    003
    004import static org.openstreetmap.josm.tools.I18n.tr;
    005
    006import java.awt.event.ActionEvent;
    007
    008import org.openstreetmap.josm.actions.JosmAction;
    009import org.openstreetmap.josm.gui.MainApplication;
    010import org.openstreetmap.josm.plugins.streetside.StreetsideAbstractImage;
    011import org.openstreetmap.josm.plugins.streetside.StreetsideDataListener;
    012import org.openstreetmap.josm.plugins.streetside.StreetsideLayer;
    013import org.openstreetmap.josm.plugins.streetside.StreetsidePlugin;
    014import org.openstreetmap.josm.tools.ImageProvider;
    015import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    016
    017/**
    018 * Zooms to the currently selected image.
    019 *
    020 * @author nokutu
    021 *
    022 */
    023public class StreetsideZoomAction extends JosmAction implements StreetsideDataListener {
    024
    025  private static final long serialVersionUID = -5885977359895624233L;
    026
    027  /**
    028   * Main constructor.
    029   */
    030  public StreetsideZoomAction() {
    031    super(
    032      tr("Zoom to selected image"),
    033      new ImageProvider(StreetsidePlugin.LOGO).setSize(ImageSizes.DEFAULT),
    034      tr("Zoom to the currently selected Streetside image"),
    035      null,
    036      false,
    037      "mapillaryZoom",
    038      true
    039    );
    040  }
    041
    042  @Override
    043  public void actionPerformed(ActionEvent arg0) {
    044    if (StreetsideLayer.getInstance().getData().getSelectedImage() == null) {
    045      throw new IllegalStateException();
    046    }
    047    MainApplication.getMap().mapView.zoomTo(StreetsideLayer.getInstance().getData()
    048        .getSelectedImage().getMovingLatLon());
    049  }
    050
    051  @Override
    052  public void imagesAdded() {
    053    // Nothing
    054  }
    055
    056    @Override
    057  protected boolean listenToSelectionChange() {
    058    return false;
    059  }
    060
    061  @Override
    062  public void selectedImageChanged(StreetsideAbstractImage oldImage, StreetsideAbstractImage newImage) {
    063    if (oldImage == null && newImage != null) {
    064      setEnabled(true);
    065    } else if (oldImage != null && newImage == null) {
    066      setEnabled(false);
    067    }
    068  }
    069
    070  @Override
    071  protected void updateEnabledState() {
    072    super.updateEnabledState();
    073    setEnabled(StreetsideLayer.hasInstance() && StreetsideLayer.getInstance().getData().getSelectedImage() != null);
    074  }
    075}