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

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • 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;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11import org.openstreetmap.josm.data.osm.Relation;
12import 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 */
18public 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}
Note: See TracBrowser for help on using the repository browser.