[josm-dev] patches for wmsplugin preferences bugs (one of them replaces my previous patch)

Bodo Meissner bodo at bodo-m.de
Wed Jul 2 10:58:16 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I found two problems with the preferences handling in wmsplugin.

first problem: wmsplugin screws up the numbers in the preferences entries
when storing the data in wmsList. It stores the values when it has found
a value with a different ID number but wrongly uses the ID of the new
entry (prefid) instead of the last ID (lastid) that belongs to the stored
values.

The included patch for WMSPlugin.java to fix this problem is combined with
my previous patch that saves the enabled state of the menu entries.

second problem: preferences values can be deleted by using a null value
instead of an empty string. Patch for WMSPreferenceEditor.java included.


Bodo


Index: /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
===================================================================
- --- /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java	(revision 8649)
+++ /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java	(working copy)
@@ -33,6 +33,9 @@
 	static JMenu wmsJMenu;

 	static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>();
+
+	// remember state of menu item to restore on changed preferences
+	static private boolean menuEnabled = false;
 	
 	public WMSPlugin() {
 		refreshMenu();
@@ -62,7 +65,7 @@
 			}
 			if (prefid != lastid) {
 				if ((name != null) && (url != null)) {
- -					wmsList.add(new WMSInfo(name, url, prefid));
+					wmsList.add(new WMSInfo(name, url, lastid));
 				}
 				name = null; url = null; lastid = prefid;
 			}
@@ -117,7 +120,7 @@
 		}));
 		wmsJMenu.addSeparator();
 		wmsJMenu.add(new JMenuItem(new Help_WMSmenuAction()));
- -		setEnabledAll(false);
+		setEnabledAll(menuEnabled);
 	}

 	public static Grabber getGrabber(String wmsurl) {
@@ -134,6 +137,7 @@
 			
 			if(item != null) item.setEnabled(isEnabled);
 		}
+		menuEnabled = isEnabled;
 	}
 	
 	public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {


Index: /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
===================================================================
- --- /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java	(revision 8649)
+++ /home/mei/ews/osm/osm/applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java	(working copy)
@@ -110,11 +110,11 @@
 			}
 		}
 		
- -		// josm doesn't seem to give us an option to delete preferences,
- -		// we can only overwrite them with empty strings...
+		// using null values instead of empty string really deletes
+		// the preferences entry
 		for (WMSInfo i : oldValues.values()) {
- -			i.url = "";
- -			i.name = "";
+			i.url = null;
+			i.name = null;
 			i.save();
 			change = true;
 		}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIa1E2nMz9fgzDSqcRAv0eAKCEW9Zq71492MFhrBH3hf6Bz1AYogCcCkFp
hQxmquz+sAmLmVTtAGOpL+M=
=DPIx
-----END PGP SIGNATURE-----




More information about the josm-dev mailing list