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