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