| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package relcontext.actions;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 5 |
|
|---|
| 6 | import java.awt.event.ActionEvent;
|
|---|
| 7 | import java.util.Collections;
|
|---|
| 8 |
|
|---|
| 9 | import javax.swing.AbstractAction;
|
|---|
| 10 |
|
|---|
| 11 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 12 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 14 |
|
|---|
| 15 | import relcontext.ChosenRelation;
|
|---|
| 16 | import relcontext.ChosenRelationListener;
|
|---|
| 17 |
|
|---|
| 18 | public class SelectMembersAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| 19 | private final ChosenRelation rel;
|
|---|
| 20 |
|
|---|
| 21 | public SelectMembersAction(ChosenRelation rel) {
|
|---|
| 22 | super(tr("Select members"));
|
|---|
| 23 | putValue(SMALL_ICON, ImageProvider.get("selectall"));
|
|---|
| 24 | this.rel = rel;
|
|---|
| 25 | rel.addChosenRelationListener(this);
|
|---|
| 26 | setEnabled(rel.get() != null);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | @Override
|
|---|
| 30 | public void actionPerformed(ActionEvent e) {
|
|---|
| 31 | MainApplication.getLayerManager().getEditLayer().data.setSelected(
|
|---|
| 32 | rel.get() == null ? Collections.emptyList() : rel.get().getMemberPrimitives());
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | @Override
|
|---|
| 36 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| 37 | setEnabled(newRelation != null);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|