    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.StreetsideLayer;
    011import org.openstreetmap.josm.plugins.streetside.mode.JoinMode;
    012import org.openstreetmap.josm.plugins.streetside.mode.SelectMode;
    013import org.openstreetmap.josm.tools.ImageProvider;
    014import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
    015
    016/**
    017 * Changes the mode of the Layer, from Select mode to Join mode and vice versa.
    018 *
    019 * @author nokutu
    020 *
    021 */
    022public class StreetsideJoinAction extends JosmAction {
    023
    024  private static final long serialVersionUID = -7082300908202843706L;
    025
    026  /**
    027   * Main constructor.
    028   */
    029  public StreetsideJoinAction() {
    030    super(tr("Join mode"), new ImageProvider("mapmode", "mapillary-join").setSize(ImageSizes.DEFAULT),
    031        tr("Join/unjoin pictures"), null, false, "mapillaryJoin", true);
    032  }
    033
    034  @Override
    035  public void actionPerformed(ActionEvent arg0) {
    036    if (StreetsideLayer.getInstance().mode instanceof SelectMode) {
    037      StreetsideLayer.getInstance().setMode(new JoinMode());
    038    } else {
    039      StreetsideLayer.getInstance().setMode(new SelectMode());
    040    }
    041  }
    042
    043  @Override
    044  protected boolean listenToSelectionChange() {
    045    return false;
    046  }
    047
    048  /**
    049   * Enabled when mapillary layer is the active layer
    050   */
    051  @Override
    052  protected void updateEnabledState() {
    053    super.updateEnabledState();
    054    setEnabled(MainApplication.getLayerManager().getActiveLayer() instanceof StreetsideLayer);
    055  }
    056}