1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.plugins;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
7 | import org.openstreetmap.josm.gui.download.DownloadSelection;
|
---|
8 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
9 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Helper class for the JOSM system to communicate with the plugin.
|
---|
13 | *
|
---|
14 | * This class should be of no interest for sole plugin writer.
|
---|
15 | *
|
---|
16 | * @author Immanuel.Scholz
|
---|
17 | */
|
---|
18 | public class PluginProxy extends Plugin {
|
---|
19 |
|
---|
20 | public final Object plugin;
|
---|
21 |
|
---|
22 | public PluginProxy(Object plugin, PluginInformation info) {
|
---|
23 | super(info);
|
---|
24 | this.plugin = plugin;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
28 | try {
|
---|
29 | plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
|
---|
30 | } catch (NoSuchMethodException e) {
|
---|
31 | } catch (Exception e) {
|
---|
32 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override public PreferenceSetting getPreferenceSetting() {
|
---|
37 | try {
|
---|
38 | return (PreferenceSetting)plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
|
---|
39 | } catch (NoSuchMethodException e) {
|
---|
40 | return null;
|
---|
41 | } catch (Exception e) {
|
---|
42 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
43 | }
|
---|
44 | return null;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override public void addDownloadSelection(List<DownloadSelection> list) {
|
---|
48 | try {
|
---|
49 | plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
|
---|
50 | } catch (NoSuchMethodException e) {
|
---|
51 | // ignore
|
---|
52 | } catch (Exception e) {
|
---|
53 | BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|