001 // License: GPL. Copyright 2007 by Immanuel Scholz and others
002 package org.openstreetmap.josm.plugins;
003
004 import java.util.List;
005
006 import org.openstreetmap.josm.gui.MapFrame;
007 import org.openstreetmap.josm.gui.download.DownloadSelection;
008 import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
009 import org.openstreetmap.josm.tools.BugReportExceptionHandler;
010
011 /**
012 * Helper class for the JOSM system to communicate with the plugin.
013 *
014 * This class should be of no interest for sole plugin writer.
015 *
016 * @author Immanuel.Scholz
017 */
018 public class PluginProxy extends Plugin {
019
020 public final Object plugin;
021
022 public PluginProxy(Object plugin, PluginInformation info) {
023 super(info);
024 this.plugin = plugin;
025 }
026
027 @Override public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
028 try {
029 plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
030 } catch (NoSuchMethodException e) {
031 } catch (Exception e) {
032 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
033 }
034 }
035
036 @Override public PreferenceSetting getPreferenceSetting() {
037 try {
038 return (PreferenceSetting)plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
039 } catch (NoSuchMethodException e) {
040 return null;
041 } catch (Exception e) {
042 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
043 }
044 return null;
045 }
046
047 @Override public void addDownloadSelection(List<DownloadSelection> list) {
048 try {
049 plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
050 } catch (NoSuchMethodException e) {
051 // ignore
052 } catch (Exception e) {
053 BugReportExceptionHandler.handleException(new PluginException(this, getPluginInformation().name, e));
054 }
055 }
056 }