Changeset 22735 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2010-08-22T21:42:02+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r22712 r22735 25 25 import javax.swing.JMenu; 26 26 import javax.swing.JMenuItem; 27 import javax.swing.JOptionPane; 27 28 28 29 import org.openstreetmap.josm.Main; … … 62 63 static private boolean menuEnabled = false; 63 64 64 static boolean remoteControlAvailable = false; 65 static String remoteControlVersion = null; 65 /*************************************************************** 66 * Remote control initialization: 67 * If you need remote control in some other plug-in 68 * copy this stuff and the call to initRemoteControl below 69 * and replace the RequestHandler subclass in initRemoteControl 70 ***************************************************************/ 71 72 /** name of remote control plugin */ 73 private static final String REMOTECONTROL_NAME = "remotecontrol"; 74 75 /* if necessary change these version numbers to ensure compatibility */ 76 77 /** RemoteControlPlugin older than this SVN revision is not compatible */ 78 static final int REMOTECONTROL_MIN_REVISION = 22734; 79 /** WMSPlugin needs this specific API major version of RemoteControlPlugin */ 80 static final int REMOTECONTROL_NEED_API_MAJOR = 1; 81 /** All API minor versions starting from this should be compatible */ 82 static final int REMOTECONTROL_MIN_API_MINOR = 0; 83 84 /* these fields will contain state and version of remote control plug-in */ 85 boolean remoteControlAvailable = false; 86 boolean remoteControlCompatible = true; 87 boolean remoteControlInitialized = false; 88 int remoteControlRevision = 0; 89 int remoteControlApiMajor = 0; 90 int remoteControlApiMinor = 0; 91 int remoteControlProtocolMajor = 0; 92 int remoteControlProtocolMinor = 0; 93 94 /** 95 * Check if remote control plug-in is available and if its version is 96 * high enough and register remote control command for this plug-in. 97 */ 98 private void initRemoteControl() { 99 for(PluginProxy pp: PluginHandler.pluginList) 100 { 101 PluginInformation info = pp.getPluginInformation(); 102 if(REMOTECONTROL_NAME.equals(info.name)) 103 { 104 remoteControlAvailable = true; 105 remoteControlRevision = Integer.parseInt(info.version); 106 if(REMOTECONTROL_MIN_REVISION > remoteControlRevision) 107 { 108 remoteControlCompatible = false; 109 } 110 } 111 } 112 113 if(remoteControlAvailable && remoteControlCompatible) 114 { 115 Plugin plugin = 116 (Plugin) PluginHandler.getPlugin(REMOTECONTROL_NAME); 117 try { 118 Method method; 119 method = plugin.getClass().getMethod("getVersion"); 120 Object obj = method.invoke(plugin); 121 if((obj != null ) && (obj instanceof int[])) 122 { 123 int[] versions = (int[]) obj; 124 if(versions.length >= 4) 125 { 126 remoteControlApiMajor = versions[0]; 127 remoteControlApiMinor = versions[1]; 128 remoteControlProtocolMajor = versions[2]; 129 remoteControlProtocolMinor = versions[3]; 130 } 131 } 132 133 if((remoteControlApiMajor != REMOTECONTROL_NEED_API_MAJOR) || 134 (remoteControlApiMinor < REMOTECONTROL_MIN_API_MINOR)) 135 { 136 remoteControlCompatible = false; 137 } 138 if(remoteControlCompatible) 139 { 140 System.out.println(this.getClass().getSimpleName() + ": initializing remote control"); 141 method = plugin.getClass().getMethod("addRequestHandler", String.class, Class.class); 142 // replace command and class when you copy this to some other plug-in 143 // for compatibility with old remotecontrol add leading "/" 144 method.invoke(plugin, "/" + WMSRemoteHandler.command, WMSRemoteHandler.class); 145 remoteControlInitialized = true; 146 } 147 } catch (SecurityException e) { 148 e.printStackTrace(); 149 } catch (NoSuchMethodException e) { 150 e.printStackTrace(); 151 } catch (IllegalArgumentException e) { 152 e.printStackTrace(); 153 } catch (IllegalAccessException e) { 154 e.printStackTrace(); 155 } catch (InvocationTargetException e) { 156 e.printStackTrace(); 157 } 158 } 159 if(remoteControlAvailable) 160 { 161 String msg = null; 162 163 if(remoteControlCompatible) 164 { 165 if(!remoteControlInitialized) 166 { 167 msg = tr("Could not initialize remote control."); 168 } 169 } 170 else 171 { 172 msg = tr("Remote control plugin is not compatible with {0}.", 173 this.getClass().getSimpleName()); 174 } 175 176 if(msg != null) 177 { 178 String versionMessage = tr("{0} will work but remote control is disabled.\n" 179 + "Current version of \"{1}\": {2}, internal version {3}. " 180 + "Need version {4}, internal version {5}.\n" 181 + "You should update the plugins. If this does not help report a bug for \"{0}\".", 182 this.getClass().getSimpleName(), 183 REMOTECONTROL_NAME, 184 ""+remoteControlRevision, 185 (remoteControlApiMajor != 0) ? 186 ""+remoteControlApiMajor+"."+remoteControlApiMinor : 187 "unknown", 188 ""+REMOTECONTROL_MIN_REVISION, 189 ""+REMOTECONTROL_NEED_API_MAJOR+"."+REMOTECONTROL_MIN_API_MINOR ); 190 191 String title = tr("{0}: Problem with remote control", 192 this.getClass().getSimpleName()); 193 194 JOptionPane.showMessageDialog( 195 Main.parent, 196 msg + "\n" + versionMessage, 197 title, 198 JOptionPane.WARNING_MESSAGE 199 ); 200 } 201 } 202 203 if(!remoteControlAvailable) { 204 System.out.println("wmsplugin: remote control not available"); 205 } 206 } 207 208 /*************************************** 209 * end of remote control initialization 210 ***************************************/ 66 211 67 212 protected void initExporterAndImporter() { … … 81 226 initExporterAndImporter(); 82 227 initRemoteControl(); 83 }84 85 /**86 * Check if remotecontrol plug-in is available and if its version is87 * high enough and add handler for "wms" remote control command "wms".88 */89 private void initRemoteControl() {90 final String remotecontrolName = "remotecontrol";91 final String remotecontrolMinVersion = "22675";92 for(PluginProxy pp: PluginHandler.pluginList)93 {94 PluginInformation info = pp.getPluginInformation();95 if(remotecontrolName.equals(info.name))96 {97 if(remotecontrolMinVersion.compareTo(info.version) <= 0)98 {99 remoteControlAvailable = true;100 remoteControlVersion = info.version;101 }102 else103 {104 System.out.println("wmsplugin: remote control plugin version is " +105 info.version + ", need " + remotecontrolMinVersion + " or newer");106 }107 break;108 }109 }110 111 if(remoteControlAvailable)112 {113 remoteControlAvailable = false;114 System.out.println("wmsplugin: initializing remote control");115 Plugin plugin =116 (Plugin) PluginHandler.getPlugin(remotecontrolName);117 try {118 Method method = plugin.getClass().getMethod("addRequestHandler", String.class, Class.class);119 method.invoke(plugin, WMSRemoteHandler.command, WMSRemoteHandler.class);120 remoteControlAvailable = true;121 } catch (SecurityException e) {122 e.printStackTrace();123 } catch (NoSuchMethodException e) {124 e.printStackTrace();125 } catch (IllegalArgumentException e) {126 e.printStackTrace();127 } catch (IllegalAccessException e) {128 e.printStackTrace();129 } catch (InvocationTargetException e) {130 e.printStackTrace();131 }132 }133 if(!remoteControlAvailable)134 {135 System.out.println("wmsplugin: cannot use remote control");136 }137 228 } 138 229 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSRemoteHandler.java
r22677 r22735 9 9 10 10 import org.openstreetmap.josm.Main; 11 import org.openstreetmap.josm.plugins.remotecontrol.PermissionPref; 11 import org.openstreetmap.josm.plugins.remotecontrol.PermissionPrefWithDefault; 12 12 import org.openstreetmap.josm.plugins.remotecontrol.RequestHandler; 13 13 import org.openstreetmap.josm.plugins.remotecontrol.RequestHandlerErrorException; … … 15 15 public class WMSRemoteHandler extends RequestHandler { 16 16 17 public static final String command = " /wms";17 public static final String command = "wms"; 18 18 19 19 @Override … … 24 24 25 25 @Override 26 public PermissionPref getPermissionPref() 26 public PermissionPrefWithDefault getPermissionPref() 27 27 { 28 return new PermissionPref("wmsplugin.remotecontrol", 28 return new PermissionPrefWithDefault( 29 "wmsplugin.remotecontrol", 30 true, 29 31 "RemoteControl: WMS forbidden by preferences"); 30 32 }
Note:
See TracChangeset
for help on using the changeset viewer.