[32395] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[25680] | 2 | package relcontext.actions;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[32395] | 5 |
|
---|
[25680] | 6 | import java.awt.event.ActionEvent;
|
---|
| 7 | import java.net.URI;
|
---|
| 8 | import java.util.List;
|
---|
[32395] | 9 |
|
---|
[25680] | 10 | import javax.swing.AbstractAction;
|
---|
[32395] | 11 |
|
---|
[25680] | 12 | import org.openstreetmap.josm.Main;
|
---|
| 13 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
[33530] | 14 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
[34086] | 15 | import org.openstreetmap.josm.gui.dialogs.properties.HelpAction;
|
---|
[25680] | 16 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
| 17 | import org.openstreetmap.josm.tools.LanguageInfo;
|
---|
[34086] | 18 | import org.openstreetmap.josm.tools.Logging;
|
---|
[32395] | 19 |
|
---|
[25680] | 20 | import relcontext.ChosenRelation;
|
---|
| 21 | import relcontext.ChosenRelationListener;
|
---|
| 22 |
|
---|
| 23 | public class RelationHelpAction extends AbstractAction implements ChosenRelationListener {
|
---|
[34086] | 24 | private final ChosenRelation rel;
|
---|
[25680] | 25 |
|
---|
[32395] | 26 | public RelationHelpAction(ChosenRelation rel) {
|
---|
[25695] | 27 | putValue(NAME, tr("Open relation wiki page"));
|
---|
[25680] | 28 | putValue(SHORT_DESCRIPTION, tr("Launch browser with wiki help for selected object"));
|
---|
| 29 | putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
|
---|
| 30 | this.rel = rel;
|
---|
| 31 | rel.addChosenRelationListener(this);
|
---|
[25711] | 32 | setEnabled(rel.get() != null);
|
---|
[25680] | 33 | }
|
---|
| 34 |
|
---|
[32395] | 35 | @Override
|
---|
| 36 | public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
|
---|
[25695] | 37 | setEnabled(newRelation != null);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[32395] | 40 | @Override
|
---|
| 41 | public void actionPerformed(ActionEvent e) {
|
---|
[32398] | 42 | if (rel.get() == null)
|
---|
[25680] | 43 | return;
|
---|
| 44 | try {
|
---|
[34095] | 45 | String base = Main.pref.get("url.openstreetmap-wiki", "https://wiki.openstreetmap.org/wiki/");
|
---|
[25680] | 46 | String lang = LanguageInfo.getWikiLanguagePrefix();
|
---|
[34086] | 47 | final List<URI> uris = HelpAction.getRelationURIs(base, lang, rel.get());
|
---|
| 48 | MainApplication.worker.execute(() -> HelpAction.displayHelp(uris));
|
---|
[25680] | 49 | } catch (Exception e1) {
|
---|
[34086] | 50 | Logging.error(e1);
|
---|
[25680] | 51 | }
|
---|
| 52 | }
|
---|
| 53 | }
|
---|