Changeset 2686 in josm


Ignore:
Timestamp:
Dec 28, 2009 12:14:33 AM (3 years ago)
Author:
Gubaer
Message:

Partial commit due to issue described in #4137
Breaks the build

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  
    6969            } 
    7070        } 
     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 
    7180        this.min = new LatLon(values[0], values[1]); 
    7281        this.max = new LatLon(values[2], values[3]); 
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r2676 r2686  
    3737     */ 
    3838    private boolean incomplete; 
     39    /** the changeset content */ 
     40    private ChangesetDataSet content = null; 
    3941 
    4042    /** 
     
    275277        this.tags = new HashMap<String, String>(other.tags); 
    276278        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; 
    277294    } 
    278295} 
  • trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java

    r2655 r2686  
    55import java.util.Collection; 
    66import java.util.HashMap; 
     7import java.util.HashSet; 
    78import java.util.List; 
    89import java.util.Map; 
     10import java.util.Set; 
    911import java.util.concurrent.CopyOnWriteArrayList; 
     12import java.util.logging.Logger; 
     13 
     14import javax.swing.SwingUtilities; 
    1015 
    1116import org.openstreetmap.josm.Main; 
     
    1318import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 
    1419 
     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 */ 
    1536public 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 */ 
    1740    static private final ChangesetCache instance = new ChangesetCache(); 
    1841 
     42    /** 
     43     * Replies the unique instance of the cache 
     44     *  
     45     * @return the unique instance of the cache 
     46     */ 
    1947    public static ChangesetCache getInstance() { 
    2048        return instance; 
    2149    } 
    2250 
     51    /** the cached changesets */ 
    2352    private final Map<Integer, Changeset> cache  = new HashMap<Integer, Changeset>(); 
    2453 
     
    3160 
    3261    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            } 
    3566        } 
    3667    } 
    3768 
    3869    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); 
    4589        } 
    4690    } 
     
    89133    } 
    90134 
     135    public Set<Changeset> getChangesets() { 
     136        return new HashSet<Changeset>(cache.values()); 
     137    } 
     138 
    91139    protected void remove(int id, DefaultChangesetCacheEvent e) { 
    92140        if (id <= 0) return; 
     
    111159    } 
    112160 
     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 
    113181    public int size() { 
    114182        return cache.size(); 
  • trunk/src/org/openstreetmap/josm/data/osm/NameFormatter.java

    r2512 r2686  
    11// License: GPL. For details, see LICENSE file. 
    22package org.openstreetmap.josm.data.osm; 
     3 
    34 
    45public interface NameFormatter { 
  • trunk/src/org/openstreetmap/josm/data/osm/UserInfo.java

    r2512 r2686  
    99public class UserInfo { 
    1010    /** the user id */ 
    11     private long id; 
     11    private int id; 
    1212    /** the display name */ 
    1313    private String displayName; 
     
    2727    } 
    2828 
    29     public long getId() { 
     29    public int getId() { 
    3030        return id; 
    3131    } 
    32     public void setId(long id) { 
     32    public void setId(int id) { 
    3333        this.id = id; 
    3434    } 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r2512 r2686  
    3434        this.coords = coords; 
    3535    } 
     36 
     37    @Override 
     38    public String getDisplayName(HistoryNameFormatter formatter) { 
     39        return formatter.format(this); 
     40    } 
    3641} 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryOsmPrimitive.java

    r2626 r2686  
    77import java.util.Date; 
    88import java.util.HashMap; 
     9import java.util.Locale; 
    910import java.util.Map; 
    1011 
     
    146147    } 
    147148 
     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 
    148196    @Override 
    149197    public int hashCode() { 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryRelation.java

    r2512 r2686  
    111111        members.add(member); 
    112112    } 
     113 
     114    @Override 
     115    public String getDisplayName(HistoryNameFormatter formatter) { 
     116        return formatter.format(this); 
     117    } 
    113118} 
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryWay.java

    r2512 r2686  
    7777        nodeIds.add(ref); 
    7878    } 
     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    } 
    7993} 
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r2578 r2686  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others 
    22package org.openstreetmap.josm.data.osm.visitor; 
     3 
     4import java.util.Collection; 
    35 
    46import org.openstreetmap.josm.Main; 
     
    2931    public void visit(Way w) { 
    3032        if (w.isIncomplete()) return; 
    31         for (Node n : w.getNodes()) 
     33        for (Node n : w.getNodes()) { 
    3234            visit(n); 
     35        } 
    3336    } 
    3437 
     
    6164        if(latlon != null) 
    6265        { 
    63             if(latlon instanceof CachedLatLon) 
     66            if(latlon instanceof CachedLatLon) { 
    6467                visit(((CachedLatLon)latlon).getEastNorth()); 
    65             else 
     68            } else { 
    6669                visit(Main.proj.latlon2eastNorth(latlon)); 
     70            } 
    6771        } 
    6872    } 
     
    7074    public void visit(EastNorth eastNorth) { 
    7175        if (eastNorth != null) { 
    72             if (bounds == null) 
     76            if (bounds == null) { 
    7377                bounds = new ProjectionBounds(eastNorth); 
    74             else 
     78            } else { 
    7579                bounds.extend(eastNorth); 
     80            } 
    7681        } 
    7782    } 
     
    111116        LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.max); 
    112117        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))); 
    115120    } 
    116121 
     
    118123        return "BoundingXYVisitor["+bounds+"]"; 
    119124    } 
     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    } 
    120135} 
Note: See TracChangeset for help on using the changeset viewer.