| 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 |
|
|---|
| 8 | import javax.swing.AbstractAction;
|
|---|
| 9 |
|
|---|
| 10 | import org.openstreetmap.josm.data.osm.Relation;
|
|---|
| 11 | import org.openstreetmap.josm.gui.MainApplication;
|
|---|
| 12 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 13 |
|
|---|
| 14 | import relcontext.ChosenRelation;
|
|---|
| 15 | import relcontext.ChosenRelationListener;
|
|---|
| 16 |
|
|---|
| 17 | public class SelectRelationAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| 18 | private ChosenRelation rel;
|
|---|
| 19 |
|
|---|
| 20 | public SelectRelationAction(ChosenRelation rel) {
|
|---|
| 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);
|
|---|
| 26 | setEnabled(rel.get() != null);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | @Override
|
|---|
| 30 | public void actionPerformed(ActionEvent e) {
|
|---|
| 31 | MainApplication.getLayerManager().getEditLayer().data.setSelected(rel.get() == null ? null : rel.get());
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| 36 | setEnabled(newRelation != null);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|