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