[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | package org.openstreetmap.josm.plugins;
|
---|
| 3 |
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
[6310] | 6 | import org.openstreetmap.josm.Main;
|
---|
[626] | 7 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
| 8 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
---|
| 9 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
[1326] | 10 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
[626] | 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Helper class for the JOSM system to communicate with the plugin.
|
---|
| 14 | *
|
---|
| 15 | * This class should be of no interest for sole plugin writer.
|
---|
| 16 | *
|
---|
| 17 | * @author Immanuel.Scholz
|
---|
| 18 | */
|
---|
| 19 | public class PluginProxy extends Plugin {
|
---|
| 20 |
|
---|
[8953] | 21 | /**
|
---|
| 22 | * The plugin.
|
---|
| 23 | */
|
---|
[1169] | 24 | public final Object plugin;
|
---|
[626] | 25 |
|
---|
[8953] | 26 | /**
|
---|
| 27 | * Constructs a new {@code PluginProxy}.
|
---|
| 28 | * @param plugin the plugin
|
---|
| 29 | * @param info the associated plugin info
|
---|
| 30 | */
|
---|
[1169] | 31 | public PluginProxy(Object plugin, PluginInformation info) {
|
---|
[2830] | 32 | super(info);
|
---|
[1169] | 33 | this.plugin = plugin;
|
---|
[626] | 34 | }
|
---|
| 35 |
|
---|
[8953] | 36 | private void handlePluginException(Exception e) {
|
---|
| 37 | PluginHandler.pluginLoadingExceptions.put(getPluginInformation().name, e);
|
---|
| 38 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | @Override
|
---|
| 42 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
[1169] | 43 | try {
|
---|
| 44 | plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
|
---|
[626] | 45 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 46 | Main.debug("Plugin "+plugin+" does not define mapFrameInitialized");
|
---|
[626] | 47 | } catch (Exception e) {
|
---|
[8953] | 48 | handlePluginException(e);
|
---|
[626] | 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[8953] | 52 | @Override
|
---|
| 53 | public PreferenceSetting getPreferenceSetting() {
|
---|
[1169] | 54 | try {
|
---|
[8510] | 55 | return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
|
---|
[1169] | 56 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 57 | Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
|
---|
[1169] | 58 | return null;
|
---|
| 59 | } catch (Exception e) {
|
---|
[8953] | 60 | handlePluginException(e);
|
---|
[1169] | 61 | }
|
---|
[1326] | 62 | return null;
|
---|
[626] | 63 | }
|
---|
[1169] | 64 |
|
---|
[8953] | 65 | @Override
|
---|
| 66 | public void addDownloadSelection(List<DownloadSelection> list) {
|
---|
[1169] | 67 | try {
|
---|
| 68 | plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
|
---|
| 69 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 70 | Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
|
---|
[1169] | 71 | } catch (Exception e) {
|
---|
[8953] | 72 | handlePluginException(e);
|
---|
[1169] | 73 | }
|
---|
| 74 | }
|
---|
[626] | 75 | }
|
---|