Changeset 2618 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2009-12-12T16:38:28+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r2542 r2618 24 24 import java.util.TreeMap; 25 25 import java.util.Map.Entry; 26 import java.util.concurrent.CopyOnWriteArrayList; 26 27 import java.util.regex.Matcher; 27 28 import java.util.regex.Pattern; … … 50 51 private File preferencesDirFile = null; 51 52 53 public static interface PreferenceChangeEvent{ 54 public String getKey(); 55 public String getOldValue(); 56 public String getNewValue(); 57 } 58 52 59 public static interface PreferenceChangedListener { 53 void preferenceChanged(String key, String newValue); 60 void preferenceChanged(PreferenceChangeEvent e); 61 } 62 63 private static class DefaultPreferenceChangeEvent implements PreferenceChangeEvent { 64 private String key; 65 private String oldValue; 66 private String newValue; 67 68 public DefaultPreferenceChangeEvent(String key, String oldValue, String newValue) { 69 this.key = key; 70 this.oldValue = oldValue; 71 this.newValue = newValue; 72 } 73 74 public String getKey() { 75 return key; 76 } 77 public void setKey(String key) { 78 this.key = key; 79 } 80 public String getOldValue() { 81 return oldValue; 82 } 83 public void setOldValue(String oldValue) { 84 this.oldValue = oldValue; 85 } 86 public String getNewValue() { 87 return newValue; 88 } 89 public void setNewValue(String newValue) { 90 this.newValue = newValue; 91 } 54 92 } 55 93 … … 96 134 } 97 135 98 public final ArrayList<PreferenceChangedListener> listener = new ArrayList<PreferenceChangedListener>(); 136 private final CopyOnWriteArrayList<PreferenceChangedListener> listeners = new CopyOnWriteArrayList<PreferenceChangedListener>(); 137 138 139 public void addPreferenceChangeListener(PreferenceChangedListener listener) { 140 if (listener != null && ! listeners.contains(listener)) { 141 listeners.add(listener); 142 } 143 } 144 145 public void removePreferenceChangeListener(PreferenceChangedListener listener) { 146 if (listener != null && listeners.contains(listener)) { 147 listeners.remove(listener); 148 } 149 } 150 151 protected void firePrefrenceChanged(String key, String oldValue, String newValue) { 152 PreferenceChangeEvent evt = new DefaultPreferenceChangeEvent(key, oldValue, newValue); 153 for (PreferenceChangedListener l : listeners) { 154 l.preferenceChanged(evt); 155 } 156 } 99 157 100 158 /** … … 289 347 System.out.println(tr("Warning: failed to persist preferences to ''{0}''", getPreferenceFile().getAbsoluteFile())); 290 348 } 291 firePref erenceChanged(key, value);349 firePrefrenceChanged(key, oldvalue, value); 292 350 return true; 293 351 } … … 311 369 } 312 370 313 private final void firePreferenceChanged(final String key, final String value) {314 for (final PreferenceChangedListener l : listener) {315 l.preferenceChanged(key, value);316 }317 }318 371 319 372 /** … … 618 671 synchronized public String getCollectionAsString(final String key) { 619 672 String s = get(key); 620 if(s != null && s.length() != 0) 673 if(s != null && s.length() != 0) { 621 674 s = s.replaceAll("\u001e",","); 675 } 622 676 return s; 623 677 } -
trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java
r2613 r2618 10 10 import java.util.logging.Logger; 11 11 12 public class ChangesetCache { 12 import org.openstreetmap.josm.Main; 13 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 14 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 15 16 public class ChangesetCache implements PreferenceChangedListener{ 13 17 static private final Logger logger = Logger.getLogger(ChangesetCache.class.getName()); 14 18 static private final ChangesetCache instance = new ChangesetCache(); … … 24 28 25 29 private ChangesetCache() { 30 Main.pref.addPreferenceChangeListener(this); 26 31 } 27 32 … … 135 140 return ret; 136 141 } 142 143 /* ------------------------------------------------------------------------- */ 144 /* interface PreferenceChangedListener */ 145 /* ------------------------------------------------------------------------- */ 146 public void preferenceChanged(PreferenceChangeEvent e) { 147 if (e.getKey() == null || ! e.getKey().equals("osm-server.url")) 148 return; 149 150 // clear the cache when the API url changes 151 if (e.getOldValue() == null || e.getNewValue() == null || !e.getOldValue().equals(e.getNewValue())) { 152 clear(); 153 } 154 } 137 155 } -
trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java
r2613 r2618 30 30 import org.openstreetmap.josm.Main; 31 31 import org.openstreetmap.josm.data.APIDataSet; 32 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 33 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 32 34 import org.openstreetmap.josm.data.osm.Changeset; 33 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 45 47 * 46 48 */ 47 public class UploadDialog extends JDialog implements PropertyChangeListener {49 public class UploadDialog extends JDialog implements PropertyChangeListener, PreferenceChangedListener{ 48 50 protected static final Logger logger = Logger.getLogger(UploadDialog.class.getName()); 49 51 … … 221 223 } 222 224 ); 225 226 Main.pref.addPreferenceChangeListener(this); 223 227 } 224 228 … … 453 457 } 454 458 } 459 460 /* -------------------------------------------------------------------------- */ 461 /* Interface PreferenceChangedListener */ 462 /* -------------------------------------------------------------------------- */ 463 public void preferenceChanged(PreferenceChangeEvent e) { 464 if (e.getKey() == null || ! e.getKey().equals("osm-server.url")) 465 return; 466 if (e.getNewValue() == null) { 467 setTitle(tr("Upload")); 468 } else { 469 setTitle(tr("Upload to ''{0}''", e.getNewValue())); 470 } 471 } 455 472 } -
trunk/src/org/openstreetmap/josm/gui/layer/RawGpsLayer.java
r2450 r2618 34 34 import org.openstreetmap.josm.actions.RenameLayerAction; 35 35 import org.openstreetmap.josm.data.Bounds; 36 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 36 37 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 37 38 import org.openstreetmap.josm.data.coor.EastNorth; … … 113 114 setAssociatedFile(associatedFile); 114 115 this.data = data; 115 Main.pref. listener.add(this);116 Main.pref.addPreferenceChangeListener(this); 116 117 } 117 118 … … 284 285 } 285 286 286 public void preferenceChanged( String key, String newValue) {287 if (Main.map != null && ( key.equals("draw.rawgps.lines") || key.equals("draw.rawgps.lines.force"))) {287 public void preferenceChanged(PreferenceChangeEvent e) { 288 if (Main.map != null && (e.getKey().equals("draw.rawgps.lines") || e.getKey().equals("draw.rawgps.lines.force"))) { 288 289 Main.map.repaint(); 289 290 } … … 291 292 292 293 @Override public void destroy() { 293 Main.pref. listener.remove(RawGpsLayer.this);294 Main.pref.removePreferenceChangeListener(this); 294 295 } 295 296 }
Note:
See TracChangeset
for help on using the changeset viewer.