| 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.properties.HelpAction;
|
|---|
| 13 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 14 | import org.openstreetmap.josm.tools.Logging;
|
|---|
| 15 |
|
|---|
| 16 | import relcontext.ChosenRelation;
|
|---|
| 17 | import relcontext.ChosenRelationListener;
|
|---|
| 18 |
|
|---|
| 19 | public class RelationHelpAction extends AbstractAction implements ChosenRelationListener {
|
|---|
| 20 | private final ChosenRelation rel;
|
|---|
| 21 |
|
|---|
| 22 | public RelationHelpAction(ChosenRelation rel) {
|
|---|
| 23 | putValue(NAME, tr("Open relation wiki page"));
|
|---|
| 24 | putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));
|
|---|
| 25 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
|
|---|
| 26 | this.rel = rel;
|
|---|
| 27 | rel.addChosenRelationListener(this);
|
|---|
| 28 | setEnabled(rel.get() != null);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | @Override
|
|---|
| 32 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
|---|
| 33 | setEnabled(newRelation != null);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | @Override
|
|---|
| 37 | public void actionPerformed(ActionEvent e) {
|
|---|
| 38 | if (rel.get() == null)
|
|---|
| 39 | return;
|
|---|
| 40 | try {
|
|---|
| 41 | MainApplication.worker.execute(() -> HelpAction.displayRelationHelp(rel.get()));
|
|---|
| 42 | } catch (Exception e1) {
|
|---|
| 43 | Logging.error(e1);
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|