001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.actions.relation; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.event.ActionEvent; 007 008import org.openstreetmap.josm.Main; 009import org.openstreetmap.josm.gui.layer.OsmDataLayer; 010import org.openstreetmap.josm.tools.ImageProvider; 011 012/** 013 * Sets the current selection to specified list of relations 014 * @since 5793 015 */ 016public class SelectRelationAction extends AbstractRelationAction { 017 018 private final boolean add; 019 020 /** 021 * Constructs a new <code>SelectRelationAction</code>. 022 * @param add if <code>true</code>, the relation will be added to current selection. If <code>false</code>, the relation will replace the current selection. 023 */ 024 public SelectRelationAction(boolean add) { 025 putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") : tr("Set the current selection to the list of selected relations")); 026 putValue(SMALL_ICON, ImageProvider.get("dialogs", "select")); 027 putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation")); 028 this.add = add; 029 } 030 031 @Override 032 public void actionPerformed(ActionEvent e) { 033 if (!isEnabled() || relations.isEmpty()) return; 034 OsmDataLayer editLayer = Main.main.getEditLayer(); 035 if (editLayer==null || editLayer.data==null) return; 036 if (add) { 037 editLayer.data.addSelected(relations); 038 } else { 039 editLayer.data.setSelected(relations); 040 } 041 } 042}