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 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
10 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Sets the current selection to specified list of relations
|
---|
14 | * @since 5793
|
---|
15 | */
|
---|
16 | public class SelectRelationAction extends AbstractRelationAction {
|
---|
17 |
|
---|
18 | private final boolean add;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Constructs a new <code>SelectRelationAction</code>.
|
---|
22 | * @param add if <code>true</code>, the relation will be added to current selection.
|
---|
23 | * If <code>false</code>, the relation will replace the current selection.
|
---|
24 | */
|
---|
25 | public SelectRelationAction(boolean add) {
|
---|
26 | putValue(SHORT_DESCRIPTION, add ? tr("Add the selected relations to the current selection") :
|
---|
27 | tr("Set the current selection to the list of selected relations"));
|
---|
28 | new ImageProvider("dialogs", "select").getResource().attachImageIcon(this, true);
|
---|
29 | putValue(NAME, add ? tr("Select relation (add)") : tr("Select relation"));
|
---|
30 | this.add = add;
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void actionPerformed(ActionEvent e) {
|
---|
35 | if (!isEnabled() || relations.isEmpty()) return;
|
---|
36 | OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
|
---|
37 | if (editLayer == null || editLayer.data == null) return;
|
---|
38 | if (add) {
|
---|
39 | editLayer.data.addSelected(relations);
|
---|
40 | } else {
|
---|
41 | editLayer.data.setSelected(relations);
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|