Changeset 2686 in josm for trunk/src/org
- Timestamp:
- 2009-12-28T00:14:33+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r2512 r2686 69 69 } 70 70 } 71 if (!LatLon.isValidLat(values[0])) 72 throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[0])); 73 if (!LatLon.isValidLon(values[1])) 74 throw new IllegalArgumentException(tr("Illegal longitude value ''{0}''", values[1])); 75 if (!LatLon.isValidLat(values[2])) 76 throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[2])); 77 if (!LatLon.isValidLon(values[3])) 78 throw new IllegalArgumentException(tr("Illegal latitude value ''{0}''", values[3])); 79 71 80 this.min = new LatLon(values[0], values[1]); 72 81 this.max = new LatLon(values[2], values[3]); -
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r2676 r2686 37 37 */ 38 38 private boolean incomplete; 39 /** the changeset content */ 40 private ChangesetDataSet content = null; 39 41 40 42 /** … … 275 277 this.tags = new HashMap<String, String>(other.tags); 276 278 this.incomplete = other.incomplete; 279 280 // FIXME: merging of content required? 281 this.content = other.content; 282 } 283 284 public boolean hasContent() { 285 return content != null; 286 } 287 288 public ChangesetDataSet getContent() { 289 return content; 290 } 291 292 public void setContent(ChangesetDataSet content) { 293 this.content = content; 277 294 } 278 295 } -
trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java
r2655 r2686 5 5 import java.util.Collection; 6 6 import java.util.HashMap; 7 import java.util.HashSet; 7 8 import java.util.List; 8 9 import java.util.Map; 10 import java.util.Set; 9 11 import java.util.concurrent.CopyOnWriteArrayList; 12 import java.util.logging.Logger; 13 14 import javax.swing.SwingUtilities; 10 15 11 16 import org.openstreetmap.josm.Main; … … 13 18 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 14 19 20 /** 21 * ChangesetCache is global in-memory cache for changesets downloaded from 22 * an OSM API server. The unique instance is available as singleton, see 23 * {@see #getInstance()}. 24 * 25 * Clients interested in cache updates can register for {@see ChangesetCacheEvent}s 26 * using {@see #addChangesetCacheListener(ChangesetCacheListener)}. They can use 27 * {@see #removeChangesetCacheListener(ChangesetCacheListener)} to unregister as 28 * cache event listener. 29 * 30 * The cache itself listens to {@see java.util.prefs.PreferenceChangeEvent}s. It 31 * clears itself if the OSM API URL is changed in the preferences. 32 * 33 * {@see ChangesetCacheEvent}s are delivered on the EDT. 34 * 35 */ 15 36 public class ChangesetCache implements PreferenceChangedListener{ 16 //static private final Logger logger = Logger.getLogger(ChangesetCache.class.getName()); 37 static private final Logger logger = Logger.getLogger(ChangesetCache.class.getName()); 38 39 /** the unique instance */ 17 40 static private final ChangesetCache instance = new ChangesetCache(); 18 41 42 /** 43 * Replies the unique instance of the cache 44 * 45 * @return the unique instance of the cache 46 */ 19 47 public static ChangesetCache getInstance() { 20 48 return instance; 21 49 } 22 50 51 /** the cached changesets */ 23 52 private final Map<Integer, Changeset> cache = new HashMap<Integer, Changeset>(); 24 53 … … 31 60 32 61 public void addChangesetCacheListener(ChangesetCacheListener listener) { 33 if (listener != null) { 34 listeners.addIfAbsent(listener); 62 synchronized(listeners) { 63 if (listener != null && ! listeners.contains(listener)) { 64 listeners.add(listener); 65 } 35 66 } 36 67 } 37 68 38 69 public void removeChangesetCacheListener(ChangesetCacheListener listener) { 39 listeners.remove(listener); 40 } 41 42 protected void fireChangesetCacheEvent(ChangesetCacheEvent e) { 43 for(ChangesetCacheListener l: listeners) { 44 l.changesetCacheUpdated(e); 70 synchronized(listeners) { 71 if (listener != null && listeners.contains(listener)) { 72 listeners.remove(listener); 73 } 74 } 75 } 76 77 protected void fireChangesetCacheEvent(final ChangesetCacheEvent e) { 78 Runnable r = new Runnable() { 79 public void run() { 80 for(ChangesetCacheListener l: listeners) { 81 l.changesetCacheUpdated(e); 82 } 83 } 84 }; 85 if (SwingUtilities.isEventDispatchThread()) { 86 r.run(); 87 } else { 88 SwingUtilities.invokeLater(r); 45 89 } 46 90 } … … 89 133 } 90 134 135 public Set<Changeset> getChangesets() { 136 return new HashSet<Changeset>(cache.values()); 137 } 138 91 139 protected void remove(int id, DefaultChangesetCacheEvent e) { 92 140 if (id <= 0) return; … … 111 159 } 112 160 161 /** 162 * Removes the changesets in <code>changesets</code> from the cache. A 163 * {@see ChangesetCacheEvent} is fired. 164 * 165 * @param changesets the changesets to remove. Ignored if null. 166 */ 167 public void remove(Collection<Changeset> changesets) { 168 if (changesets == null) return; 169 DefaultChangesetCacheEvent evt = new DefaultChangesetCacheEvent(this); 170 for (Changeset cs : changesets) { 171 if (cs == null || cs.isNew()) { 172 continue; 173 } 174 remove(cs.getId(), evt); 175 } 176 if (! evt.isEmpty()) { 177 fireChangesetCacheEvent(evt); 178 } 179 } 180 113 181 public int size() { 114 182 return cache.size(); -
trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java
r2512 r2686 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 4 5 public interface NameFormatter { -
trunk/src/org/openstreetmap/josm/data/osm/UserInfo.java
r2512 r2686 9 9 public class UserInfo { 10 10 /** the user id */ 11 private longid;11 private int id; 12 12 /** the display name */ 13 13 private String displayName; … … 27 27 } 28 28 29 public longgetId() {29 public int getId() { 30 30 return id; 31 31 } 32 public void setId( longid) {32 public void setId(int id) { 33 33 this.id = id; 34 34 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java
r2512 r2686 34 34 this.coords = coords; 35 35 } 36 37 @Override 38 public String getDisplayName(HistoryNameFormatter formatter) { 39 return formatter.format(this); 40 } 36 41 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java
r2626 r2686 7 7 import java.util.Date; 8 8 import java.util.HashMap; 9 import java.util.Locale; 9 10 import java.util.Map; 10 11 … … 146 147 } 147 148 149 /** 150 * Replies the name of this primitive. The default implementation replies the value 151 * of the tag <tt>name</tt> or null, if this tag is not present. 152 * 153 * @return the name of this primitive 154 */ 155 public String getName() { 156 if (get("name") != null) 157 return get("name"); 158 return null; 159 } 160 161 /** 162 * Replies the display name of a primitive formatted by <code>formatter</code> 163 * 164 * @return the display name 165 */ 166 public abstract String getDisplayName(HistoryNameFormatter formatter); 167 168 /** 169 * Replies the a localized name for this primitive given by the value of the tags (in this order) 170 * <ul> 171 * <li>name:lang_COUNTRY_Variant of the current locale</li> 172 * <li>name:lang_COUNTRY of the current locale</li> 173 * <li>name:lang of the current locale</li> 174 * <li>name of the current locale</li> 175 * </ul> 176 * 177 * null, if no such tag exists 178 * 179 * @return the name of this primitive 180 */ 181 public String getLocalName() { 182 String key = "name:" + Locale.getDefault().toString(); 183 if (get(key) != null) 184 return get(key); 185 key = "name:" + Locale.getDefault().getLanguage() + "_" + Locale.getDefault().getCountry(); 186 if (get(key) != null) 187 return get(key); 188 key = "name:" + Locale.getDefault().getLanguage(); 189 if (get(key) != null) 190 return get(key); 191 return getName(); 192 } 193 194 195 148 196 @Override 149 197 public int hashCode() { -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java
r2512 r2686 111 111 members.add(member); 112 112 } 113 114 @Override 115 public String getDisplayName(HistoryNameFormatter formatter) { 116 return formatter.format(this); 117 } 113 118 } -
trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java
r2512 r2686 77 77 nodeIds.add(ref); 78 78 } 79 80 /** 81 * Replies true if this way is closed. 82 * 83 * @return true if this way is closed. 84 */ 85 public boolean isClosed() { 86 return getNumNodes() >= 3 && nodeIds.get(0) == nodeIds.get(nodeIds.size()-1); 87 } 88 89 @Override 90 public String getDisplayName(HistoryNameFormatter formatter) { 91 return formatter.format(this); 92 } 79 93 } -
trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java
r2578 r2686 1 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others 2 2 package org.openstreetmap.josm.data.osm.visitor; 3 4 import java.util.Collection; 3 5 4 6 import org.openstreetmap.josm.Main; … … 29 31 public void visit(Way w) { 30 32 if (w.isIncomplete()) return; 31 for (Node n : w.getNodes()) 33 for (Node n : w.getNodes()) { 32 34 visit(n); 35 } 33 36 } 34 37 … … 61 64 if(latlon != null) 62 65 { 63 if(latlon instanceof CachedLatLon) 66 if(latlon instanceof CachedLatLon) { 64 67 visit(((CachedLatLon)latlon).getEastNorth()); 65 else68 } else { 66 69 visit(Main.proj.latlon2eastNorth(latlon)); 70 } 67 71 } 68 72 } … … 70 74 public void visit(EastNorth eastNorth) { 71 75 if (eastNorth != null) { 72 if (bounds == null) 76 if (bounds == null) { 73 77 bounds = new ProjectionBounds(eastNorth); 74 else78 } else { 75 79 bounds.extend(eastNorth); 80 } 76 81 } 77 82 } … … 111 116 LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.max); 112 117 bounds = new ProjectionBounds( 113 Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)),114 Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree)));118 Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)), 119 Main.proj.latlon2eastNorth(new LatLon(maxLatlon.lat() + enlargeDegree, maxLatlon.lon() + enlargeDegree))); 115 120 } 116 121 … … 118 123 return "BoundingXYVisitor["+bounds+"]"; 119 124 } 125 126 public void computeBoundingBox(Collection<? extends OsmPrimitive> primitives) { 127 if (primitives == null) return; 128 for (OsmPrimitive p: primitives) { 129 if (p == null) { 130 continue; 131 } 132 p.visit(this); 133 } 134 } 120 135 }
Note:
See TracChangeset
for help on using the changeset viewer.