Changeset 16 in josm for src/org/openstreetmap/josm/data/Preferences.java
- Timestamp:
- 2005-10-08T17:14:54+02:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/data/Preferences.java
r15 r16 1 1 package org.openstreetmap.josm.data; 2 2 3 import java.beans.PropertyChangeEvent;4 import java.beans.PropertyChangeListener;5 3 import java.io.File; 6 4 import java.io.FileReader; 7 5 import java.io.FileWriter; 6 import java.util.Collection; 8 7 import java.util.LinkedList; 9 8 import java.util.List; … … 28 27 public class Preferences { 29 28 30 31 29 /** 32 30 * The look and feel. Classname of the look and feel class to use. 33 31 */ 34 private LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 32 public LookAndFeelInfo laf = UIManager.getInstalledLookAndFeels()[0]; 33 35 34 /** 36 35 * The convertor used to translate lat/lon points to screen points. 37 36 */ 38 37 private Projection projection = new UTM(); 38 39 39 40 /** 40 41 * Whether nodes on the same place should be considered identical. 41 42 */ 42 private boolean mergeNodes = true; 43 public boolean mergeNodes = true; 44 45 43 46 47 /** 48 * List of all available Projections. 49 */ 50 public static final Projection[] allProjections = new Projection[]{ 51 new UTM(), 52 new LatitudeLongitude() 53 }; 44 54 45 55 /** 56 * Return the location of the preferences file 57 */ 58 public static String getPreferencesFile() { 59 return System.getProperty("user.home")+"/.josm-preferences"; 60 } 61 46 62 /** 47 63 * Exception thrown in case of any loading/saving error (including parse errors). … … 53 69 } 54 70 } 55 56 /**57 * List of all available Projections.58 */59 public static final Projection[] allProjections = new Projection[]{60 new UTM(),61 new LatitudeLongitude()62 };63 64 65 66 67 // listener stuff68 69 /**70 * The event listener list71 */72 private List<PropertyChangeListener> listener = new LinkedList<PropertyChangeListener>();73 /**74 * If <code>listener != null</code>, add it to the listener list.75 */76 public void addPropertyChangeListener(PropertyChangeListener listener) {77 if (listener != null)78 this.listener.add(listener);79 }80 /**81 * If <code>listener != null</code>, remove it from the listener list.82 */83 public void removePropertyChangeListener(PropertyChangeListener listener) {84 if (listener != null)85 this.listener.remove(listener);86 }87 /**88 * Fires an event that the property has changed.89 */90 private void firePropertyChanged(String propName, Object oldValue, Object newValue) {91 PropertyChangeEvent event = null;92 for (PropertyChangeListener l : listener) {93 if (event == null)94 event = new PropertyChangeEvent(this, propName, oldValue, newValue);95 l.propertyChange(event);96 }97 }98 99 100 101 /**102 * Return the location of the preferences file103 */104 public static String getPreferencesFile() {105 return System.getProperty("user.home")+"/.josm-preferences";106 }107 108 71 /** 109 72 * Load from disk. … … 120 83 for (LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) 121 84 if (lafInfo.getClassName().equals(lafClassName)) { 122 setLaf(lafInfo);85 laf = lafInfo; 123 86 break; 124 87 } 125 if ( getLaf()== null)88 if (laf == null) 126 89 throw new PreferencesException("Look and Feel not found.", null); 127 128 // setprojection90 91 // projection 129 92 Class<?> projectionClass = Class.forName(root.getChildText("projection")); 130 93 projection = allProjections[0]; // defaults to UTM … … 136 99 } 137 100 138 setMergeNodes(root.getChild("mergeNodes") != null);101 mergeNodes = root.getChild("mergeNodes") != null; 139 102 } catch (Exception e) { 140 103 if (e instanceof PreferencesException) … … 153 116 154 117 List children = root.getChildren(); 155 children.add(new Element("laf").setText( getLaf().getClassName()));118 children.add(new Element("laf").setText(laf.getClassName())); 156 119 children.add(new Element("projection").setText(getProjection().getClass().getName())); 157 if ( isMergeNodes())120 if (mergeNodes) 158 121 children.add(new Element("mergeNodes")); 159 122 … … 167 130 } 168 131 169 // getter / setter 170 132 133 // projection change listener stuff 134 135 /** 136 * This interface notifies any interested about changes in the projection 137 * @author imi 138 */ 139 public interface ProjectionChangeListener { 140 void projectionChanged(Projection oldProjection, Projection newProjection); 141 } 142 /** 143 * The list of all listeners to projection changes. 144 */ 145 private Collection<ProjectionChangeListener> listener = new LinkedList<ProjectionChangeListener>(); 146 /** 147 * Add a listener of projection changes to the list of listeners. 148 * @param listener The listerner to add. 149 */ 150 public void addProjectionChangeListener(ProjectionChangeListener listener) { 151 if (listener != null) 152 this.listener.add(listener); 153 } 154 /** 155 * Remove the listener from the list. 156 */ 157 public void removeProjectionChangeListener(ProjectionChangeListener listener) { 158 this.listener.remove(listener); 159 } 160 /** 161 * Set the projection and fire an event to all ProjectionChangeListener 162 * @param projection The new Projection. 163 */ 171 164 public void setProjection(Projection projection) { 172 165 Projection old = this.projection; 173 166 this.projection = projection; 174 firePropertyChanged("projection", old, projection); 167 if (old != projection) 168 for (ProjectionChangeListener l : listener) 169 l.projectionChanged(old, projection); 175 170 } 171 /** 172 * Get the current projection. 173 * @return The current projection set. 174 */ 176 175 public Projection getProjection() { 177 176 return projection; 178 177 } 179 public void setMergeNodes(boolean mergeNodes) {180 boolean old = this.mergeNodes;181 this.mergeNodes = mergeNodes;182 firePropertyChanged("mergeNodes", old, mergeNodes);183 }184 public boolean isMergeNodes() {185 return mergeNodes;186 }187 public void setLaf(LookAndFeelInfo laf) {188 LookAndFeelInfo old = this.laf;189 this.laf = laf;190 firePropertyChanged("laf", old, laf);191 }192 public LookAndFeelInfo getLaf() {193 return laf;194 }195 178 }
Note:
See TracChangeset
for help on using the changeset viewer.