1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.relation;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.util.HashSet;
|
---|
8 | import java.util.Set;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
12 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
13 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Sets the current selection to the list of relations selected in this dialog
|
---|
17 | * @since 5793
|
---|
18 | */
|
---|
19 | public class SelectMembersAction extends AbstractRelationAction {
|
---|
20 |
|
---|
21 | private final boolean add;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Constructs a new <code>SelectMembersAction</code>.
|
---|
25 | * @param add if <code>true</code>, the members will be added to current selection.
|
---|
26 | * If <code>false</code>, the members will replace the current selection.
|
---|
27 | */
|
---|
28 | public SelectMembersAction(boolean add) {
|
---|
29 | putValue(SHORT_DESCRIPTION, add ? tr("Add the members of all selected relations to current selection")
|
---|
30 | : tr("Select the members of all selected relations"));
|
---|
31 | putValue(SMALL_ICON, ImageProvider.get("selectall"));
|
---|
32 | putValue(NAME, add ? tr("Select members (add)") : tr("Select members"));
|
---|
33 | this.add = add;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void actionPerformed(ActionEvent e) {
|
---|
38 | if (!isEnabled() || relations.isEmpty() || !Main.isDisplayingMapView()) return;
|
---|
39 |
|
---|
40 | Set<OsmPrimitive> members = new HashSet<>();
|
---|
41 | for (Relation r: relations) {
|
---|
42 | members.addAll(r.getMemberPrimitivesList());
|
---|
43 | }
|
---|
44 | if (add) {
|
---|
45 | Main.getLayerManager().getEditLayer().data.addSelected(members);
|
---|
46 | } else {
|
---|
47 | Main.getLayerManager().getEditLayer().data.setSelected(members);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|