source: josm/trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java@ 12464

Last change on this file since 12464 was 11038, checked in by simon04, 8 years ago

Use Relation.getMemberPrimitivesList where possible to avoid unnecessary set creation

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.relation;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.util.HashSet;
8import java.util.Set;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.Relation;
13import 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 */
19public 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}
Note: See TracBrowser for help on using the repository browser.