    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.actions;
    003
    004import java.awt.event.ActionEvent;
    005import java.awt.event.KeyEvent;
    006
    007import org.openstreetmap.josm.actions.JosmAction;
    008import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeEvent;
    009import org.openstreetmap.josm.data.preferences.AbstractProperty.ValueChangeListener;
    010import org.openstreetmap.josm.plugins.streetside.StreetsideLayer;
    011import org.openstreetmap.josm.plugins.streetside.StreetsidePlugin;
    012import org.openstreetmap.josm.plugins.streetside.io.download.StreetsideDownloader;
    013import org.openstreetmap.josm.plugins.streetside.utils.StreetsideProperties;
    014import org.openstreetmap.josm.tools.I18n;
    015import org.openstreetmap.josm.tools.ImageProvider;
    016import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    017import org.openstreetmap.josm.tools.Shortcut;
    018
    019/**
    020 * If in "download images in visible area" mode, downloads all the images in the current view.
    021 *
    022 * @author nokutu
    023 *
    024 */
    025public class StreetsideDownloadViewAction extends JosmAction implements ValueChangeListener<String> {
    026
    027  private static final long serialVersionUID = 6738276777802831669L;
    028
    029  private static final String DESCRIPTION = I18n.marktr("Download Streetside images in current view");
    030
    031  /**
    032   * Main constructor.
    033   */
    034  public StreetsideDownloadViewAction() {
    035    super(
    036      I18n.tr(DESCRIPTION),
    037      new ImageProvider(StreetsidePlugin.LOGO).setSize(ImageSizes.DEFAULT),
    038      I18n.tr(DESCRIPTION),
    039      Shortcut.registerShortcut("Streetside area", I18n.tr(DESCRIPTION), KeyEvent.VK_PERIOD, Shortcut.SHIFT),
    040      false,
    041      "streetsideArea",
    042      true
    043    );
    044    StreetsideProperties.DOWNLOAD_MODE.addListener(this);
    045    initEnabledState();
    046  }
    047
    048  @Override
    049  public void actionPerformed(ActionEvent arg0) {
    050    StreetsideDownloader.downloadVisibleArea();
    051  }
    052
    053  @Override
    054  protected boolean listenToSelectionChange() {
    055    return false;
    056  }
    057
    058  /**
    059   * Enabled when the Streetside layer is instantiated and download mode is either "osm area" or "manual".
    060   */
    061  @Override
    062  protected void updateEnabledState() {
    063    super.updateEnabledState();
    064    setEnabled(
    065      StreetsideLayer.hasInstance() && (
    066        StreetsideDownloader.getMode() == StreetsideDownloader.DOWNLOAD_MODE.OSM_AREA
    067        || StreetsideDownloader.getMode() == StreetsideDownloader.DOWNLOAD_MODE.MANUAL_ONLY
    068      )
    069    );
    070  }
    071
    072  @Override
    073  public void valueChanged(ValueChangeEvent<? extends String> e) {
    074    updateEnabledState();
    075  }
    076}