1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.plugins;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
8 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
---|
9 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
10 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
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 |
|
---|
21 | public final Object plugin;
|
---|
22 |
|
---|
23 | public PluginProxy(Object plugin, PluginInformation info) {
|
---|
24 | super(info);
|
---|
25 | this.plugin = plugin;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
29 | try {
|
---|
30 | plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
|
---|
31 | } catch (NoSuchMethodException e) {
|
---|
32 | Main.debug("Plugin "+plugin+" does not define mapFrameInitialized");
|
---|
33 | } catch (Exception e) {
|
---|
34 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override public PreferenceSetting getPreferenceSetting() {
|
---|
39 | try {
|
---|
40 | return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
|
---|
41 | } catch (NoSuchMethodException e) {
|
---|
42 | Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
|
---|
43 | return null;
|
---|
44 | } catch (Exception e) {
|
---|
45 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
46 | }
|
---|
47 | return null;
|
---|
48 | }
|
---|
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) {
|
---|
54 | Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
|
---|
55 | } catch (Exception e) {
|
---|
56 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|