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