| 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.gui.dialogs.relation.RelationEditor;
|
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 14 |
|
|---|
| 15 | import relcontext.ChosenRelation;
|
|---|
| 16 | import relcontext.ChosenRelationListener;
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Opens an editor for chosen relation.
|
|---|
| 20 | *
|
|---|
| 21 | * @author Zverik
|
|---|
| 22 | */
|
|---|
| 23 | public class EditChosenRelationAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| 24 | private final ChosenRelation rel;
|
|---|
| 25 |
|
|---|
| 26 | public EditChosenRelationAction(ChosenRelation rel) {
|
|---|
| 27 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit", ImageProvider.ImageSizes.SMALLICON));
|
|---|
| 28 | putValue(SHORT_DESCRIPTION, tr("Open relation editor for the chosen relation"));
|
|---|
| 29 | this.rel = rel;
|
|---|
| 30 | rel.addChosenRelationListener(this);
|
|---|
| 31 | setEnabled(rel.get() != null);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | @Override
|
|---|
| 35 | public void actionPerformed(ActionEvent e) {
|
|---|
| 36 | Relation relation = rel.get();
|
|---|
| 37 | if (relation == null) return;
|
|---|
| 38 | RelationEditor.getEditor(MainApplication.getLayerManager().getEditLayer(), relation, null).setVisible(true);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | @Override
|
|---|
| 42 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| 43 | setEnabled(newRelation != null);
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|