[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 |
|
---|
[1169] | 21 | public final Object plugin;
|
---|
[626] | 22 |
|
---|
[1169] | 23 | public PluginProxy(Object plugin, PluginInformation info) {
|
---|
[2830] | 24 | super(info);
|
---|
[1169] | 25 | this.plugin = plugin;
|
---|
[626] | 26 | }
|
---|
| 27 |
|
---|
[1169] | 28 | @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
| 29 | try {
|
---|
| 30 | plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
|
---|
[626] | 31 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 32 | Main.debug("Plugin "+plugin+" does not define mapFrameInitialized");
|
---|
[626] | 33 | } catch (Exception e) {
|
---|
[2830] | 34 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
[626] | 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[1169] | 38 | @Override public PreferenceSetting getPreferenceSetting() {
|
---|
| 39 | try {
|
---|
| 40 | return (PreferenceSetting)plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
|
---|
| 41 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 42 | Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
|
---|
[1169] | 43 | return null;
|
---|
| 44 | } catch (Exception e) {
|
---|
[2830] | 45 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
[1169] | 46 | }
|
---|
[1326] | 47 | return null;
|
---|
[626] | 48 | }
|
---|
[1169] | 49 |
|
---|
| 50 | @Override public void addDownloadSelection(List<DownloadSelection> list) {
|
---|
| 51 | try {
|
---|
| 52 | plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
|
---|
| 53 | } catch (NoSuchMethodException e) {
|
---|
[6310] | 54 | Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
|
---|
[1169] | 55 | } catch (Exception e) {
|
---|
[2830] | 56 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
[1169] | 57 | }
|
---|
| 58 | }
|
---|
[626] | 59 | }
|
---|