Changeset 17 in josm for src/org/openstreetmap/josm/data/Preferences.java
- Timestamp:
- 2005-10-09T04:14:40+02:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/Preferences.java
r16 r17 1 1 package org.openstreetmap.josm.data; 2 2 3 import java.beans.PropertyChangeEvent; 4 import java.beans.PropertyChangeListener; 3 5 import java.io.File; 4 6 import java.io.FileReader; … … 38 40 39 41 42 /** 43 * Whether lines should be drawn between track points of raw gps data. 44 */ 45 private boolean drawRawGpsLines = false; 40 46 /** 41 47 * Whether nodes on the same place should be considered identical. … … 100 106 101 107 mergeNodes = root.getChild("mergeNodes") != null; 108 drawRawGpsLines = root.getChild("drawRawGpsLines") != null; 102 109 } catch (Exception e) { 103 110 if (e instanceof PreferencesException) … … 120 127 if (mergeNodes) 121 128 children.add(new Element("mergeNodes")); 129 if (drawRawGpsLines) 130 children.add(new Element("drawRawGpsLines")); 122 131 123 132 try { … … 134 143 135 144 /** 136 * This interface notifies any interested about changes in the projection137 * @author imi138 */139 public interface ProjectionChangeListener {140 void projectionChanged(Projection oldProjection, Projection newProjection);141 }142 /**143 145 * The list of all listeners to projection changes. 144 146 */ 145 private Collection<Pro jectionChangeListener> listener = new LinkedList<ProjectionChangeListener>();147 private Collection<PropertyChangeListener> listener = new LinkedList<PropertyChangeListener>(); 146 148 /** 147 149 * Add a listener of projection changes to the list of listeners. 148 150 * @param listener The listerner to add. 149 151 */ 150 public void addPro jectionChangeListener(ProjectionChangeListener listener) {152 public void addPropertyChangeListener(PropertyChangeListener listener) { 151 153 if (listener != null) 152 154 this.listener.add(listener); … … 155 157 * Remove the listener from the list. 156 158 */ 157 public void removePro jectionChangeListener(ProjectionChangeListener listener) {159 public void removePropertyChangeListener(PropertyChangeListener listener) { 158 160 this.listener.remove(listener); 159 161 } 162 /** 163 * Fires a PropertyChangeEvent if the old value differs from the new value. 164 */ 165 private <T> void firePropertyChanged(String name, T oldValue, T newValue) { 166 if (oldValue == newValue) 167 return; 168 PropertyChangeEvent evt = null; 169 for (PropertyChangeListener l : listener) { 170 if (evt == null) 171 evt = new PropertyChangeEvent(this, name, oldValue, newValue); 172 l.propertyChange(evt); 173 } 174 } 175 176 // getter / setter 177 160 178 /** 161 179 * Set the projection and fire an event to all ProjectionChangeListener … … 165 183 Projection old = this.projection; 166 184 this.projection = projection; 167 if (old != projection) 168 for (ProjectionChangeListener l : listener) 169 l.projectionChanged(old, projection); 185 firePropertyChanged("projection", old, projection); 170 186 } 171 187 /** … … 176 192 return projection; 177 193 } 194 public void setDrawRawGpsLines(boolean drawRawGpsLines) { 195 boolean old = this.drawRawGpsLines; 196 this.drawRawGpsLines = drawRawGpsLines; 197 firePropertyChanged("drawRawGpsLines", old, drawRawGpsLines); 198 } 199 public boolean isDrawRawGpsLines() { 200 return drawRawGpsLines; 201 } 178 202 }
Note:
See TracChangeset
for help on using the changeset viewer.