| 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 SelectInRelationPanelAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| 18 | private ChosenRelation rel;
|
|---|
| 19 |
|
|---|
| 20 | public SelectInRelationPanelAction(ChosenRelation rel) {
|
|---|
| 21 | super();
|
|---|
| 22 | putValue(NAME, tr("Select in relation list"));
|
|---|
| 23 | putValue(SHORT_DESCRIPTION, tr("Select relation in relation list."));
|
|---|
| 24 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "relationlist"));
|
|---|
| 25 | this.rel = rel;
|
|---|
| 26 | rel.addChosenRelationListener(this);
|
|---|
| 27 | setEnabled(rel.get() != null);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | @Override
|
|---|
| 31 | public void actionPerformed(ActionEvent e) {
|
|---|
| 32 | if (rel.get() != null) {
|
|---|
| 33 | MainApplication.getMap().relationListDialog.selectRelation(rel.get());
|
|---|
| 34 | MainApplication.getMap().relationListDialog.unfurlDialog();
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | @Override
|
|---|
| 39 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| 40 | setEnabled(newRelation != null);
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|