Ignore:
Timestamp:
2008-12-23T15:07:05+01:00 (18 years ago)
Author:
stoecker
Message:

removed usage of tab stops

Location:
trunk/src/org/openstreetmap/josm/data/osm
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r655 r1169  
    2020 */
    2121public final class Changeset /*extends OsmPrimitive*/ implements OsmWriterInterface {
    22         /**
    23         * The key/value list for this primitive.
    24         */
    25         public Map<String, String> keys;
     22    /**
     23    * The key/value list for this primitive.
     24    */
     25    public Map<String, String> keys;
    2626
    27         public long id = 0;
    28        
    29         /**
    30         * User that created this changeset, as specified by the server.
    31         * Never changed by JOSM.
    32         */
    33         public User user = null;
    34        
    35         /**
    36         * Time of last modification to this object. This is not set by JOSM but
    37         * read from the server and delivered back to the server unmodified. 
    38         */
    39         public String end_timestamp = null;
    40        
    41         /**
    42         * Time of first modification to this object. This is not set by JOSM but
    43         * read from the server and delivered back to the server unmodified.
    44         */
    45         public String start_timestamp = null;
     27    public long id = 0;
     28
     29    /**
     30    * User that created this changeset, as specified by the server.
     31    * Never changed by JOSM.
     32    */
     33    public User user = null;
     34
     35    /**
     36    * Time of last modification to this object. This is not set by JOSM but
     37    * read from the server and delivered back to the server unmodified.
     38    */
     39    public String end_timestamp = null;
     40
     41    /**
     42    * Time of first modification to this object. This is not set by JOSM but
     43    * read from the server and delivered back to the server unmodified.
     44    */
     45    public String start_timestamp = null;
    4646
    4747        private void addTags(PrintWriter out) {
    … …  
    5353        }
    5454
    55         public final void header(PrintWriter out) {
    56                 out.print("<osm version='");
     55    public final void header(PrintWriter out) {
     56            out.print("<osm version='");
    5757                out.print(Main.pref.get("osm-server.version", "0.6"));
    5858                out.println("' generator='JOSM'>");
    59         }
    60         public final void write(PrintWriter out) {
    61                 out.print("  <changeset");
    62                 if (id != 0)
    63                         out.print(" id="+id);
    64                 if (this.user != null) {
    65                         out.print(" user='"+XmlWriter.encode(this.user.name)+"'");
    66                 }
    67                 out.println(">\n");
    68                 addTags( out );
    69                 out.println("  </changeset>");
    70         }
    71         public final void footer(PrintWriter out) {
    72                 out.println("</osm>");
    73         }
    74        
    75         /******************************************************
    76          * This tag stuff is copied from OsmPrimitive. Perhaps a changeset
    77          * really is a primitive, but it's not right now. Perhaps it should
    78          * be...
    79          ******************************************************/
    80          
    81         /**
    82          * Set the given value to the given key
    83          * @param key The key, for which the value is to be set.
    84          * @param value The value for the key.
    85          */
    86         public final void put(String key, String value) {
    87                 if (value == null)
    88                         remove(key);
    89                 else {
    90                         if (keys == null)
    91                                 keys = new HashMap<String, String>();
    92                         keys.put(key, value);
    93                 }
    94         }
    95         /**
    96          * Remove the given key from the list.
    97          */
    98         public final void remove(String key) {
    99                 if (keys != null) {
    100                         keys.remove(key);
    101                         if (keys.isEmpty())
    102                                 keys = null;
    103                 }
    104         }
     59    }
     60    public final void write(PrintWriter out) {
     61        out.print("  <changeset");
     62        if (id != 0)
     63            out.print(" id="+id);
     64        if (this.user != null) {
     65            out.print(" user='"+XmlWriter.encode(this.user.name)+"'");
     66        }
     67        out.println(">\n");
     68        addTags( out );
     69        out.println("  </changeset>");
     70    }
     71    public final void footer(PrintWriter out) {
     72        out.println("</osm>");
     73    }
    10574
    106         public final String get(String key) {
    107                 return keys == null ? null : keys.get(key);
    108         }
     75    /******************************************************
     76     * This tag stuff is copied from OsmPrimitive. Perhaps a changeset
     77     * really is a primitive, but it's not right now. Perhaps it should
     78     * be...
     79     ******************************************************/
    10980
    110         public final Collection<Entry<String, String>> entrySet() {
    111                 if (keys == null)
    112                         return Collections.emptyList();
    113                 return keys.entrySet();
    114         }
     81    /**
     82     * Set the given value to the given key
     83     * @param key The key, for which the value is to be set.
     84     * @param value The value for the key.
     85     */
     86    public final void put(String key, String value) {
     87        if (value == null)
     88            remove(key);
     89        else {
     90            if (keys == null)
     91                keys = new HashMap<String, String>();
     92            keys.put(key, value);
     93        }
     94    }
     95    /**
     96     * Remove the given key from the list.
     97     */
     98    public final void remove(String key) {
     99        if (keys != null) {
     100            keys.remove(key);
     101            if (keys.isEmpty())
     102                keys = null;
     103        }
     104    }
    115105
    116         public final Collection<String> keySet() {
    117                 if (keys == null)
    118                         return Collections.emptyList();
    119                 return keys.keySet();
    120         }
     106    public final String get(String key) {
     107        return keys == null ? null : keys.get(key);
     108    }
     109
     110    public final Collection<Entry<String, String>> entrySet() {
     111        if (keys == null)
     112            return Collections.emptyList();
     113        return keys.entrySet();
     114    }
     115
     116    public final Collection<String> keySet() {
     117        if (keys == null)
     118            return Collections.emptyList();
     119        return keys.keySet();
     120    }
    121121}
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r1004 r1169  
    1717 * DataSet is the data behind the application. It can consists of only a few points up to the whole
    1818 * osm database. DataSet's can be merged together, saved, (up/down/disk)loaded etc.
    19  * 
     19 *
    2020 * Note that DataSet is not an osm-primitive and so has no key association but a few members to
    2121 * store some information.
    22  * 
     22 *
    2323 * @author imi
    2424 */
    … …  
    3333    /**
    3434     * All ways (Streets etc.) in the DataSet.
    35      * 
     35     *
    3636     * The way nodes are stored only in the way list.
    3737     */
    … …  
    235235
    236236    // Provide well-defined sorting for collections of OsmPrimitives.
    237     // FIXME: probably not a good place to put this code. 
     237    // FIXME: probably not a good place to put this code.
    238238    public static OsmPrimitive[] sort(Collection<? extends OsmPrimitive> list) {
    239239        OsmPrimitive[] selArr = new OsmPrimitive[list.size()];
  • trunk/src/org/openstreetmap/josm/data/osm/DataSource.java

    r627 r1169  
    55
    66public class DataSource implements Cloneable {
    7         public final Bounds bounds;
    8         public final String origin;
    9        
    10         public DataSource(Bounds bounds, String origin) {
    11             this.bounds = bounds;
    12             this.origin = origin;
     7    public final Bounds bounds;
     8    public final String origin;
     9
     10    public DataSource(Bounds bounds, String origin) {
     11        this.bounds = bounds;
     12        this.origin = origin;
    1313    }
    1414
    15         @Override protected Object clone() throws CloneNotSupportedException {
    16             return new DataSource(bounds, origin);
     15    @Override protected Object clone() throws CloneNotSupportedException {
     16        return new DataSource(bounds, origin);
    1717    }
    1818}
  • trunk/src/org/openstreetmap/josm/data/osm/DateFormatter.java

    r627 r1169  
    99/**
    1010 * Outputs a date in a format suitable for an OSM XML file.
    11  * 
     11 *
    1212 * @author Brett Henderson
    1313 */
    1414public class DateFormatter {
    15        
    16         private GregorianCalendar calendar;
    17        
    18        
    19         /**
    20         * Creates a new instance.
    21         */
    22         public DateFormatter() {
    23                 calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
    24         }
    25        
    26        
    27         /**
    28         * Formats a date in XML format.
    29          *
    30         * @param date
    31         *            The date to be formatted.
    32         * @return The string representing the date.
    33         */
    34         public String format(Date date) {
    35                 StringBuilder result;
    36                 int year;
    37                 int month;
    38                 int day;
    39                 int hour;
    40                 int minute;
    41                 int second;
    42                
    43                 calendar.setTime(date);
    44                
    45                 result = new StringBuilder(20);
    46                
    47                 year = calendar.get(Calendar.YEAR);
    48                 month = calendar.get(Calendar.MONTH) + 1;
    49                 day = calendar.get(Calendar.DATE);
    50                 hour = calendar.get(Calendar.HOUR_OF_DAY);
    51                 minute = calendar.get(Calendar.MINUTE);
    52                 second = calendar.get(Calendar.SECOND);
    53                
    54                 result.append(year);
    55                 result.append('-');
    56                 if (month < 10) {
    57                         result.append('0');
    58                 }
    59                 result.append(month);
    60                 result.append('-');
    61                 if (day < 10) {
    62                         result.append('0');
    63                 }
    64                 result.append(day);
    65                 result.append('T');
    66                 if (hour < 10) {
    67                         result.append('0');
    68                 }
    69                 result.append(hour);
    70                 result.append(':');
    71                 if (minute < 10) {
    72                         result.append('0');
    73                 }
    74                 result.append(minute);
    75                 result.append(':');
    76                 if (second < 10) {
    77                         result.append('0');
    78                 }
    79                 result.append(second);
    80                 result.append('Z');
    81                
    82                 return result.toString();
    83         }
     15
     16    private GregorianCalendar calendar;
     17
     18
     19    /**
     20    * Creates a new instance.
     21    */
     22    public DateFormatter() {
     23        calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
     24    }
     25
     26
     27    /**
     28    * Formats a date in XML format.
     29     *
     30    * @param date
     31    *            The date to be formatted.
     32    * @return The string representing the date.
     33    */
     34    public String format(Date date) {
     35        StringBuilder result;
     36        int year;
     37        int month;
     38        int day;
     39        int hour;
     40        int minute;
     41        int second;
     42
     43        calendar.setTime(date);
     44
     45        result = new StringBuilder(20);
     46
     47        year = calendar.get(Calendar.YEAR);
     48        month = calendar.get(Calendar.MONTH) + 1;
     49        day = calendar.get(Calendar.DATE);
     50        hour = calendar.get(Calendar.HOUR_OF_DAY);
     51        minute = calendar.get(Calendar.MINUTE);
     52        second = calendar.get(Calendar.SECOND);
     53
     54        result.append(year);
     55        result.append('-');
     56        if (month < 10) {
     57            result.append('0');
     58        }
     59        result.append(month);
     60        result.append('-');
     61        if (day < 10) {
     62            result.append('0');
     63        }
     64        result.append(day);
     65        result.append('T');
     66        if (hour < 10) {
     67            result.append('0');
     68        }
     69        result.append(hour);
     70        result.append(':');
     71        if (minute < 10) {
     72            result.append('0');
     73        }
     74        result.append(minute);
     75        result.append(':');
     76        if (second < 10) {
     77            result.append('0');
     78        }
     79        result.append(second);
     80        result.append('Z');
     81
     82        return result.toString();
     83    }
    8484}
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r1108 r1169  
    1919 */
    2020public final class Node extends OsmPrimitive {
    21        
    22         public LatLon coor;
    23         public volatile EastNorth eastNorth;
    24    
     21
     22    public LatLon coor;
     23    public volatile EastNorth eastNorth;
     24
    2525    private static CoordinateFormat mCord;
    26    
     26
    2727    static {
    2828        try {
    … …  
    3333    }
    3434
    35         /**
    36          * Create an incomplete Node object
    37          */
    38         public Node(long id) {
    39                 this.id = id;
    40                 incomplete = true;
    41         }
    42        
    43         /**
    44          * Create an identical clone of the argument (including the id)
    45          */
    46         public Node(Node clone) {
    47                 cloneFrom(clone);
    48         }
     35    /**
     36     * Create an incomplete Node object
     37     */
     38    public Node(long id) {
     39        this.id = id;
     40        incomplete = true;
     41    }
    4942
    50         public Node(LatLon latlon) {
    51                 this.coor = latlon;
    52                 eastNorth = Main.proj.latlon2eastNorth(latlon);
    53         }
     43    /**
     44     * Create an identical clone of the argument (including the id)
     45     */
     46    public Node(Node clone) {
     47        cloneFrom(clone);
     48    }
    5449
    55         @Override public void visit(Visitor visitor) {
    56                 visitor.visit(this);
    57         }
    58        
    59         @Override public void cloneFrom(OsmPrimitive osm) {
    60                 super.cloneFrom(osm);
    61                 coor = ((Node)osm).coor;
    62                 eastNorth = ((Node)osm).eastNorth;
    63         }
     50    public Node(LatLon latlon) {
     51        this.coor = latlon;
     52        eastNorth = Main.proj.latlon2eastNorth(latlon);
     53    }
    6454
    65         @Override public String toString() {
    66                 if (coor == null) return "{Node id="+id+"}";
    67                 return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
    68         }
     55    @Override public void visit(Visitor visitor) {
     56        visitor.visit(this);
     57    }
    6958
    70         @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    71                 if (osm instanceof Node) {
     59    @Override public void cloneFrom(OsmPrimitive osm) {
     60        super.cloneFrom(osm);
     61        coor = ((Node)osm).coor;
     62        eastNorth = ((Node)osm).eastNorth;
     63    }
     64
     65    @Override public String toString() {
     66        if (coor == null) return "{Node id="+id+"}";
     67        return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
     68    }
     69
     70    @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
     71        if (osm instanceof Node) {
    7272            if (super.realEqual(osm, semanticOnly)) {
    7373                if ((coor == null) && ((Node)osm).coor == null)
    … …  
    8080    }
    8181
    82         public int compareTo(OsmPrimitive o) {
    83             return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
    84         }
     82    public int compareTo(OsmPrimitive o) {
     83        return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
     84    }
    8585
    86         public String getName() {
    87                 String name;
    88                 if (incomplete) {
    89                         name = tr("incomplete");
    90                 } else {
    91                         name = get("name");
    92                         if (name == null)
    93                                 name = id == 0 ? "" : ""+id;
    94                         name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
    95                 }
    96                 return name;
    97         }
     86    public String getName() {
     87        String name;
     88        if (incomplete) {
     89            name = tr("incomplete");
     90        } else {
     91            name = get("name");
     92            if (name == null)
     93                name = id == 0 ? "" : ""+id;
     94            name += " (" + coor.latToString(mCord) + ", " + coor.lonToString(mCord) + ")";
     95        }
     96        return name;
     97    }
    9898}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r795 r1169  
    3030abstract public class OsmPrimitive implements Comparable<OsmPrimitive> {
    3131
    32         /**
    33         * The key/value list for this primitive.
    34         */
    35         public Map<String, String> keys;
    36 
    37         /**
    38         * Unique identifier in OSM. This is used to identify objects on the server.
    39         * An id of 0 means an unknown id. The object has not been uploaded yet to
    40         * know what id it will get.
    41         *
    42         * Do not write to this attribute except you know exactly what you are doing.
    43         * More specific, it is not good to set this to 0 and think the object is now
    44         * new to the server! To create a new object, call the default constructor of
    45         * the respective class.
    46         */
    47         public long id = 0;
    48 
    49         /**
    50         * <code>true</code> if the object has been modified since it was loaded from
    51         * the server. In this case, on next upload, this object will be updated.
    52         * Deleted objects are deleted from the server. If the objects are added (id=0),
    53         * the modified is ignored and the object is added to the server.
    54         */
    55         public boolean modified = false;
    56 
    57         /**
    58         * <code>true</code>, if the object has been deleted.
    59         */
    60         public boolean deleted = false;
    61 
    62         /**
    63         * Visibility status as specified by the server. The visible attribute was
    64         * introduced with the 0.4 API to be able to communicate deleted objects
    65         * (they will have visible=false). Currently JOSM does never deal with
    66         * these, so this is really for future use only.
    67         */
    68         public boolean visible = true;
    69 
    70         /**
    71         * User that last modified this primitive, as specified by the server.
    72         * Never changed by JOSM.
    73         */
    74         public User user = null;
    75 
    76         /**
    77         * true if this object is considered "tagged". To be "tagged", an object
    78         * must have one or more "non-standard" tags. "created_by" and "source"
    79         * are typically considered "standard" tags and do not make an object
    80         * "tagged".
    81         */
    82         public boolean tagged = false;
    83 
    84         /**
    85         * true if this object has direction dependent tags (e.g. oneway)
    86         */
    87         public boolean hasDirectionKeys = false;
    88 
    89         /**
    90         * If set to true, this object is currently selected.
    91         */
    92         public volatile boolean selected = false;
    93 
    94         /**
    95         * Time of last modification to this object. This is not set by JOSM but
    96         * read from the server and delivered back to the server unmodified. It is
    97         * used to check against edit conflicts.
    98         */
    99         public String timestamp = null;
    100 
    101         /**
    102         * The timestamp is only parsed when this is really necessary, and this
    103         * is the cache for the result.
    104         */
    105         public Date parsedTimestamp = null;
    106 
    107         /**
    108         * If set to true, this object is incomplete, which means only the id
    109         * and type is known (type is the objects instance class)
    110         */
    111         public boolean incomplete = false;
    112 
    113         /**
    114         * Contains the version number as returned by the API. Needed to
    115         * ensure update consistency
    116         */
    117         public int version = -1;
    118 
    119         /**
    120         * Contains a list of "uninteresting" keys that do not make an object
    121         * "tagged".
    122         * Initialized by checkTagged()
    123         */
    124         private static Collection<String> uninteresting = null;
    125 
    126         /**
    127         * Contains a list of direction-dependent keys that make an object
    128         * direction dependent.
    129         * Initialized by checkDirectionTagged()
    130         */
    131         private static Collection<String> directionKeys = null;
    132 
    133         /**
    134         * Implementation of the visitor scheme. Subclasses have to call the correct
    135         * visitor function.
    136         * @param visitor The visitor from which the visit() function must be called.
    137         */
    138         abstract public void visit(Visitor visitor);
    139 
    140         public final void delete(boolean deleted) {
    141                 this.deleted = deleted;
    142                 selected = false;
    143                 modified = true;
    144         }
    145 
    146         /**
    147         * Returns the timestamp for this object, or the current time if none is set.
    148         * Internally, parses the timestamp from XML into a Date object and caches it
    149         * for possible repeated calls.
    150         */
    151         public Date getTimestamp() {
    152                 if (parsedTimestamp == null) {
    153                         try {
    154                                 parsedTimestamp = DateParser.parse(timestamp);
    155                         } catch (ParseException ex) {
    156                                 parsedTimestamp = new Date();
    157                         }
    158                 }
    159                 return parsedTimestamp;
    160         }
    161 
    162         /**
    163         * Equal, if the id (and class) is equal.
    164         *
    165         * An primitive is equal to its incomplete counter part.
    166         */
    167         @Override public boolean equals(Object obj) {
    168                 if (id == 0) return obj == this;
    169                 if (obj instanceof OsmPrimitive) { // not null too
    170                         return ((OsmPrimitive)obj).id == id && obj.getClass() == getClass();
    171                 }
    172                 return false;
    173         }
    174 
    175         /**
    176         * Return the id plus the class type encoded as hashcode or super's hashcode if id is 0.
    177         *
    178         * An primitive has the same hashcode as its incomplete counterpart.
    179         */
    180         @Override public final int hashCode() {
    181                 if (id == 0)
    182                         return super.hashCode();
    183                 final int[] ret = new int[1];
    184                 Visitor v = new Visitor(){
    185                         public void visit(Node n) { ret[0] = 1; }
    186                         public void visit(Way w) { ret[0] = 2; }
    187                         public void visit(Relation e) { ret[0] = 3; }
    188                 };
    189                 visit(v);
    190                 return id == 0 ? super.hashCode() : (int)(id<<2)+ret[0];
    191         }
    192 
    193         /**
    194         * Set the given value to the given key
    195         * @param key The key, for which the value is to be set.
    196         * @param value The value for the key.
    197         */
    198         public final void put(String key, String value) {
    199                 if (value == null)
    200                         remove(key);
    201                 else {
    202                         if (keys == null)
    203                                 keys = new HashMap<String, String>();
    204                         keys.put(key, value);
    205                 }
    206                 checkTagged();
    207                 checkDirectionTagged();
    208         }
    209         /**
    210         * Remove the given key from the list.
    211         */
    212         public final void remove(String key) {
    213                 if (keys != null) {
    214                         keys.remove(key);
    215                         if (keys.isEmpty())
    216                                 keys = null;
    217                 }
    218                 checkTagged();
    219                 checkDirectionTagged();
    220         }
    221 
    222         public String getName() {
    223                 return null;
    224         }
    225 
    226         public final String get(String key) {
    227                 return keys == null ? null : keys.get(key);
    228         }
    229 
    230         public final Collection<Entry<String, String>> entrySet() {
    231                 if (keys == null)
    232                         return Collections.emptyList();
    233                 return keys.entrySet();
    234         }
    235 
    236         public final Collection<String> keySet() {
    237                 if (keys == null)
    238                         return Collections.emptyList();
    239                 return keys.keySet();
    240         }
    241 
    242         /**
    243         * Get and write all attributes from the parameter. Does not fire any listener, so
    244         * use this only in the data initializing phase
    245         */
    246         public void cloneFrom(OsmPrimitive osm) {
    247                 keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys);
    248                 id = osm.id;
    249                 modified = osm.modified;
    250                 deleted = osm.deleted;
    251                 selected = osm.selected;
    252                 timestamp = osm.timestamp;
    253                 version = osm.version;
    254                 tagged = osm.tagged;
    255                 incomplete = osm.incomplete;
    256         }
    257 
    258         /**
    259         * Perform an equality compare for all non-volatile fields not only for the id
    260         * but for the whole object (for conflict resolving)
    261         * @param semanticOnly if <code>true</code>, modified flag and timestamp are not compared
    262         */
    263         public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    264                 return
    265                         id == osm.id &&
    266                         incomplete == osm.incomplete &&
    267                         (semanticOnly || (modified == osm.modified)) &&
    268                         deleted == osm.deleted &&
    269                         (semanticOnly || (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp))) &&
    270                         (semanticOnly || (version==osm.version)) &&
    271                         (semanticOnly || (user == null ? osm.user==null : user==osm.user)) &&
    272                         (semanticOnly || (visible == osm.visible)) &&
    273                         (keys == null ? osm.keys==null : keys.equals(osm.keys));
    274         }
    275 
    276         public String getTimeStr() {
    277                 return timestamp == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
    278         }
    279 
    280         /**
    281         * Updates the "tagged" flag. "keys" property should probably be made private
    282         * to make sure this gets called when keys are set.
    283         */
    284         public void checkTagged() {
    285                 tagged = false;
    286                 if(uninteresting == null)
    287                         uninteresting = new HashSet<String>(Arrays.asList(Main.pref.get("tags.uninteresting",
    288                         "source;note;converted_by;created_by").split(";")));
    289                 if (keys != null) {
    290                         for (Entry<String,String> e : keys.entrySet()) {
    291                                 if (!uninteresting.contains(e.getKey())) {
    292                                         tagged = true;
    293                                         break;
    294                                 }
    295                         }
    296                 }
    297         }
    298         /**
    299         * Updates the "hasDirectionKeys" flag. "keys" property should probably be made private
    300         * to make sure this gets called when keys are set.
    301         */
    302         public void checkDirectionTagged() {
    303                 hasDirectionKeys = false;
    304                 if(directionKeys == null)
    305                         directionKeys = new HashSet<String>(Arrays.asList(Main.pref.get("tags.direction",
    306                         "oneway;incline;incline_step;aerialway").split(";")));
    307                 if (keys != null) {
    308                         for (Entry<String,String> e : keys.entrySet()) {
    309                                 if (directionKeys.contains(e.getKey())) {
    310                                         hasDirectionKeys = true;
    311                                         break;
    312                                 }
    313                         }
    314                 }
    315         }
     32    /**
     33    * The key/value list for this primitive.
     34    */
     35    public Map<String, String> keys;
     36
     37    /**
     38    * Unique identifier in OSM. This is used to identify objects on the server.
     39    * An id of 0 means an unknown id. The object has not been uploaded yet to
     40    * know what id it will get.
     41    *
     42    * Do not write to this attribute except you know exactly what you are doing.
     43    * More specific, it is not good to set this to 0 and think the object is now
     44    * new to the server! To create a new object, call the default constructor of
     45    * the respective class.
     46    */
     47    public long id = 0;
     48
     49    /**
     50    * <code>true</code> if the object has been modified since it was loaded from
     51    * the server. In this case, on next upload, this object will be updated.
     52    * Deleted objects are deleted from the server. If the objects are added (id=0),
     53    * the modified is ignored and the object is added to the server.
     54    */
     55    public boolean modified = false;
     56
     57    /**
     58    * <code>true</code>, if the object has been deleted.
     59    */
     60    public boolean deleted = false;
     61
     62    /**
     63    * Visibility status as specified by the server. The visible attribute was
     64    * introduced with the 0.4 API to be able to communicate deleted objects
     65    * (they will have visible=false). Currently JOSM does never deal with
     66    * these, so this is really for future use only.
     67    */
     68    public boolean visible = true;
     69
     70    /**
     71    * User that last modified this primitive, as specified by the server.
     72    * Never changed by JOSM.
     73    */
     74    public User user = null;
     75
     76    /**
     77    * true if this object is considered "tagged". To be "tagged", an object
     78    * must have one or more "non-standard" tags. "created_by" and "source"
     79    * are typically considered "standard" tags and do not make an object
     80    * "tagged".
     81    */
     82    public boolean tagged = false;
     83
     84    /**
     85    * true if this object has direction dependent tags (e.g. oneway)
     86    */
     87    public boolean hasDirectionKeys = false;
     88
     89    /**
     90    * If set to true, this object is currently selected.
     91    */
     92    public volatile boolean selected = false;
     93
     94    /**
     95    * Time of last modification to this object. This is not set by JOSM but
     96    * read from the server and delivered back to the server unmodified. It is
     97    * used to check against edit conflicts.
     98    */
     99    public String timestamp = null;
     100
     101    /**
     102    * The timestamp is only parsed when this is really necessary, and this
     103    * is the cache for the result.
     104    */
     105    public Date parsedTimestamp = null;
     106
     107    /**
     108    * If set to true, this object is incomplete, which means only the id
     109    * and type is known (type is the objects instance class)
     110    */
     111    public boolean incomplete = false;
     112
     113    /**
     114    * Contains the version number as returned by the API. Needed to
     115    * ensure update consistency
     116    */
     117    public int version = -1;
     118
     119    /**
     120    * Contains a list of "uninteresting" keys that do not make an object
     121    * "tagged".
     122    * Initialized by checkTagged()
     123    */
     124    private static Collection<String> uninteresting = null;
     125
     126    /**
     127    * Contains a list of direction-dependent keys that make an object
     128    * direction dependent.
     129    * Initialized by checkDirectionTagged()
     130    */
     131    private static Collection<String> directionKeys = null;
     132
     133    /**
     134    * Implementation of the visitor scheme. Subclasses have to call the correct
     135    * visitor function.
     136    * @param visitor The visitor from which the visit() function must be called.
     137    */
     138    abstract public void visit(Visitor visitor);
     139
     140    public final void delete(boolean deleted) {
     141        this.deleted = deleted;
     142        selected = false;
     143        modified = true;
     144    }
     145
     146    /**
     147    * Returns the timestamp for this object, or the current time if none is set.
     148    * Internally, parses the timestamp from XML into a Date object and caches it
     149    * for possible repeated calls.
     150    */
     151    public Date getTimestamp() {
     152        if (parsedTimestamp == null) {
     153            try {
     154                parsedTimestamp = DateParser.parse(timestamp);
     155            } catch (ParseException ex) {
     156                parsedTimestamp = new Date();
     157            }
     158        }
     159        return parsedTimestamp;
     160    }
     161
     162    /**
     163    * Equal, if the id (and class) is equal.
     164    *
     165    * An primitive is equal to its incomplete counter part.
     166    */
     167    @Override public boolean equals(Object obj) {
     168        if (id == 0) return obj == this;
     169        if (obj instanceof OsmPrimitive) { // not null too
     170            return ((OsmPrimitive)obj).id == id && obj.getClass() == getClass();
     171        }
     172        return false;
     173    }
     174
     175    /**
     176    * Return the id plus the class type encoded as hashcode or super's hashcode if id is 0.
     177    *
     178    * An primitive has the same hashcode as its incomplete counterpart.
     179    */
     180    @Override public final int hashCode() {
     181        if (id == 0)
     182            return super.hashCode();
     183        final int[] ret = new int[1];
     184        Visitor v = new Visitor(){
     185            public void visit(Node n) { ret[0] = 1; }
     186            public void visit(Way w) { ret[0] = 2; }
     187            public void visit(Relation e) { ret[0] = 3; }
     188        };
     189        visit(v);
     190        return id == 0 ? super.hashCode() : (int)(id<<2)+ret[0];
     191    }
     192
     193    /**
     194    * Set the given value to the given key
     195    * @param key The key, for which the value is to be set.
     196    * @param value The value for the key.
     197    */
     198    public final void put(String key, String value) {
     199        if (value == null)
     200            remove(key);
     201        else {
     202            if (keys == null)
     203                keys = new HashMap<String, String>();
     204            keys.put(key, value);
     205        }
     206        checkTagged();
     207        checkDirectionTagged();
     208    }
     209    /**
     210    * Remove the given key from the list.
     211    */
     212    public final void remove(String key) {
     213        if (keys != null) {
     214            keys.remove(key);
     215            if (keys.isEmpty())
     216                keys = null;
     217        }
     218        checkTagged();
     219        checkDirectionTagged();
     220    }
     221
     222    public String getName() {
     223        return null;
     224    }
     225
     226    public final String get(String key) {
     227        return keys == null ? null : keys.get(key);
     228    }
     229
     230    public final Collection<Entry<String, String>> entrySet() {
     231        if (keys == null)
     232            return Collections.emptyList();
     233        return keys.entrySet();
     234    }
     235
     236    public final Collection<String> keySet() {
     237        if (keys == null)
     238            return Collections.emptyList();
     239        return keys.keySet();
     240    }
     241
     242    /**
     243    * Get and write all attributes from the parameter. Does not fire any listener, so
     244    * use this only in the data initializing phase
     245    */
     246    public void cloneFrom(OsmPrimitive osm) {
     247        keys = osm.keys == null ? null : new HashMap<String, String>(osm.keys);
     248        id = osm.id;
     249        modified = osm.modified;
     250        deleted = osm.deleted;
     251        selected = osm.selected;
     252        timestamp = osm.timestamp;
     253        version = osm.version;
     254        tagged = osm.tagged;
     255        incomplete = osm.incomplete;
     256    }
     257
     258    /**
     259    * Perform an equality compare for all non-volatile fields not only for the id
     260    * but for the whole object (for conflict resolving)
     261    * @param semanticOnly if <code>true</code>, modified flag and timestamp are not compared
     262    */
     263    public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
     264        return
     265            id == osm.id &&
     266            incomplete == osm.incomplete &&
     267            (semanticOnly || (modified == osm.modified)) &&
     268            deleted == osm.deleted &&
     269            (semanticOnly || (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp))) &&
     270            (semanticOnly || (version==osm.version)) &&
     271            (semanticOnly || (user == null ? osm.user==null : user==osm.user)) &&
     272            (semanticOnly || (visible == osm.visible)) &&
     273            (keys == null ? osm.keys==null : keys.equals(osm.keys));
     274    }
     275
     276    public String getTimeStr() {
     277        return timestamp == null ? null : new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
     278    }
     279
     280    /**
     281    * Updates the "tagged" flag. "keys" property should probably be made private
     282    * to make sure this gets called when keys are set.
     283    */
     284    public void checkTagged() {
     285        tagged = false;
     286        if(uninteresting == null)
     287            uninteresting = new HashSet<String>(Arrays.asList(Main.pref.get("tags.uninteresting",
     288            "source;note;converted_by;created_by").split(";")));
     289        if (keys != null) {
     290            for (Entry<String,String> e : keys.entrySet()) {
     291                if (!uninteresting.contains(e.getKey())) {
     292                    tagged = true;
     293                    break;
     294                }
     295            }
     296        }
     297    }
     298    /**
     299    * Updates the "hasDirectionKeys" flag. "keys" property should probably be made private
     300    * to make sure this gets called when keys are set.
     301    */
     302    public void checkDirectionTagged() {
     303        hasDirectionKeys = false;
     304        if(directionKeys == null)
     305            directionKeys = new HashSet<String>(Arrays.asList(Main.pref.get("tags.direction",
     306            "oneway;incline;incline_step;aerialway").split(";")));
     307        if (keys != null) {
     308            for (Entry<String,String> e : keys.entrySet()) {
     309                if (directionKeys.contains(e.getKey())) {
     310                    hasDirectionKeys = true;
     311                    break;
     312                }
     313            }
     314        }
     315    }
    316316}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java

    r702 r1169  
    88public class OsmUtils {
    99
    10         static ArrayList<String> TRUE_VALUES = new ArrayList<String>(Arrays
    11                 .asList(new String[] { "true", "yes", "1", "on" }));
    12         static ArrayList<String> FALSE_VALUES = new ArrayList<String>(Arrays
    13                 .asList(new String[] { "false", "no", "0", "off" }));
     10    static ArrayList<String> TRUE_VALUES = new ArrayList<String>(Arrays
     11            .asList(new String[] { "true", "yes", "1", "on" }));
     12    static ArrayList<String> FALSE_VALUES = new ArrayList<String>(Arrays
     13            .asList(new String[] { "false", "no", "0", "off" }));
    1414
    15         public static final String trueval = "yes";
    16         public static final String falseval = "no";
     15    public static final String trueval = "yes";
     16    public static final String falseval = "no";
    1717
    18         public static Boolean getOsmBoolean(String value) {
    19                 if(value == null) return null;
    20                 String lowerValue = value.toLowerCase(Locale.ENGLISH);
    21                 if (TRUE_VALUES.contains(lowerValue)) return Boolean.TRUE;
    22                 if (FALSE_VALUES.contains(lowerValue)) return Boolean.FALSE;
    23                 return null;
    24         }
    25         public static String getNamedOsmBoolean(String value) {
    26                 Boolean res = getOsmBoolean(value);
    27                 return res == null ? value : (res ? trueval : falseval);
    28         }
     18    public static Boolean getOsmBoolean(String value) {
     19        if(value == null) return null;
     20        String lowerValue = value.toLowerCase(Locale.ENGLISH);
     21        if (TRUE_VALUES.contains(lowerValue)) return Boolean.TRUE;
     22        if (FALSE_VALUES.contains(lowerValue)) return Boolean.FALSE;
     23        return null;
     24    }
     25    public static String getNamedOsmBoolean(String value) {
     26        Boolean res = getOsmBoolean(value);
     27        return res == null ? value : (res ? trueval : falseval);
     28    }
    2929}
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r1162 r1169  
    1111/**
    1212 * An relation, having a set of tags and any number (0...n) of members.
    13  * 
     13 *
    1414 * @author Frederik Ramm <frederik@remote.org>
    1515 */
    1616public final class Relation extends OsmPrimitive {
    17        
    18         /**
    19          * All members of this relation. Note that after changing this,
    20          * makeBackReferences and/or removeBackReferences should be called.
    21          */
    22         public final List<RelationMember> members = new ArrayList<RelationMember>();
    2317
    24         @Override public void visit(Visitor visitor) {
    25                 visitor.visit(this);
    26         }
     18    /**
     19     * All members of this relation. Note that after changing this,
     20     * makeBackReferences and/or removeBackReferences should be called.
     21     */
     22    public final List<RelationMember> members = new ArrayList<RelationMember>();
    2723
    28         /**
    29          * Create an identical clone of the argument (including the id)
    30          */
    31         public Relation(Relation clone) {
    32                 cloneFrom(clone);
    33         }
    34        
    35         /**
    36          * Create an incomplete Relation.
    37          */
    38         public Relation(long id) {
    39                 this.id = id;
    40                 incomplete = true;
    41         }
    42        
    43         /**
    44          * Create an empty Relation. Use this only if you set meaningful values
    45          * afterwards.
    46          */
    47         public Relation() {     
    48         }
    49        
    50         @Override public void cloneFrom(OsmPrimitive osm) {
    51                 super.cloneFrom(osm);
    52                 members.clear();
    53                 // we must not add the members themselves, but instead
    54                 // add clones of the members
    55                 for (RelationMember em : ((Relation)osm).members) {
    56                         members.add(new RelationMember(em));
    57                 }
    58         }
     24    @Override public void visit(Visitor visitor) {
     25        visitor.visit(this);
     26    }
    5927
    60         @Override public String toString() {
    61                 // return "{Relation id="+id+" version="+version+" members="+Arrays.toString(members.toArray())+"}";
    62                 // adding members in string increases memory usage a lot and overflows for looped relations
    63                 return "{Relation id="+id+" version="+version+"}";
    64         }
     28    /**
     29     * Create an identical clone of the argument (including the id)
     30     */
     31    public Relation(Relation clone) {
     32        cloneFrom(clone);
     33    }
    6534
    66         @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    67                 return osm instanceof Relation ? super.realEqual(osm, semanticOnly) && members.equals(((Relation)osm).members) : false;
    68         }
     35    /**
     36     * Create an incomplete Relation.
     37     */
     38    public Relation(long id) {
     39        this.id = id;
     40        incomplete = true;
     41    }
    6942
    70         public int compareTo(OsmPrimitive o) {
    71             return o instanceof Relation ? Long.valueOf(id).compareTo(o.id) : -1;
    72         }
     43    /**
     44     * Create an empty Relation. Use this only if you set meaningful values
     45     * afterwards.
     46     */
     47    public Relation() {
     48    }
    7349
    74         public String getName() {
    75                 String name;
    76                 if (incomplete) {
    77                         name = tr("incomplete");
    78                 } else {
    79                         name = get("type");
    80                         // FIXME add names of members
    81                         if (name == null)
    82                                 name = tr("relation");
    83                        
    84                         name += " (";
    85                         String nameTag = get("name");
    86                         if (nameTag == null) nameTag = get("ref");
    87                         if (nameTag == null) nameTag = get("note");
    88                         if (nameTag != null) name += "\"" + nameTag + "\", ";
    89                         int mbno = members.size();
    90                         name += trn("{0} member", "{0} members", mbno, mbno) + ")";
    91                 }
    92                 return name;
    93         }
     50    @Override public void cloneFrom(OsmPrimitive osm) {
     51        super.cloneFrom(osm);
     52        members.clear();
     53        // we must not add the members themselves, but instead
     54        // add clones of the members
     55        for (RelationMember em : ((Relation)osm).members) {
     56            members.add(new RelationMember(em));
     57        }
     58    }
    9459
    95         public boolean isIncomplete() {
    96                 for (RelationMember m : members)
    97                         if (m.member == null)
    98                                 return true;
    99                 return false;
    100         }
     60    @Override public String toString() {
     61        // return "{Relation id="+id+" version="+version+" members="+Arrays.toString(members.toArray())+"}";
     62        // adding members in string increases memory usage a lot and overflows for looped relations
     63        return "{Relation id="+id+" version="+version+"}";
     64    }
     65
     66    @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
     67        return osm instanceof Relation ? super.realEqual(osm, semanticOnly) && members.equals(((Relation)osm).members) : false;
     68    }
     69
     70    public int compareTo(OsmPrimitive o) {
     71        return o instanceof Relation ? Long.valueOf(id).compareTo(o.id) : -1;
     72    }
     73
     74    public String getName() {
     75        String name;
     76        if (incomplete) {
     77            name = tr("incomplete");
     78        } else {
     79            name = get("type");
     80            // FIXME add names of members
     81            if (name == null)
     82                name = tr("relation");
     83
     84            name += " (";
     85            String nameTag = get("name");
     86            if (nameTag == null) nameTag = get("ref");
     87            if (nameTag == null) nameTag = get("note");
     88            if (nameTag != null) name += "\"" + nameTag + "\", ";
     89            int mbno = members.size();
     90            name += trn("{0} member", "{0} members", mbno, mbno) + ")";
     91        }
     92        return name;
     93    }
     94
     95    public boolean isIncomplete() {
     96        for (RelationMember m : members)
     97            if (m.member == null)
     98                return true;
     99        return false;
     100    }
    101101}
  • trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java

    r627 r1169  
    22
    33/**
    4  * A linkage class that can be used by an relation to keep a list of 
     4 * A linkage class that can be used by an relation to keep a list of
    55 * members. Since membership may be qualified by a "role", a simple
    66 * list is not sufficient.
    7  * 
     7 *
    88 * @author Frederik Ramm <frederik@remote.org>
    99 */
    1010public class RelationMember {
    1111
    12         public String role;
    13         public OsmPrimitive member;
    14        
    15         /**
    16          * Default constructor. Does nothing.
    17          */
    18         public RelationMember() { }
     12    public String role;
     13    public OsmPrimitive member;
    1914
    20         public RelationMember(String role, OsmPrimitive member) {
    21                 this.role = role;
    22                 this.member = member;
    23         }
    24        
    25         /**
    26          * Copy constructor.
    27          * @param other relation member to be copied.
    28          */
    29         public RelationMember(RelationMember other) {
    30                 role = other.role;
    31                 member = other.member;
    32         }
    33        
    34         @Override public boolean equals(Object other) {
    35                 if (!(other instanceof RelationMember)) return false;
    36                 RelationMember otherMember = (RelationMember) other;
    37                 return otherMember.role.equals(role) && otherMember.member.equals(member);
    38         }
     15    /**
     16     * Default constructor. Does nothing.
     17     */
     18    public RelationMember() { }
    3919
    40         @Override public String toString() {
    41                 return '"' + role + "\"=" + member;
    42         }
     20    public RelationMember(String role, OsmPrimitive member) {
     21        this.role = role;
     22        this.member = member;
     23    }
     24
     25    /**
     26     * Copy constructor.
     27     * @param other relation member to be copied.
     28     */
     29    public RelationMember(RelationMember other) {
     30        role = other.role;
     31        member = other.member;
     32    }
     33
     34    @Override public boolean equals(Object other) {
     35        if (!(other instanceof RelationMember)) return false;
     36        RelationMember otherMember = (RelationMember) other;
     37        return otherMember.role.equals(role) && otherMember.member.equals(member);
     38    }
     39
     40    @Override public String toString() {
     41        return '"' + role + "\"=" + member;
     42    }
    4343}
  • trunk/src/org/openstreetmap/josm/data/osm/TigerUtils.java

    r627 r1169  
    55import java.util.TreeSet;
    66
    7 /** 
     7/**
    88 * A simple class to keep helper functions for merging TIGER data
    9  * 
     9 *
    1010 * @author daveh
    1111 *
    1212 */
    1313public class TigerUtils {
    14        
    15         public static boolean isTigerTag(String tag)
    16         {       
    17                 if (tag.indexOf("tiger:") == -1)
    18                         return false;
    19                 return true;
    20         }
    21        
    22         public static boolean tagIsInt(String name) {
    23                 if (name.equals("tiger:tlid"))
    24                         return true;
    25                 return false;
    26         }
    27        
    28         public static Object tagObj(String name) {
    29                 if (tagIsInt(name))
    30                         return new Integer(name);
    31                 return name;
    32         }
    33        
    34         public static String combineTags(String name, Set<String> values) {
     14
     15    public static boolean isTigerTag(String tag)
     16    {
     17        if (tag.indexOf("tiger:") == -1)
     18            return false;
     19        return true;
     20    }
     21
     22    public static boolean tagIsInt(String name) {
     23        if (name.equals("tiger:tlid"))
     24            return true;
     25        return false;
     26    }
     27
     28    public static Object tagObj(String name) {
     29        if (tagIsInt(name))
     30            return new Integer(name);
     31        return name;
     32    }
     33
     34    public static String combineTags(String name, Set<String> values) {
    3535        TreeSet<Object> resultSet = new TreeSet<Object>();
    3636        for (String value: values) {
    37                 for (String part: value.split(":")) {
     37            for (String part: value.split(":")) {
    3838               resultSet.add(tagObj(part));
    3939            }
    … …  
    4242        for (Object part : resultSet) {
    4343            if (combined.length() > 0)
    44                         combined += ":";
    45                 combined += part;
     44                combined += ":";
     45            combined += part;
    4646        }
    47                 return combined;
    48         }
    49        
    50         public static String combineTags(String name, String t1, String t2) {
    51                 Set<String> set = new TreeSet<String>();
    52                 set.add(t1);
    53                 set.add(t2);
    54                 return TigerUtils.combineTags(name, set);
    55         }
     47        return combined;
     48    }
     49
     50    public static String combineTags(String name, String t1, String t2) {
     51        Set<String> set = new TreeSet<String>();
     52        set.add(t1);
     53        set.add(t2);
     54        return TigerUtils.combineTags(name, set);
     55    }
    5656}
  • trunk/src/org/openstreetmap/josm/data/osm/User.java

    r655 r1169  
    44import java.util.HashMap;
    55
    6 /** 
     6/**
    77 * A simple class to keep a list of user names.
    8  * 
     8 *
    99 * Instead of storing user names as strings with every OSM primitive, we store
    1010 * a reference to an user object, and make sure that for each username there
    1111 * is only one user object.
    12  * 
     12 *
    1313 * @author fred
    1414 *
    … …  
    1616public class User {
    1717
    18         /** storage for existing User objects. */
    19         private static HashMap<String,User> userMap = new HashMap<String,User>();
    20        
    21         /** the username. */
    22         public String name;
    23        
    24         /** private constructor, only called from get method. */
    25         private User(String name) {
    26                 this.name = name;
    27         }
    28        
    29         /** returns a new or existing User object that represents the given name. */
    30         public static User get(String name) {
    31                 User user = userMap.get(name);
    32                 if (user == null) {
    33                         user = new User(name);
    34                         userMap.put(name, user);
    35                 }
    36                 return user;
    37         }
     18    /** storage for existing User objects. */
     19    private static HashMap<String,User> userMap = new HashMap<String,User>();
     20
     21    /** the username. */
     22    public String name;
     23
     24    /** private constructor, only called from get method. */
     25    private User(String name) {
     26        this.name = name;
     27    }
     28
     29    /** returns a new or existing User object that represents the given name. */
     30    public static User get(String name) {
     31        User user = userMap.get(name);
     32        if (user == null) {
     33            user = new User(name);
     34            userMap.put(name, user);
     35        }
     36        return user;
     37    }
    3838}
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r755 r1169  
    2121public final class Way extends OsmPrimitive {
    2222
    23         /**
    24         * All way nodes in this way
    25         */
    26         public final List<Node> nodes = new ArrayList<Node>();
     23    /**
     24    * All way nodes in this way
     25    */
     26    public final List<Node> nodes = new ArrayList<Node>();
    2727
    28         public void visitNodes(Visitor v) {
    29                 for (Node n : this.nodes)
    30                         v.visit(n);
    31         }
     28    public void visitNodes(Visitor v) {
     29        for (Node n : this.nodes)
     30            v.visit(n);
     31    }
    3232
    33         public ArrayList<Pair<Node,Node>> getNodePairs(boolean sort) {
    34                 ArrayList<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
    35                 Node lastN = null;
    36                 for (Node n : this.nodes) {
     33    public ArrayList<Pair<Node,Node>> getNodePairs(boolean sort) {
     34        ArrayList<Pair<Node,Node>> chunkSet = new ArrayList<Pair<Node,Node>>();
     35        Node lastN = null;
     36        for (Node n : this.nodes) {
    3737            if (lastN == null) {
    38                     lastN = n;
    39                         continue;
    40                     }
    41                         Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
    42                 if (sort) {
    43                         Pair.sort(np);
    44                 }
    45                 chunkSet.add(np);
    46                 lastN = n;
    47                 }
    48                 return chunkSet;
    49         }
     38                lastN = n;
     39                continue;
     40            }
     41            Pair<Node,Node> np = new Pair<Node,Node>(lastN, n);
     42            if (sort) {
     43                Pair.sort(np);
     44            }
     45            chunkSet.add(np);
     46            lastN = n;
     47        }
     48        return chunkSet;
     49    }
    5050
    5151
    52         @Override public void visit(Visitor visitor) {
    53                 visitor.visit(this);
    54         }
     52    @Override public void visit(Visitor visitor) {
     53        visitor.visit(this);
     54    }
    5555
    56         /**
    57         * Create an identical clone of the argument (including the id)
    58         */
    59         public Way(Way clone) {
    60             cloneFrom(clone);           
    61         }
    62        
    63         /**
    64         * Create an empty way without id. Use this only if you set meaningful 
    65         * values yourself.
    66         */
    67         public Way() {
    68         }
    69        
    70         /**
    71         * Create an incomplete Way.
    72         */
    73         public Way(long id) {
    74                 this.id = id;
    75                 incomplete = true;
    76         }
    77        
    78         @Override public void cloneFrom(OsmPrimitive osm) {
    79                 super.cloneFrom(osm);
    80                 nodes.clear();
    81                 nodes.addAll(((Way)osm).nodes);
     56    /**
     57    * Create an identical clone of the argument (including the id)
     58    */
     59    public Way(Way clone) {
     60            cloneFrom(clone);
     61    }
     62
     63    /**
     64    * Create an empty way without id. Use this only if you set meaningful
     65    * values yourself.
     66    */
     67    public Way() {
     68    }
     69
     70    /**
     71    * Create an incomplete Way.
     72    */
     73    public Way(long id) {
     74        this.id = id;
     75        incomplete = true;
     76    }
     77
     78    @Override public void cloneFrom(OsmPrimitive osm) {
     79        super.cloneFrom(osm);
     80        nodes.clear();
     81        nodes.addAll(((Way)osm).nodes);
    8282                checkDirectionTagged();
    83         }
     83    }
    8484
    8585    @Override public String toString() {
    … …  
    8787    }
    8888
    89         @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
    90                 return osm instanceof Way ? super.realEqual(osm, semanticOnly) && nodes.equals(((Way)osm).nodes) : false;
     89    @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) {
     90        return osm instanceof Way ? super.realEqual(osm, semanticOnly) && nodes.equals(((Way)osm).nodes) : false;
    9191    }
    9292
    93         public int compareTo(OsmPrimitive o) {
    94                 if(o instanceof Relation)
    95                         return 1;
    96                 return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1;
    97         }
     93    public int compareTo(OsmPrimitive o) {
     94        if(o instanceof Relation)
     95            return 1;
     96        return o instanceof Way ? Long.valueOf(id).compareTo(o.id) : -1;
     97    }
    9898
    99         public String getName() {
    100                 String name;
    101                 if (incomplete) {
    102                         name = tr("incomplete");
    103                 } else {
    104                         name = get("name");
    105                         if (name == null) name = get("ref");
    106                         if (name == null) {
    107                                 name =
    108                                         (get("highway") != null) ? tr("highway") :
    109                                         (get("railway") != null) ? tr("railway") :
    110                                         (get("waterway") != null) ? tr("waterway") :
    111                                         (get("landuse") != null) ? tr("landuse") : "";
    112                         }
     99    public String getName() {
     100        String name;
     101        if (incomplete) {
     102            name = tr("incomplete");
     103        } else {
     104            name = get("name");
     105            if (name == null) name = get("ref");
     106            if (name == null) {
     107                name =
     108                    (get("highway") != null) ? tr("highway") :
     109                    (get("railway") != null) ? tr("railway") :
     110                    (get("waterway") != null) ? tr("waterway") :
     111                    (get("landuse") != null) ? tr("landuse") : "";
     112            }
    113113
    114                         int nodesNo = new HashSet<Node>(nodes).size();
    115                         name += trn(" ({0} node)", " ({0} nodes)", nodesNo, nodesNo);
    116                 }
    117                 return name;
    118         }
     114            int nodesNo = new HashSet<Node>(nodes).size();
     115            name += trn(" ({0} node)", " ({0} nodes)", nodesNo, nodesNo);
     116        }
     117        return name;
     118    }
    119119
    120         @Deprecated
    121         public boolean isIncomplete() {
    122                 return incomplete;
    123         }
     120    @Deprecated
     121    public boolean isIncomplete() {
     122        return incomplete;
     123    }
    124124}
  • trunk/src/org/openstreetmap/josm/data/osm/WaySegment.java

    r627 r1169  
    66 */
    77public final class WaySegment {
    8         /**
    9         * The way.
    10         */
    11         public Way way;
     8    /**
     9    * The way.
     10    */
     11    public Way way;
    1212
    13         /**
    14         * The index of one of the 2 nodes in the way.  The other node has the
    15         * index <code>lowerIndex + 1</code>.
    16         */
    17         public int lowerIndex;
     13    /**
     14    * The index of one of the 2 nodes in the way.  The other node has the
     15    * index <code>lowerIndex + 1</code>.
     16    */
     17    public int lowerIndex;
    1818
    19         public WaySegment(Way w, int i) {
    20                 way = w;
    21                 lowerIndex = i;
    22         }
     19    public WaySegment(Way w, int i) {
     20        way = w;
     21        lowerIndex = i;
     22    }
    2323
    24         @Override public boolean equals(Object o) {
    25                 return o != null && o instanceof WaySegment
    26                         && ((WaySegment) o).way == way
    27                         && ((WaySegment) o).lowerIndex == lowerIndex;
    28         }
     24    @Override public boolean equals(Object o) {
     25        return o != null && o instanceof WaySegment
     26            && ((WaySegment) o).way == way
     27            && ((WaySegment) o).lowerIndex == lowerIndex;
     28    }
    2929
    30         @Override public int hashCode() {
    31                 return way.hashCode() ^ lowerIndex;
    32         }
     30    @Override public int hashCode() {
     31        return way.hashCode() ^ lowerIndex;
     32    }
    3333}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/AddVisitor.java

    r655 r1169  
    99/**
    1010 * Visitor that adds the visited object to the dataset given at constructor.
    11  * 
     11 *
    1212 * Is not capable of adding keys.
    13  * 
     13 *
    1414 * @author imi
    1515 */
    1616public class AddVisitor implements Visitor {
    17        
    18         protected final DataSet ds;
    19        
    20         public AddVisitor(DataSet ds) {
    21                 this.ds = ds;
    22         }
    23        
    24         public void visit(Node n) {
    25                 ds.nodes.add(n);
    26         }
    27         public void visit(Way w) {
    28                 ds.ways.add(w);
    29         }
    30         public void visit(Relation e) {
    31                 ds.relations.add(e);
    32         }
     17
     18    protected final DataSet ds;
     19
     20    public AddVisitor(DataSet ds) {
     21        this.ds = ds;
     22    }
     23
     24    public void visit(Node n) {
     25        ds.nodes.add(n);
     26    }
     27    public void visit(Way w) {
     28        ds.ways.add(w);
     29    }
     30    public void visit(Relation e) {
     31        ds.relations.add(e);
     32    }
    3333}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r627 r1169  
    1313/**
    1414 * Collect all nodes a specific osm primitive has.
    15  * 
     15 *
    1616 * @author imi
    1717 */
    1818public class AllNodesVisitor implements Visitor {
    1919
    20         /**
    21         * The resulting nodes collected so far.
    22         */
    23         public Collection<Node> nodes = new HashSet<Node>();
     20    /**
     21    * The resulting nodes collected so far.
     22    */
     23    public Collection<Node> nodes = new HashSet<Node>();
    2424
    25         /**
    26         * Nodes have only itself as nodes.
    27         */
    28         public void visit(Node n) {
    29                 nodes.add(n);
    30         }
     25    /**
     26    * Nodes have only itself as nodes.
     27    */
     28    public void visit(Node n) {
     29        nodes.add(n);
     30    }
    3131
    32         /**
    33         * Ways have their way nodes.
    34         */
    35         public void visit(Way w) {
    36                 w.visitNodes(this);
    37         }
     32    /**
     33    * Ways have their way nodes.
     34    */
     35    public void visit(Way w) {
     36        w.visitNodes(this);
     37    }
    3838
    39         /**
    40         * Relations may have any number of nodes.
    41         * FIXME: do we want to collect nodes from segs/ways that are relation members?
    42         * if so, use AutomatchVisitor!
    43         */
    44         public void visit(Relation e) {
    45                 for (RelationMember m : e.members)
    46                         if (m.member instanceof Node) visit((Node)m.member);
    47         }
    48         /**
    49         * @return All nodes the given primitive has.
    50         */
    51         public static Collection<Node> getAllNodes(Collection<? extends OsmPrimitive> osms) {
    52                 AllNodesVisitor v = new AllNodesVisitor();
    53                 for (OsmPrimitive osm : osms)
    54                         osm.visit(v);
    55                 return v.nodes;
    56         }
     39    /**
     40    * Relations may have any number of nodes.
     41    * FIXME: do we want to collect nodes from segs/ways that are relation members?
     42    * if so, use AutomatchVisitor!
     43    */
     44    public void visit(Relation e) {
     45        for (RelationMember m : e.members)
     46            if (m.member instanceof Node) visit((Node)m.member);
     47    }
     48    /**
     49    * @return All nodes the given primitive has.
     50    */
     51    public static Collection<Node> getAllNodes(Collection<? extends OsmPrimitive> osms) {
     52        AllNodesVisitor v = new AllNodesVisitor();
     53        for (OsmPrimitive osm : osms)
     54            osm.visit(v);
     55        return v.nodes;
     56    }
    5757}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r948 r1169  
    1212
    1313/**
    14  * Calculates the total bounding rectangle of a series of {@link OsmPrimitive} objects, using the 
     14 * Calculates the total bounding rectangle of a series of {@link OsmPrimitive} objects, using the
    1515 * EastNorth values as reference.
    1616 * @author imi
    … …  
    6161
    6262    /**
    63      * Enlarges the calculated bounding box by 0.0001 degrees. 
     63     * Enlarges the calculated bounding box by 0.0001 degrees.
    6464     * If the bounding box has not been set (<code>min</code> or <code>max</code>
    6565     * equal <code>null</code>) this method does not do anything.
    66      *   
     66     *
    6767     * @param enlargeDegree
    6868     */
    … …  
    7272
    7373    /**
    74      * Enlarges the calculated bounding box by the specified number of degrees. 
     74     * Enlarges the calculated bounding box by the specified number of degrees.
    7575     * If the bounding box has not been set (<code>min</code> or <code>max</code>
    7676     * equal <code>null</code>) this method does not do anything.
    77      *   
     77     *
    7878     * @param enlargeDegree
    7979     */
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r627 r1169  
    1414/**
    1515 * Helper that collect all ways a node is part of.
    16  * 
     16 *
    1717 * Deleted objects are not collected.
    18  * 
     18 *
    1919 * @author imi
    2020 */
    2121public class CollectBackReferencesVisitor implements Visitor {
    2222
    23         private final DataSet ds;
    24         private final boolean indirectRefs;
     23    private final DataSet ds;
     24    private final boolean indirectRefs;
    2525
    26         /**
    27         * The result list of primitives stored here.
    28         */
    29         public final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>();
     26    /**
     27    * The result list of primitives stored here.
     28    */
     29    public final Collection<OsmPrimitive> data = new HashSet<OsmPrimitive>();
    3030
    3131
    32         /**
    33         * Construct a back reference counter.
    34         * @param ds The dataset to operate on.
    35         */
    36         public CollectBackReferencesVisitor(DataSet ds) {
    37                 this.ds = ds;
    38                 this.indirectRefs = true;
    39         }
     32    /**
     33    * Construct a back reference counter.
     34    * @param ds The dataset to operate on.
     35    */
     36    public CollectBackReferencesVisitor(DataSet ds) {
     37        this.ds = ds;
     38        this.indirectRefs = true;
     39    }
    4040
    41         public CollectBackReferencesVisitor(DataSet ds, boolean indirectRefs) {
    42                 this.ds = ds;
    43                 this.indirectRefs = indirectRefs;
    44         }
     41    public CollectBackReferencesVisitor(DataSet ds, boolean indirectRefs) {
     42        this.ds = ds;
     43        this.indirectRefs = indirectRefs;
     44    }
    4545
    46         public void visit(Node n) {
    47                 for (Way w : ds.ways) {
    48                         if (w.deleted || w.incomplete) continue;
    49                         for (Node n2 : w.nodes) {
    50                                 if (n == n2) {
    51                                         data.add(w);
    52                                         if (indirectRefs) {
    53                                                 visit(w);
    54                                         }
    55                                 }
    56                         }
    57                 }
    58                 checkRelationMembership(n);
    59         }
    60        
    61         public void visit(Way w) {
    62                 checkRelationMembership(w);
    63         }
    64        
    65         public void visit(Relation r) {
    66                 checkRelationMembership(r);
    67         }
    68        
    69         private void checkRelationMembership(OsmPrimitive p) {
    70                 // FIXME - this might be a candidate for optimisation 
    71                 // if OSM primitives are made to hold a list of back
    72                 // references.
    73                 for (Relation r : ds.relations) {
    74                         if (r.incomplete || r.deleted) continue;
    75                         for (RelationMember m : r.members) {
    76                                 if (m.member == p) {
    77                                         if (!data.contains(r)) {
    78                                                 data.add(r);
    79                                                 if (indirectRefs) {
    80                                                         // move up the tree (there might be relations
    81                                                         // referring to this relation)
    82                                                         checkRelationMembership(r);
    83                                                 }
    84                                         }
    85                                         break;
    86                                 }
    87                         }
    88                 }
    89         }
     46    public void visit(Node n) {
     47        for (Way w : ds.ways) {
     48            if (w.deleted || w.incomplete) continue;
     49            for (Node n2 : w.nodes) {
     50                if (n == n2) {
     51                    data.add(w);
     52                    if (indirectRefs) {
     53                        visit(w);
     54                    }
     55                }
     56            }
     57        }
     58        checkRelationMembership(n);
     59    }
     60
     61    public void visit(Way w) {
     62        checkRelationMembership(w);
     63    }
     64
     65    public void visit(Relation r) {
     66        checkRelationMembership(r);
     67    }
     68
     69    private void checkRelationMembership(OsmPrimitive p) {
     70        // FIXME - this might be a candidate for optimisation
     71        // if OSM primitives are made to hold a list of back
     72        // references.
     73        for (Relation r : ds.relations) {
     74            if (r.incomplete || r.deleted) continue;
     75            for (RelationMember m : r.members) {
     76                if (m.member == p) {
     77                    if (!data.contains(r)) {
     78                        data.add(r);
     79                        if (indirectRefs) {
     80                            // move up the tree (there might be relations
     81                            // referring to this relation)
     82                            checkRelationMembership(r);
     83                        }
     84                    }
     85                    break;
     86                }
     87            }
     88        }
     89    }
    9090}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/CreateOsmChangeVisitor.java

    r1071 r1169  
    1616/**
    1717 * Creates an OsmChange document from JOSM edits.
    18  * See http://wiki.openstreetmap.org/index.php/OsmChange for a documentation of the 
     18 * See http://wiki.openstreetmap.org/index.php/OsmChange for a documentation of the
    1919 * OsmChange format.
    20  * 
     20 *
    2121 * @author fred
    2222 *
    … …  
    3030    StringWriter swriter;
    3131    OsmWriter osmwriter;
    32    
     32
    3333    public CreateOsmChangeVisitor(Changeset changeset) {
    3434        writer = new PrintWriter(swriter = new StringWriter());
    3535        writer.write("<osmChange version=\"");
    3636        writer.write(Main.pref.get("osm-server.version", "0.6"));
    37         writer.write("\" generator=\"JOSM\">\n"); 
     37        writer.write("\" generator=\"JOSM\">\n");
    3838        this.changeset = changeset;
    3939        osmwriter = new OsmWriter(writer, false, changeset);
    4040    }
    41    
     41
    4242    public void visit(Node n) {
    4343        if (n.deleted) {
    … …  
    5555        }
    5656    }
    57    
     57
    5858    public void visit(Way w) {
    5959        if (w.deleted) {
    … …  
    6969            switchMode((w.id == 0) ? "create" : "modify");
    7070            w.visit(osmwriter);
    71         }       
     71        }
    7272    }
    73    
     73
    7474    public void visit(Relation r) {
    7575        if (r.deleted) {
    … …  
    8585            switchMode((r.id == 0) ? "create" : "modify");
    8686            r.visit(osmwriter);
    87         }           
     87        }
    8888    }
    89    
     89
    9090    private void switchMode(String newMode) {
    9191        if ((newMode != null && !newMode.equals(currentMode))||(newMode == null && currentMode != null)) {
    … …  
    105105        }
    106106    }
    107    
     107
    108108    public String getDocument() {
    109109        switchMode(null);
    110110        return swriter.toString() + "</osmChange>\n";
    111111    }
    112    
     112
    113113    public Map<OsmPrimitive,Long> getNewIdMap() {
    114114        return osmwriter.usedNewIds;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/DeleteVisitor.java

    r655 r1169  
    99/**
    1010 * Visitor that adds the visited object to the dataset given at constructor.
    11  * 
     11 *
    1212 * Is not capable of adding keys.
    13  * 
     13 *
    1414 * @author imi
    1515 */
    1616public class DeleteVisitor implements Visitor {
    17        
    18         private final DataSet ds;
    19        
    20         public DeleteVisitor(DataSet ds) {
    21                 this.ds = ds;
    22         }
    23        
    24         public void visit(Node n) {
    25                 ds.nodes.remove(n);
    26         }
    27         public void visit(Way w) {
    28                 ds.ways.remove(w);
    29         }
    30         public void visit(Relation e) {
    31                 ds.relations.remove(e);
    32         }
     17
     18    private final DataSet ds;
     19
     20    public DeleteVisitor(DataSet ds) {
     21        this.ds = ds;
     22    }
     23
     24    public void visit(Node n) {
     25        ds.nodes.remove(n);
     26    }
     27    public void visit(Way w) {
     28        ds.ways.remove(w);
     29    }
     30    public void visit(Relation e) {
     31        ds.relations.remove(e);
     32    }
    3333}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MapPaintVisitor.java

    r1077 r1169  
    3333
    3434public class MapPaintVisitor extends SimplePaintVisitor {
    35         protected boolean useRealWidth;
    36         protected boolean zoomLevelDisplay;
    37         protected boolean fillAreas;
    38         protected int fillAlpha;
    39         protected Color untaggedColor;
    40         protected Color textColor;
    41         protected boolean currentDashed = false;
    42         protected int currentWidth = 0;
    43         protected Stroke currentStroke = null;
    44         protected Font orderFont;
    45         protected ElemStyles styles;
    46         protected double circum;
    47         protected String regionalNameOrder[];
    48 
    49         protected boolean isZoomOk(ElemStyle e) {
    50                 if (!zoomLevelDisplay) /* show everything if the user wishes so */
    51                         return true;
    52 
    53                 if(e == null) /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */
    54                         return (circum < 1500);
    55 
    56                 // formula to calculate a map scale: natural size / map size = scale
    57                 // example: 876000mm (876m as displayed) / 22mm (roughly estimated screen size of legend bar) = 39818
    58                 //
    59                 // so the exact "correcting value" below depends only on the screen size and resolution
    60                 // XXX - do we need a Preference setting for this (if things vary widely)?
    61                 return !(circum >= e.maxScale / 22 || circum < e.minScale / 22);
    62         }
    63 
    64         /**
    65         * Draw a small rectangle.
    66         * White if selected (as always) or red otherwise.
    67         *
    68         * @param n The node to draw.
    69         */
    70         public void visit(Node n) {
    71                 IconElemStyle nodeStyle = styles.get(n);
    72                 if (nodeStyle != null && isZoomOk(nodeStyle))
    73                         drawNode(n, nodeStyle.icon, nodeStyle.annotate);
    74                 else if (n.selected)
    75                         drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    76                 else if (n.tagged)
    77                         drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
    78                 else
    79                         drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
    80         }
    81 
    82         /**
    83         * Draw a line for all segments, according to tags.
    84         * @param w The way to draw.
    85         */
    86         public void visit(Way w) {
    87                 if(w.nodes.size() < 2)
    88                         return;
    89                 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key
    90                 // (even if the tag is negated as in oneway=false) or the way is selected
    91                 boolean showDirection = w.selected || ((!useRealWidth) && (showDirectionArrow
    92                 && (!showRelevantDirectionsOnly || w.hasDirectionKeys)));
    93 
    94                 Color color = untaggedColor;
    95                 int width = defaultSegmentWidth;
    96                 int realWidth = 0; //the real width of the element in meters
    97                 boolean dashed = false;
    98                 ElemStyle wayStyle = styles.get(w);
    99 
    100                 if(!isZoomOk(wayStyle))
    101                         return;
    102 
    103                 LineElemStyle l = null;
    104                 if(wayStyle!=null)
    105                 {
    106                         Color areacolor = untaggedColor;
    107                         boolean area = false;
    108                         if(wayStyle instanceof LineElemStyle)
    109                                 l = (LineElemStyle)wayStyle;
    110                         else if (wayStyle instanceof AreaElemStyle)
    111                         {
    112                                 areacolor = ((AreaElemStyle)wayStyle).color;
    113                                 color = areacolor;
    114                                 l = ((AreaElemStyle)wayStyle).line;
    115                                 area = true;
    116                         }
    117                         if(l != null)
    118                         {
    119                                 color = l.color;
    120                                 width = l.width;
    121                                 realWidth = l.realWidth;
    122                                 dashed = l.dashed;
    123                         }
    124                         if (area && fillAreas)
    125                                 drawWayAsArea(w, areacolor);
    126                 }
    127 
    128                 if (realWidth > 0 && useRealWidth && !showDirection)
    129                 {
    130                         int tmpWidth = (int) (100 /  (float) (circum / realWidth));
    131                         if (tmpWidth > width) width = tmpWidth;
    132                 }
    133                 if(w.selected)
    134                         color = selectedColor;
    135 
    136                 Node lastN;
    137                 if(l != null && l.overlays != null)
    138                 {
    139                         for(LineElemStyle s : l.overlays)
    140                         {
    141                                 if(!s.over)
    142                                 {
    143                                         lastN = null;
    144                                         for(Node n : w.nodes)
    145                                         {
    146                                                 if(lastN != null)
    147                                                 {
    148                                                         drawSeg(lastN, n, s.color != null  && !w.selected ? s.color : color,
    149                                                         false, s.getWidth(width), s.dashed);
    150                                                 }
    151                                                 lastN = n;
    152                                         }
    153                                 }
    154                         }
    155                 }
    156 
    157                 lastN = null;
    158                 for(Node n : w.nodes)
    159                 {
    160                         if(lastN != null)
    161                                 drawSeg(lastN, n, color, showDirection, width, dashed);
    162                         lastN = n;
    163                 }
    164 
    165                 if(l != null && l.overlays != null)
    166                 {
    167                         for(LineElemStyle s : l.overlays)
    168                         {
    169                                 if(s.over)
    170                                 {
    171                                         lastN = null;
    172                                         for(Node n : w.nodes)
    173                                         {
    174                                                 if(lastN != null)
    175                                                 {
    176                                                         drawSeg(lastN, n, s.color != null && !w.selected ? s.color : color,
    177                                                         false, s.getWidth(width), s.dashed);
    178                                                 }
    179                                                 lastN = n;
    180                                         }
    181                                 }
    182                         }
    183                 }
    184 
    185                 if(showOrderNumber)
    186                 {
    187                         int orderNumber = 0;
    188                         lastN = null;
    189                         for(Node n : w.nodes)
    190                         {
    191                                 if(lastN != null)
    192                                 {
    193                                         orderNumber++;
    194                                         drawOrderNumber(lastN, n, orderNumber);
    195                                 }
    196                                 lastN = n;
    197                         }
    198                 }
    199                 displaySegments();
    200         }
    201 
    202         public void visit(Relation e) {
    203                 // relations are not (yet?) drawn.
    204         }
    205 
    206         // This assumes that all segments are aligned in the same direction!
    207         protected void drawWayAsArea(Way w, Color color)
    208         {
    209                 Polygon polygon = new Polygon();
    210 
    211                 for (Node n : w.nodes)
    212                 {
    213                         Point p = nc.getPoint(n.eastNorth);
    214                         polygon.addPoint(p.x,p.y);
    215                 }
    216 
    217                 Color mycolor = w.selected ? selectedColor : color;
    218                 // set the opacity (alpha) level of the filled polygon
    219                 g.setColor(new Color( mycolor.getRed(), mycolor.getGreen(), mycolor.getBlue(), fillAlpha));
    220 
    221                 g.fillPolygon(polygon);
    222         }
    223 
    224         // NEW
    225         protected void drawNode(Node n, ImageIcon icon, boolean annotate) {
    226                 Point p = nc.getPoint(n.eastNorth);
    227                 if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
    228                 int w = icon.getIconWidth(), h=icon.getIconHeight();
    229                 icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 );
    230                 String name = getNodeName(n);
    231                 if (name!=null && annotate)
    232                 {
    233                         g.setColor(textColor);
    234                         Font defaultFont = g.getFont();
    235                         g.setFont (orderFont);
    236                         g.drawString (name, p.x+w/2+2, p.y+h/2+2);
    237                         g.setFont(defaultFont);
    238                 }
    239                 if (n.selected)
    240                 {
    241                         g.setColor (  selectedColor );
    242                         g.drawRect (p.x-w/2-2,p.y-w/2-2, w+4, h+4);
    243                 }
    244         }
    245 
    246         protected String getNodeName(Node n) {
    247                 String name = null;
    248                 if (n.keys != null) {
    249                         for (int i = 0; i < regionalNameOrder.length; i++) {
    250                                 name = n.keys.get(regionalNameOrder[i]);
    251                                 if (name != null) break;
    252                         }
    253                 }
    254                 return name;
    255         }
    256 
    257         private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, boolean dashed) {
    258                 if (col != currentColor || width != currentWidth || dashed != currentDashed) {
    259                         displaySegments(col, width, dashed);
    260                 }
    261                 Point p1 = nc.getPoint(n1.eastNorth);
    262                 Point p2 = nc.getPoint(n2.eastNorth);
    263 
    264                 if (!isSegmentVisible(p1, p2)) {
    265                         return;
    266                 }
    267                 currentPath.moveTo(p1.x, p1.y);
    268                 currentPath.lineTo(p2.x, p2.y);
    269 
    270                 if (showDirection) {
    271                         double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    272                         currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    273                         currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    274                         currentPath.lineTo(p2.x, p2.y);
    275                 }
    276         }
    277 
    278         protected void displaySegments() {
    279                 displaySegments(null, 0, false);
    280         }
    281 
    282         protected void displaySegments(Color newColor, int newWidth, boolean newDash) {
    283                 if (currentPath != null) {
    284                         Graphics2D g2d = (Graphics2D)g;
    285                         g2d.setColor(inactive ? inactiveColor : currentColor);
    286                         if (currentStroke == null) {
    287                                 if (currentDashed)
    288                                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {9},0));
    289                                 else
    290                                         g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
    291                         }
    292                         g2d.draw(currentPath);
    293                         g2d.setStroke(new BasicStroke(1));
    294 
    295                         currentPath = new GeneralPath();
    296                         currentColor = newColor;
    297                         currentWidth = newWidth;
    298                         currentDashed = newDash;
    299                         currentStroke = null;
    300                 }
    301         }
    302 
    303         /**
    304         * Draw the node as small rectangle with the given color.
    305         *
    306         * @param n  The node to draw.
    307         * @param color The color of the node.
    308         */
    309         public void drawNode(Node n, Color color, int size, int radius, boolean fill) {
    310                 if (isZoomOk(null) && size > 1) {
    311                         Point p = nc.getPoint(n.eastNorth);
    312                         if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
    313                                         || (p.y > nc.getHeight()))
    314                                 return;
    315                         g.setColor(color);
    316                         if (fill) {
    317                                 g.fillRect(p.x - radius, p.y - radius, size, size);
    318                                 g.drawRect(p.x - radius, p.y - radius, size, size);
    319                         } else
    320                                 g.drawRect(p.x - radius, p.y - radius, size, size);
    321                 }
    322         }
    323 
    324         // NW 111106 Overridden from SimplePaintVisitor in josm-1.4-nw1
    325         // Shows areas before non-areas
    326         public void visitAll(DataSet data, Boolean virtual) {
    327                 getSettings(virtual);
    328                 untaggedColor = Main.pref.getColor(marktr("untagged"),Color.GRAY);
    329                 textColor = Main.pref.getColor (marktr("text"), Color.WHITE);
    330                 useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false);
    331                 zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false);
    332                 fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);
    333                 fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
    334                 circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
    335                 styles = MapPaintStyles.getStyles();
    336                 orderFont = new Font(Main.pref.get("mappaint.font","Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8));
    337                 String currentLocale = Locale.getDefault().getLanguage();
    338                 regionalNameOrder = Main.pref.get("mappaint.nameOrder", "name:"+currentLocale+";name;int_name").split(";");
    339 
    340                 if (styles.hasAreas()) {
    341                         Collection<Way> noAreaWays = new LinkedList<Way>();
    342 
    343                         for (final OsmPrimitive osm : data.ways)
    344                                 if (!osm.incomplete && !osm.deleted && styles.isArea((Way)osm))
    345                                         osm.visit(this);
    346                                 else if (!osm.deleted && !osm.incomplete)
    347                                         noAreaWays.add((Way)osm);
    348 
    349                         for (final OsmPrimitive osm : noAreaWays)
    350                                 osm.visit(this);
    351                 }
    352                 else
    353                 {
    354                         for (final OsmPrimitive osm : data.ways)
    355                                 if (!osm.incomplete && !osm.deleted)
    356                                         osm.visit(this);
    357                 }
    358 
    359                 for (final OsmPrimitive osm : data.getSelected())
    360                         if (!osm.incomplete && !osm.deleted){
    361                                 osm.visit(this);
    362                         }
    363 
    364                 displaySegments();
    365 
    366                 for (final OsmPrimitive osm : data.nodes)
    367                         if (!osm.incomplete && !osm.deleted)
    368                                 osm.visit(this);
    369 
    370                 if (virtualNodeSize != 0)
    371                 {
    372                         currentColor = nodeColor;
    373                         for (final OsmPrimitive osm : data.ways)
    374                                 if (!osm.deleted)
    375                                         visitVirtual((Way)osm);
    376                         displaySegments(null);
    377                 }
    378         }
    379 
    380         /**
    381         * Draw a number of the order of the two consecutive nodes within the
    382         * parents way
    383         */
    384         protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {
    385                 Point p1 = nc.getPoint(n1.eastNorth);
    386                 Point p2 = nc.getPoint(n2.eastNorth);
    387                 drawOrderNumber(p1, p2, orderNumber);
    388         }
     35    protected boolean useRealWidth;
     36    protected boolean zoomLevelDisplay;
     37    protected boolean fillAreas;
     38    protected int fillAlpha;
     39    protected Color untaggedColor;
     40    protected Color textColor;
     41    protected boolean currentDashed = false;
     42    protected int currentWidth = 0;
     43    protected Stroke currentStroke = null;
     44    protected Font orderFont;
     45    protected ElemStyles styles;
     46    protected double circum;
     47    protected String regionalNameOrder[];
     48
     49    protected boolean isZoomOk(ElemStyle e) {
     50        if (!zoomLevelDisplay) /* show everything if the user wishes so */
     51            return true;
     52
     53        if(e == null) /* the default for things that don't have a rule (show, if scale is smaller than 1500m) */
     54            return (circum < 1500);
     55
     56        // formula to calculate a map scale: natural size / map size = scale
     57        // example: 876000mm (876m as displayed) / 22mm (roughly estimated screen size of legend bar) = 39818
     58        //
     59        // so the exact "correcting value" below depends only on the screen size and resolution
     60        // XXX - do we need a Preference setting for this (if things vary widely)?
     61        return !(circum >= e.maxScale / 22 || circum < e.minScale / 22);
     62    }
     63
     64    /**
     65    * Draw a small rectangle.
     66    * White if selected (as always) or red otherwise.
     67    *
     68    * @param n The node to draw.
     69    */
     70    public void visit(Node n) {
     71        IconElemStyle nodeStyle = styles.get(n);
     72        if (nodeStyle != null && isZoomOk(nodeStyle))
     73            drawNode(n, nodeStyle.icon, nodeStyle.annotate);
     74        else if (n.selected)
     75            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
     76        else if (n.tagged)
     77            drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
     78        else
     79            drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
     80    }
     81
     82    /**
     83    * Draw a line for all segments, according to tags.
     84    * @param w The way to draw.
     85    */
     86    public void visit(Way w) {
     87        if(w.nodes.size() < 2)
     88            return;
     89        // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key
     90        // (even if the tag is negated as in oneway=false) or the way is selected
     91        boolean showDirection = w.selected || ((!useRealWidth) && (showDirectionArrow
     92        && (!showRelevantDirectionsOnly || w.hasDirectionKeys)));
     93
     94        Color color = untaggedColor;
     95        int width = defaultSegmentWidth;
     96        int realWidth = 0; //the real width of the element in meters
     97        boolean dashed = false;
     98        ElemStyle wayStyle = styles.get(w);
     99
     100        if(!isZoomOk(wayStyle))
     101            return;
     102
     103        LineElemStyle l = null;
     104        if(wayStyle!=null)
     105        {
     106            Color areacolor = untaggedColor;
     107            boolean area = false;
     108            if(wayStyle instanceof LineElemStyle)
     109                l = (LineElemStyle)wayStyle;
     110            else if (wayStyle instanceof AreaElemStyle)
     111            {
     112                areacolor = ((AreaElemStyle)wayStyle).color;
     113                color = areacolor;
     114                l = ((AreaElemStyle)wayStyle).line;
     115                area = true;
     116            }
     117            if(l != null)
     118            {
     119                color = l.color;
     120                width = l.width;
     121                realWidth = l.realWidth;
     122                dashed = l.dashed;
     123            }
     124            if (area && fillAreas)
     125                drawWayAsArea(w, areacolor);
     126        }
     127
     128        if (realWidth > 0 && useRealWidth && !showDirection)
     129        {
     130            int tmpWidth = (int) (100 /  (float) (circum / realWidth));
     131            if (tmpWidth > width) width = tmpWidth;
     132        }
     133        if(w.selected)
     134            color = selectedColor;
     135
     136        Node lastN;
     137        if(l != null && l.overlays != null)
     138        {
     139            for(LineElemStyle s : l.overlays)
     140            {
     141                if(!s.over)
     142                {
     143                    lastN = null;
     144                    for(Node n : w.nodes)
     145                    {
     146                        if(lastN != null)
     147                        {
     148                            drawSeg(lastN, n, s.color != null  && !w.selected ? s.color : color,
     149                            false, s.getWidth(width), s.dashed);
     150                        }
     151                        lastN = n;
     152                    }
     153                }
     154            }
     155        }
     156
     157        lastN = null;
     158        for(Node n : w.nodes)
     159        {
     160            if(lastN != null)
     161                drawSeg(lastN, n, color, showDirection, width, dashed);
     162            lastN = n;
     163        }
     164
     165        if(l != null && l.overlays != null)
     166        {
     167            for(LineElemStyle s : l.overlays)
     168            {
     169                if(s.over)
     170                {
     171                    lastN = null;
     172                    for(Node n : w.nodes)
     173                    {
     174                        if(lastN != null)
     175                        {
     176                            drawSeg(lastN, n, s.color != null && !w.selected ? s.color : color,
     177                            false, s.getWidth(width), s.dashed);
     178                        }
     179                        lastN = n;
     180                    }
     181                }
     182            }
     183        }
     184
     185        if(showOrderNumber)
     186        {
     187            int orderNumber = 0;
     188            lastN = null;
     189            for(Node n : w.nodes)
     190            {
     191                if(lastN != null)
     192                {
     193                    orderNumber++;
     194                    drawOrderNumber(lastN, n, orderNumber);
     195                }
     196                lastN = n;
     197            }
     198        }
     199        displaySegments();
     200    }
     201
     202    public void visit(Relation e) {
     203        // relations are not (yet?) drawn.
     204    }
     205
     206    // This assumes that all segments are aligned in the same direction!
     207    protected void drawWayAsArea(Way w, Color color)
     208    {
     209        Polygon polygon = new Polygon();
     210
     211        for (Node n : w.nodes)
     212        {
     213            Point p = nc.getPoint(n.eastNorth);
     214            polygon.addPoint(p.x,p.y);
     215        }
     216
     217        Color mycolor = w.selected ? selectedColor : color;
     218        // set the opacity (alpha) level of the filled polygon
     219        g.setColor(new Color( mycolor.getRed(), mycolor.getGreen(), mycolor.getBlue(), fillAlpha));
     220
     221        g.fillPolygon(polygon);
     222    }
     223
     224    // NEW
     225    protected void drawNode(Node n, ImageIcon icon, boolean annotate) {
     226        Point p = nc.getPoint(n.eastNorth);
     227        if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth()) || (p.y > nc.getHeight())) return;
     228        int w = icon.getIconWidth(), h=icon.getIconHeight();
     229        icon.paintIcon ( Main.map.mapView, g, p.x-w/2, p.y-h/2 );
     230        String name = getNodeName(n);
     231        if (name!=null && annotate)
     232        {
     233            g.setColor(textColor);
     234            Font defaultFont = g.getFont();
     235            g.setFont (orderFont);
     236            g.drawString (name, p.x+w/2+2, p.y+h/2+2);
     237            g.setFont(defaultFont);
     238        }
     239        if (n.selected)
     240        {
     241            g.setColor (  selectedColor );
     242            g.drawRect (p.x-w/2-2,p.y-w/2-2, w+4, h+4);
     243        }
     244    }
     245
     246    protected String getNodeName(Node n) {
     247        String name = null;
     248        if (n.keys != null) {
     249            for (int i = 0; i < regionalNameOrder.length; i++) {
     250                name = n.keys.get(regionalNameOrder[i]);
     251                if (name != null) break;
     252            }
     253        }
     254        return name;
     255    }
     256
     257    private void drawSeg(Node n1, Node n2, Color col, boolean showDirection, int width, boolean dashed) {
     258        if (col != currentColor || width != currentWidth || dashed != currentDashed) {
     259            displaySegments(col, width, dashed);
     260        }
     261        Point p1 = nc.getPoint(n1.eastNorth);
     262        Point p2 = nc.getPoint(n2.eastNorth);
     263
     264        if (!isSegmentVisible(p1, p2)) {
     265            return;
     266        }
     267        currentPath.moveTo(p1.x, p1.y);
     268        currentPath.lineTo(p2.x, p2.y);
     269
     270        if (showDirection) {
     271            double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
     272            currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
     273            currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
     274            currentPath.lineTo(p2.x, p2.y);
     275        }
     276    }
     277
     278    protected void displaySegments() {
     279        displaySegments(null, 0, false);
     280    }
     281
     282    protected void displaySegments(Color newColor, int newWidth, boolean newDash) {
     283        if (currentPath != null) {
     284            Graphics2D g2d = (Graphics2D)g;
     285            g2d.setColor(inactive ? inactiveColor : currentColor);
     286            if (currentStroke == null) {
     287                if (currentDashed)
     288                    g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,0,new float[] {9},0));
     289                else
     290                    g2d.setStroke(new BasicStroke(currentWidth,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND));
     291            }
     292            g2d.draw(currentPath);
     293            g2d.setStroke(new BasicStroke(1));
     294
     295            currentPath = new GeneralPath();
     296            currentColor = newColor;
     297            currentWidth = newWidth;
     298            currentDashed = newDash;
     299            currentStroke = null;
     300        }
     301    }
     302
     303    /**
     304    * Draw the node as small rectangle with the given color.
     305    *
     306    * @param n  The node to draw.
     307    * @param color The color of the node.
     308    */
     309    public void drawNode(Node n, Color color, int size, int radius, boolean fill) {
     310        if (isZoomOk(null) && size > 1) {
     311            Point p = nc.getPoint(n.eastNorth);
     312            if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
     313                    || (p.y > nc.getHeight()))
     314                return;
     315            g.setColor(color);
     316            if (fill) {
     317                g.fillRect(p.x - radius, p.y - radius, size, size);
     318                g.drawRect(p.x - radius, p.y - radius, size, size);
     319            } else
     320                g.drawRect(p.x - radius, p.y - radius, size, size);
     321        }
     322    }
     323
     324    // NW 111106 Overridden from SimplePaintVisitor in josm-1.4-nw1
     325    // Shows areas before non-areas
     326    public void visitAll(DataSet data, Boolean virtual) {
     327        getSettings(virtual);
     328        untaggedColor = Main.pref.getColor(marktr("untagged"),Color.GRAY);
     329        textColor = Main.pref.getColor (marktr("text"), Color.WHITE);
     330        useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth",false);
     331        zoomLevelDisplay = Main.pref.getBoolean("mappaint.zoomLevelDisplay",false);
     332        fillAreas = Main.pref.getBoolean("mappaint.fillareas", true);
     333        fillAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.fillalpha", 50))));
     334        circum = Main.map.mapView.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
     335        styles = MapPaintStyles.getStyles();
     336        orderFont = new Font(Main.pref.get("mappaint.font","Helvetica"), Font.PLAIN, Main.pref.getInteger("mappaint.fontsize", 8));
     337        String currentLocale = Locale.getDefault().getLanguage();
     338        regionalNameOrder = Main.pref.get("mappaint.nameOrder", "name:"+currentLocale+";name;int_name").split(";");
     339
     340        if (styles.hasAreas()) {
     341            Collection<Way> noAreaWays = new LinkedList<Way>();
     342
     343            for (final OsmPrimitive osm : data.ways)
     344                if (!osm.incomplete && !osm.deleted && styles.isArea((Way)osm))
     345                    osm.visit(this);
     346                else if (!osm.deleted && !osm.incomplete)
     347                    noAreaWays.add((Way)osm);
     348
     349            for (final OsmPrimitive osm : noAreaWays)
     350                osm.visit(this);
     351        }
     352        else
     353        {
     354            for (final OsmPrimitive osm : data.ways)
     355                if (!osm.incomplete && !osm.deleted)
     356                    osm.visit(this);
     357        }
     358
     359        for (final OsmPrimitive osm : data.getSelected())
     360            if (!osm.incomplete && !osm.deleted){
     361                osm.visit(this);
     362            }
     363
     364        displaySegments();
     365
     366        for (final OsmPrimitive osm : data.nodes)
     367            if (!osm.incomplete && !osm.deleted)
     368                osm.visit(this);
     369
     370        if (virtualNodeSize != 0)
     371        {
     372            currentColor = nodeColor;
     373            for (final OsmPrimitive osm : data.ways)
     374                if (!osm.deleted)
     375                    visitVirtual((Way)osm);
     376            displaySegments(null);
     377        }
     378    }
     379
     380    /**
     381    * Draw a number of the order of the two consecutive nodes within the
     382    * parents way
     383    */
     384    protected void drawOrderNumber(Node n1, Node n2, int orderNumber) {
     385        Point p1 = nc.getPoint(n1.eastNorth);
     386        Point p2 = nc.getPoint(n2.eastNorth);
     387        drawOrderNumber(p1, p2, orderNumber);
     388    }
    389389}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r627 r1169  
    1919 * A visitor that get a data set at construction time and merge every visited object
    2020 * into it.
    21  * 
     21 *
    2222 * @author imi
    2323 */
    2424public class MergeVisitor implements Visitor {
    2525
    26         /**
    27         * Map from primitives in the database to visited primitives. (Attention: The other way 
    28         * round than merged)
    29         */
    30         public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>();
    31 
    32         private final DataSet ds;
    33         private final DataSet mergeds;
    34 
    35         private final HashMap<Long, Node> nodeshash = new HashMap<Long, Node>();
    36         private final HashMap<Long, Way> wayshash = new HashMap<Long, Way>();
    37         private final HashMap<Long, Relation> relshash = new HashMap<Long, Relation>();
    38 
    39         /**
    40         * A list of all primitives that got replaced with other primitives.
    41         * Key is the primitives in the other's dataset and the value is the one that is now
    42         * in ds.nodes instead.
    43         */
    44         private final Map<OsmPrimitive, OsmPrimitive> merged
    45                 = new HashMap<OsmPrimitive, OsmPrimitive>();
    46 
    47         public MergeVisitor(DataSet ds, DataSet mergeds) {
    48                 this.ds = ds;
    49                 this.mergeds = mergeds;
    50 
    51                 for (Node n : ds.nodes) if (n.id != 0) nodeshash.put(n.id, n);
    52                 for (Way w : ds.ways) if (w.id != 0) wayshash.put(w.id, w);
    53                 for (Relation r : ds.relations) if (r.id != 0) relshash.put(r.id, r);
    54         }
    55 
    56         private <P extends OsmPrimitive> void genMerge(P other,
    57                         Collection<P> myprims, Collection<P> mergeprims,
    58                         HashMap<Long, P> primhash) {
    59                 // 1. Try to find an identical prim with the same id.
    60                 if (mergeAfterId(myprims, primhash, other))
    61                         return;
    62 
    63                 // 2. Try to find a prim we can merge with the prim from the other ds.
    64                 for (P my : myprims) {
    65                         // LinkedList.contains calls equal, and OsmPrimitive.equal
    66                         // compares just the id.
    67                         if (match(my, other) && !mergeprims.contains(my)) {
    68                                 merged.put(other, my);
    69                                 mergeCommon(my, other);
    70                                 return;
    71                         }
    72                 }
    73 
    74                 // 3. No idea how to merge that.  Simply add it unchanged.
    75                 myprims.add(other);
    76         }
    77 
    78         public void visit(Node other) {
    79                 genMerge(other, ds.nodes, mergeds.nodes, nodeshash);
    80         }
    81 
    82         public void visit(Way other) {
    83                 fixWay(other);
    84                 genMerge(other, ds.ways, mergeds.ways, wayshash);
    85         }
    86 
    87         public void visit(Relation other) {
    88                 fixRelation(other);
    89                 genMerge(other, ds.relations, mergeds.relations, relshash);
    90         }
    91 
    92         /**
    93         * Postprocess the dataset and fix all merged references to point to the actual
    94         * data.
    95         */
    96         public void fixReferences() {
    97                 for (Way w : ds.ways) fixWay(w);
    98                 for (Relation r : ds.relations) fixRelation(r);
    99                 for (OsmPrimitive osm : conflicts.values())
    100                         if (osm instanceof Way)
    101                                 fixWay((Way)osm);
    102                         else if (osm instanceof Relation)
    103                                 fixRelation((Relation) osm);
    104         }
    105 
    106         private void fixWay(Way w) {
    107             boolean replacedSomething = false;
    108             LinkedList<Node> newNodes = new LinkedList<Node>();
    109             for (Node n : w.nodes) {
    110                 Node otherN = (Node) merged.get(n);
    111                 newNodes.add(otherN == null ? n : otherN);
    112                 if (otherN != null)
    113                         replacedSomething = true;
    114             }
    115             if (replacedSomething) {
    116                 w.nodes.clear();
    117                 w.nodes.addAll(newNodes);
    118                 }
    119     }
    120 
    121         private void fixRelation(Relation r) {
    122             boolean replacedSomething = false;
    123             LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>();
    124             for (RelationMember m : r.members) {
    125                 OsmPrimitive otherP = merged.get(m.member);
    126                         if (otherP == null) {
    127                                 newMembers.add(m);
    128                         } else {
    129                                 RelationMember mnew = new RelationMember(m);
    130                                 mnew.member = otherP;
    131                                 newMembers.add(mnew);
    132                         replacedSomething = true;
    133                         }
    134             }
    135             if (replacedSomething) {
    136                 r.members.clear();
    137                 r.members.addAll(newMembers);
    138                 }
    139         }
    140 
    141         private static <P extends OsmPrimitive> boolean match(P p1, P p2) {
    142                 if ((p1.id == 0 || p2.id == 0) && !p1.incomplete && !p2.incomplete) {
    143                         return realMatch(p1, p2);
    144                 }
    145                 return p1.id == p2.id;
    146         }
    147 
    148         /** @return true if the prims have pretty much the same data, i.e. the
    149         * same position, the same members, ...
    150         */
    151         // Java cannot dispatch on generics...
    152         private static boolean realMatch(OsmPrimitive p1, OsmPrimitive p2) {
    153                 if (p1 instanceof Node && p2 instanceof Node) {
    154                         return realMatch((Node) p1, (Node) p2);
    155                 } else if (p1 instanceof Way && p2 instanceof Way) {
    156                         return realMatch((Way) p1, (Way) p2);
    157                 } else if (p1 instanceof Relation && p2 instanceof Relation) {
    158                         return realMatch((Relation) p1, (Relation) p2);
    159                 } else {
    160                         throw new RuntimeException("arguments have unknown type");
    161                 }
    162         }
    163 
    164         private static boolean realMatch(Node n1, Node n2) {
    165                 return n1.coor.equalsEpsilon(n2.coor);
    166         }
    167 
    168         private static boolean realMatch(Way w1, Way w2) {
    169                 if (w1.nodes.size() != w2.nodes.size())
    170                         return false;
    171                 Iterator<Node> it = w1.nodes.iterator();
    172                 for (Node n : w2.nodes)
    173                         if (!match(n, it.next()))
    174                                 return false;
    175                 return true;
    176         }
    177 
    178         private static boolean realMatch(Relation w1, Relation w2) {
    179                 // FIXME this is not perfect yet...
    180                 if (w1.members.size() != w2.members.size())
    181                         return false;
    182                 for (RelationMember em : w1.members) {
    183                         if (!w2.members.contains(em)) {
    184                                 return false;
    185                         }
    186                 }
    187                 return true;
    188         }
    189 
    190         /**
    191         * Merge the common parts of an osm primitive.
    192         * @param my The object, the information gets merged into
    193         * @param other The object, the information gets merged from
    194         */
    195         private void mergeCommon(OsmPrimitive my, OsmPrimitive other) {
    196                 if (other.deleted)
    197                         my.delete(true);
    198                 if (my.id == 0 || !my.modified || other.modified) {
    199                         if (my.id == 0 && other.id != 0) {
    200                                 my.id = other.id;
    201                                 my.modified = other.modified; // match a new node
    202                         } else if (my.id != 0 && other.id != 0 && other.modified)
    203                                 my.modified = true;
    204                 }
    205                 if (other.keys == null)
    206                         return;
    207                 if (my.keySet().containsAll(other.keys.keySet()))
    208                         return;
    209                 if (my.keys == null)
    210                         my.keys = other.keys;
    211                 else
    212                         my.keys.putAll(other.keys);
    213                
    214                 my.modified = true;
    215         }
    216 
    217         /**
    218         * @return <code>true</code>, if no merge is needed or merge is performed already.
    219         */
    220         private <P extends OsmPrimitive> boolean mergeAfterId(
    221                         Collection<P> primitives, HashMap<Long, P> hash, P other) {
    222                 // Fast-path merging of identical objects
    223                 if (hash.containsKey(other.id)) {
    224                         P my = hash.get(other.id);
    225                         if (my.realEqual(other, true)) {
    226                                 merged.put(other, my);
    227                                 return true;
    228                         }
    229                 }
    230 
    231                 for (P my : primitives) {
    232                         if (my.realEqual(other, false)) {
    233                                 merged.put(other, my);
    234                                 return true; // no merge needed.
    235                         }
    236                         if (my.realEqual(other, true)) {
    237                                 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
    238                                 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
    239 
    240                                 // they differ in modified/timestamp combination only. Auto-resolve it.
    241                                 merged.put(other, my);
    242                                 if (myd.before(otherd)) {
    243                                         my.modified = other.modified;
    244                                         my.timestamp = other.timestamp;
    245                                 }
    246                                 return true; // merge done.
    247                         }
    248                         if (my.id == other.id && my.id != 0) {
    249                                 Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
    250                                 Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
    251 
    252                                 if (my.incomplete || other.incomplete) {
    253                                         if (my.incomplete) {
    254                                                 my.cloneFrom(other);
    255                                         }
    256                                 } else if (my.modified && other.modified) {
    257                                         conflicts.put(my, other);
    258                                 } else if (!my.modified && !other.modified) {
    259                                         if (myd.before(otherd)) {
    260                                                 my.cloneFrom(other);
    261                                         }
    262                                 } else if (other.modified) {
    263                                         if (myd.after(otherd)) {
    264                                                 conflicts.put(my, other);
    265                                         } else {
    266                                                 my.cloneFrom(other);
    267                                         }
    268                                 } else if (my.modified) {
    269                                         if (myd.before(otherd)) {
    270                                                 conflicts.put(my, other);
    271                                         }
    272                                 }
    273                                 merged.put(other, my);
    274                                 return true;
    275                         }
    276                 }
    277                 return false;
    278         }
     26    /**
     27    * Map from primitives in the database to visited primitives. (Attention: The other way
     28    * round than merged)
     29    */
     30    public Map<OsmPrimitive, OsmPrimitive> conflicts = new HashMap<OsmPrimitive, OsmPrimitive>();
     31
     32    private final DataSet ds;
     33    private final DataSet mergeds;
     34
     35    private final HashMap<Long, Node> nodeshash = new HashMap<Long, Node>();
     36    private final HashMap<Long, Way> wayshash = new HashMap<Long, Way>();
     37    private final HashMap<Long, Relation> relshash = new HashMap<Long, Relation>();
     38
     39    /**
     40    * A list of all primitives that got replaced with other primitives.
     41    * Key is the primitives in the other's dataset and the value is the one that is now
     42    * in ds.nodes instead.
     43    */
     44    private final Map<OsmPrimitive, OsmPrimitive> merged
     45        = new HashMap<OsmPrimitive, OsmPrimitive>();
     46
     47    public MergeVisitor(DataSet ds, DataSet mergeds) {
     48        this.ds = ds;
     49        this.mergeds = mergeds;
     50
     51        for (Node n : ds.nodes) if (n.id != 0) nodeshash.put(n.id, n);
     52        for (Way w : ds.ways) if (w.id != 0) wayshash.put(w.id, w);
     53        for (Relation r : ds.relations) if (r.id != 0) relshash.put(r.id, r);
     54    }
     55
     56    private <P extends OsmPrimitive> void genMerge(P other,
     57            Collection<P> myprims, Collection<P> mergeprims,
     58            HashMap<Long, P> primhash) {
     59        // 1. Try to find an identical prim with the same id.
     60        if (mergeAfterId(myprims, primhash, other))
     61            return;
     62
     63        // 2. Try to find a prim we can merge with the prim from the other ds.
     64        for (P my : myprims) {
     65            // LinkedList.contains calls equal, and OsmPrimitive.equal
     66            // compares just the id.
     67            if (match(my, other) && !mergeprims.contains(my)) {
     68                merged.put(other, my);
     69                mergeCommon(my, other);
     70                return;
     71            }
     72        }
     73
     74        // 3. No idea how to merge that.  Simply add it unchanged.
     75        myprims.add(other);
     76    }
     77
     78    public void visit(Node other) {
     79        genMerge(other, ds.nodes, mergeds.nodes, nodeshash);
     80    }
     81
     82    public void visit(Way other) {
     83        fixWay(other);
     84        genMerge(other, ds.ways, mergeds.ways, wayshash);
     85    }
     86
     87    public void visit(Relation other) {
     88        fixRelation(other);
     89        genMerge(other, ds.relations, mergeds.relations, relshash);
     90    }
     91
     92    /**
     93    * Postprocess the dataset and fix all merged references to point to the actual
     94    * data.
     95    */
     96    public void fixReferences() {
     97        for (Way w : ds.ways) fixWay(w);
     98        for (Relation r : ds.relations) fixRelation(r);
     99        for (OsmPrimitive osm : conflicts.values())
     100            if (osm instanceof Way)
     101                fixWay((Way)osm);
     102            else if (osm instanceof Relation)
     103                fixRelation((Relation) osm);
     104    }
     105
     106    private void fixWay(Way w) {
     107        boolean replacedSomething = false;
     108        LinkedList<Node> newNodes = new LinkedList<Node>();
     109        for (Node n : w.nodes) {
     110            Node otherN = (Node) merged.get(n);
     111            newNodes.add(otherN == null ? n : otherN);
     112            if (otherN != null)
     113                replacedSomething = true;
     114        }
     115        if (replacedSomething) {
     116            w.nodes.clear();
     117            w.nodes.addAll(newNodes);
     118        }
     119    }
     120
     121    private void fixRelation(Relation r) {
     122        boolean replacedSomething = false;
     123        LinkedList<RelationMember> newMembers = new LinkedList<RelationMember>();
     124        for (RelationMember m : r.members) {
     125            OsmPrimitive otherP = merged.get(m.member);
     126            if (otherP == null) {
     127                newMembers.add(m);
     128            } else {
     129                RelationMember mnew = new RelationMember(m);
     130                mnew.member = otherP;
     131                newMembers.add(mnew);
     132                replacedSomething = true;
     133            }
     134        }
     135        if (replacedSomething) {
     136            r.members.clear();
     137            r.members.addAll(newMembers);
     138        }
     139    }
     140
     141    private static <P extends OsmPrimitive> boolean match(P p1, P p2) {
     142        if ((p1.id == 0 || p2.id == 0) && !p1.incomplete && !p2.incomplete) {
     143            return realMatch(p1, p2);
     144        }
     145        return p1.id == p2.id;
     146    }
     147
     148    /** @return true if the prims have pretty much the same data, i.e. the
     149    * same position, the same members, ...
     150    */
     151    // Java cannot dispatch on generics...
     152    private static boolean realMatch(OsmPrimitive p1, OsmPrimitive p2) {
     153        if (p1 instanceof Node && p2 instanceof Node) {
     154            return realMatch((Node) p1, (Node) p2);
     155        } else if (p1 instanceof Way && p2 instanceof Way) {
     156            return realMatch((Way) p1, (Way) p2);
     157        } else if (p1 instanceof Relation && p2 instanceof Relation) {
     158            return realMatch((Relation) p1, (Relation) p2);
     159        } else {
     160            throw new RuntimeException("arguments have unknown type");
     161        }
     162    }
     163
     164    private static boolean realMatch(Node n1, Node n2) {
     165        return n1.coor.equalsEpsilon(n2.coor);
     166    }
     167
     168    private static boolean realMatch(Way w1, Way w2) {
     169        if (w1.nodes.size() != w2.nodes.size())
     170            return false;
     171        Iterator<Node> it = w1.nodes.iterator();
     172        for (Node n : w2.nodes)
     173            if (!match(n, it.next()))
     174                return false;
     175        return true;
     176    }
     177
     178    private static boolean realMatch(Relation w1, Relation w2) {
     179        // FIXME this is not perfect yet...
     180        if (w1.members.size() != w2.members.size())
     181            return false;
     182        for (RelationMember em : w1.members) {
     183            if (!w2.members.contains(em)) {
     184                return false;
     185            }
     186        }
     187        return true;
     188    }
     189
     190    /**
     191    * Merge the common parts of an osm primitive.
     192    * @param my The object, the information gets merged into
     193    * @param other The object, the information gets merged from
     194    */
     195    private void mergeCommon(OsmPrimitive my, OsmPrimitive other) {
     196        if (other.deleted)
     197            my.delete(true);
     198        if (my.id == 0 || !my.modified || other.modified) {
     199            if (my.id == 0 && other.id != 0) {
     200                my.id = other.id;
     201                my.modified = other.modified; // match a new node
     202            } else if (my.id != 0 && other.id != 0 && other.modified)
     203                my.modified = true;
     204        }
     205        if (other.keys == null)
     206            return;
     207        if (my.keySet().containsAll(other.keys.keySet()))
     208            return;
     209        if (my.keys == null)
     210            my.keys = other.keys;
     211        else
     212            my.keys.putAll(other.keys);
     213
     214        my.modified = true;
     215    }
     216
     217    /**
     218    * @return <code>true</code>, if no merge is needed or merge is performed already.
     219    */
     220    private <P extends OsmPrimitive> boolean mergeAfterId(
     221            Collection<P> primitives, HashMap<Long, P> hash, P other) {
     222        // Fast-path merging of identical objects
     223        if (hash.containsKey(other.id)) {
     224            P my = hash.get(other.id);
     225            if (my.realEqual(other, true)) {
     226                merged.put(other, my);
     227                return true;
     228            }
     229        }
     230
     231        for (P my : primitives) {
     232            if (my.realEqual(other, false)) {
     233                merged.put(other, my);
     234                return true; // no merge needed.
     235            }
     236            if (my.realEqual(other, true)) {
     237                Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
     238                Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
     239
     240                // they differ in modified/timestamp combination only. Auto-resolve it.
     241                merged.put(other, my);
     242                if (myd.before(otherd)) {
     243                    my.modified = other.modified;
     244                    my.timestamp = other.timestamp;
     245                }
     246                return true; // merge done.
     247            }
     248            if (my.id == other.id && my.id != 0) {
     249                Date myd = my.timestamp == null ? new Date(0) : my.getTimestamp();
     250                Date otherd = other.timestamp == null ? new Date(0) : other.getTimestamp();
     251
     252                if (my.incomplete || other.incomplete) {
     253                    if (my.incomplete) {
     254                        my.cloneFrom(other);
     255                    }
     256                } else if (my.modified && other.modified) {
     257                    conflicts.put(my, other);
     258                } else if (!my.modified && !other.modified) {
     259                    if (myd.before(otherd)) {
     260                        my.cloneFrom(other);
     261                    }
     262                } else if (other.modified) {
     263                    if (myd.after(otherd)) {
     264                        conflicts.put(my, other);
     265                    } else {
     266                        my.cloneFrom(other);
     267                    }
     268                } else if (my.modified) {
     269                    if (myd.before(otherd)) {
     270                        conflicts.put(my, other);
     271                    }
     272                }
     273                merged.put(other, my);
     274                return true;
     275            }
     276        }
     277        return false;
     278    }
    279279}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/NameVisitor.java

    r756 r1169  
    1717/**
    1818 * Able to create a name and an icon for each data element.
    19  * 
     19 *
    2020 * @author imi
    2121 */
    2222public class NameVisitor implements Visitor {
    2323
    24         /**
    25          * The name of the item class
    26          */
    27         public String className;
    28         public String classNamePlural;
    29         /**
    30          * The name of this item.
    31          */
    32         public String name;
    33         /**
    34          * The icon of this item.
    35          */
    36         public Icon icon;
    37        
    38         /**
    39          * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
    40          * is displayed.
    41          */
    42         public void visit(Node n) {
    43                 name = n.getName();
    44                 addId(n);
    45                 icon = ImageProvider.get("data", "node");
    46                 className = "node";
    47                 classNamePlural = trn("node", "nodes", 2);
    48         }
     24    /**
     25     * The name of the item class
     26     */
     27    public String className;
     28    public String classNamePlural;
     29    /**
     30     * The name of this item.
     31     */
     32    public String name;
     33    /**
     34     * The icon of this item.
     35     */
     36    public Icon icon;
    4937
    50         /**
    51          * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
    52          * is displayed with x being the number of nodes in the way.
    53          */
    54         public void visit(Way w) {
    55                 name = w.getName();
    56                 addId(w);
    57                 icon = ImageProvider.get("data", "way");
    58                 className = "way";
    59                 classNamePlural = trn("way", "ways", 2);
    60         }
    61        
    62         /**
    63          */
    64         public void visit(Relation e) {
    65                 name = e.getName();
    66                 addId(e);
    67                 icon = ImageProvider.get("data", "relation");
    68                 className = "relation";
    69                 classNamePlural = trn("relation", "relations", 2);
    70         }
    71        
    72         public JLabel toLabel() {
    73                 return new JLabel(name, icon, JLabel.HORIZONTAL);
    74         }
     38    /**
     39     * If the node has a name-key or id-key, this is displayed. If not, (lat,lon)
     40     * is displayed.
     41     */
     42    public void visit(Node n) {
     43        name = n.getName();
     44        addId(n);
     45        icon = ImageProvider.get("data", "node");
     46        className = "node";
     47        classNamePlural = trn("node", "nodes", 2);
     48    }
     49
     50    /**
     51     * If the way has a name-key or id-key, this is displayed. If not, (x nodes)
     52     * is displayed with x being the number of nodes in the way.
     53     */
     54    public void visit(Way w) {
     55        name = w.getName();
     56        addId(w);
     57        icon = ImageProvider.get("data", "way");
     58        className = "way";
     59        classNamePlural = trn("way", "ways", 2);
     60    }
     61
     62    /**
     63     */
     64    public void visit(Relation e) {
     65        name = e.getName();
     66        addId(e);
     67        icon = ImageProvider.get("data", "relation");
     68        className = "relation";
     69        classNamePlural = trn("relation", "relations", 2);
     70    }
     71
     72    public JLabel toLabel() {
     73        return new JLabel(name, icon, JLabel.HORIZONTAL);
     74    }
    7575
    7676
    77         private void addId(OsmPrimitive osm) {
    78             if (Main.pref.getBoolean("osm-primitives.showid"))
    79                         name += tr(" [id: {0}]", osm.id);
     77    private void addId(OsmPrimitive osm) {
     78        if (Main.pref.getBoolean("osm-primitives.showid"))
     79            name += tr(" [id: {0}]", osm.id);
    8080    }
    8181}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r999 r1169  
    3232public class SimplePaintVisitor implements Visitor {
    3333
    34         public final static Color darkerblue = new Color(0,0,96);
    35         public final static Color darkblue = new Color(0,0,128);
    36         public final static Color darkgreen = new Color(0,128,0);
    37         public final static Color teal = new Color(0,128,128);
    38 
    39         /**
    40         * The environment to paint to.
    41         */
    42         protected Graphics g;
    43         /**
    44         * MapView to get screen coordinates.
    45         */
    46         protected NavigatableComponent nc;
    47 
    48         public boolean inactive;
    49 
    50         protected static final double PHI = Math.toRadians(20);
    51 
    52         /**
    53         * Preferences
    54         */
    55         protected Color inactiveColor;
    56         protected Color selectedColor;
    57         protected Color nodeColor;
    58         protected Color dfltWayColor;
    59         protected Color relationColor;
    60         protected Color untaggedWayColor;
    61         protected Color incompleteColor;
    62         protected Color backgroundColor;
    63         protected boolean showDirectionArrow;
    64         protected boolean showRelevantDirectionsOnly;
    65         protected boolean showOrderNumber;
    66         protected boolean fillSelectedNode;
    67         protected boolean fillUnselectedNode;
    68         protected int selectedNodeRadius;
    69         protected int unselectedNodeRadius;
    70         protected int selectedNodeSize;
    71         protected int unselectedNodeSize;
    72         protected int defaultSegmentWidth;
    73         protected int virtualNodeSize;
    74         protected int virtualNodeSpace;
    75         protected int segmentNumberSpace;
    76         protected int taggedNodeRadius;
    77         protected int taggedNodeSize;
    78 
    79         /**
    80         * Draw subsequent segments of same color as one Path
    81         */
    82         protected Color currentColor = null;
    83         protected GeneralPath currentPath = new GeneralPath();
    84 
    85         Rectangle bbox = new Rectangle();
    86 
    87         protected void getSettings(Boolean virtual) {
    88                 inactiveColor = Main.pref.getColor(marktr("inactive"), Color.DARK_GRAY);
    89                 selectedColor = Main.pref.getColor(marktr("selected"), Color.WHITE);
    90                 nodeColor = Main.pref.getColor(marktr("node"), Color.RED);
    91                 dfltWayColor = Main.pref.getColor(marktr("way"), darkblue);
    92                 relationColor = Main.pref.getColor(marktr("relation"), teal);
    93                 untaggedWayColor = Main.pref.getColor(marktr("untagged way"), darkgreen);
    94                 incompleteColor = Main.pref.getColor(marktr("incomplete way"), darkerblue);
    95                 backgroundColor = Main.pref.getColor(marktr("background"), Color.BLACK);
    96                 showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
    97                 showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only");
    98                 showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
    99                 selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2;
    100                 selectedNodeSize = selectedNodeRadius * 2;
    101                 unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2;
    102                 unselectedNodeSize = unselectedNodeRadius * 2;
    103                 taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2;
    104                 taggedNodeSize = taggedNodeRadius * 2;
    105                 defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2);
    106                 fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);
    107                 fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
    108                 virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 8) / 2 : 0;
    109                 virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
    110                 segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40);
    111 
    112                 ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    113                         Main.pref.getBoolean("mappaint.use-antialiasing", false) ?
    114                         RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
    115         }
    116 
    117         public void visitAll(DataSet data, Boolean virtual) {
    118                 getSettings(virtual);
    119                 // draw tagged ways first, then untagged ways. takes
    120                 // time to iterate through list twice, OTOH does not
    121                 // require changing the colour while painting...
    122                 for (final OsmPrimitive osm : data.relations)
    123                         if (!osm.deleted && !osm.selected)
    124                                 osm.visit(this);
    125 
    126                 for (final OsmPrimitive osm : data.ways)
    127                         if (!osm.deleted && !osm.selected && osm.tagged)
    128                                 osm.visit(this);
    129                 displaySegments();
    130 
    131                 for (final OsmPrimitive osm : data.ways)
    132                         if (!osm.deleted && !osm.selected && !osm.tagged)
    133                                 osm.visit(this);
    134                 displaySegments();
    135 
    136                 for (final OsmPrimitive osm : data.getSelected())
    137                         if (!osm.deleted)
    138                                 osm.visit(this);
    139                 displaySegments();
    140 
    141                 for (final OsmPrimitive osm : data.nodes)
    142                         if (!osm.deleted && !osm.selected)
    143                                 osm.visit(this);
    144                 if(virtualNodeSize != 0)
    145                 {
    146                         currentColor = nodeColor;
    147                         for (final OsmPrimitive osm : data.ways)
    148                                 if (!osm.deleted)
    149                                         visitVirtual((Way)osm);
    150                         displaySegments();
    151                 }
    152         }
    153 
    154         /**
    155         * Draw a small rectangle.
    156         * White if selected (as always) or red otherwise.
    157         *
    158         * @param n The node to draw.
    159         */
    160         public void visit(Node n) {
    161                 if (n.incomplete) return;
    162 
    163                 if (inactive)
    164                         drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
    165                 else if (n.selected)
    166                         drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
    167                 else if(n.tagged)
    168                         drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
    169                 else
    170                         drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
    171         }
    172 
    173         public static Boolean isLargeSegment(Point p1, Point p2, int space)
    174         {
    175                 int xd = p1.x-p2.x; if(xd < 0) xd = -xd;
    176                 int yd = p1.y-p2.y; if(yd < 0) yd = -yd;
    177                 return (xd+yd > space);
    178         }
    179 
    180         public void visitVirtual(Way w) {
    181                 Iterator<Node> it = w.nodes.iterator();
    182                 if (it.hasNext()) {
    183                         Point lastP = nc.getPoint(it.next().eastNorth);
    184                         while(it.hasNext())
    185                         {
    186                                 Point p = nc.getPoint(it.next().eastNorth);
    187                                 if(isSegmentVisible(lastP, p) && isLargeSegment(lastP, p, virtualNodeSpace))
    188                                 {
    189                                         int x = (p.x+lastP.x)/2;
    190                                         int y = (p.y+lastP.y)/2;
    191                                         currentPath.moveTo(x-virtualNodeSize, y);
    192                                         currentPath.lineTo(x+virtualNodeSize, y);
    193                                         currentPath.moveTo(x, y-virtualNodeSize);
    194                                         currentPath.lineTo(x, y+virtualNodeSize);
    195                                 }
    196                                 lastP = p;
    197                         }
    198                 }
    199         }
    200 
    201         /**
    202         * Draw a darkblue line for all segments.
    203         * @param w The way to draw.
    204         */
    205         public void visit(Way w) {
    206                 if (w.incomplete || w.nodes.size() < 2)
    207                         return;
    208 
    209                 // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key
    210                 // (even if the tag is negated as in oneway=false) or the way is selected
    211 
    212                 boolean showThisDirectionArrow = w.selected
    213                 || (showDirectionArrow && (!showRelevantDirectionsOnly || w.hasDirectionKeys));
    214                 Color wayColor;
    215 
    216                 if (inactive) {
    217                         wayColor = inactiveColor;
    218                 } else if (!w.tagged) {
    219                         wayColor = untaggedWayColor;
    220                 } else {
    221                         wayColor = dfltWayColor;
    222                 }
    223 
    224                 Iterator<Node> it = w.nodes.iterator();
    225                 if (it.hasNext()) {
    226                         Point lastP = nc.getPoint(it.next().eastNorth);
    227                         for (int orderNumber = 1; it.hasNext(); orderNumber++) {
    228                                 Point p = nc.getPoint(it.next().eastNorth);
    229                                 drawSegment(lastP, p, w.selected && !inactive ? selectedColor : wayColor, showThisDirectionArrow);
    230                                 if (showOrderNumber)
    231                                         drawOrderNumber(lastP, p, orderNumber);
    232                                 lastP = p;
    233                         }
    234                 }
    235         }
    236 
    237         private Stroke relatedWayStroke = new BasicStroke(
    238                 4, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    239         public void visit(Relation r) {
    240                 if (r.incomplete) return;
    241 
    242                 Color col;
    243                 if (inactive) {
    244                         col = inactiveColor;
    245                 } else if (r.selected) {
    246                         col = selectedColor;
    247                 } else {
    248                         col = relationColor;
    249                 }
    250                 g.setColor(col);
    251 
    252                 for (RelationMember m : r.members) {
    253                         if (m.member.incomplete || m.member.deleted) continue;
    254 
    255                         if (m.member instanceof Node) {
    256                                 Point p = nc.getPoint(((Node) m.member).eastNorth);
    257                                 if (p.x < 0 || p.y < 0
    258                                         || p.x > nc.getWidth() || p.y > nc.getHeight()) continue;
    259 
    260                                 g.drawOval(p.x-3, p.y-3, 6, 6);
    261                         } else if (m.member instanceof Way) {
    262                                 GeneralPath path = new GeneralPath();
    263 
    264                                 boolean first = true;
    265                                 for (Node n : ((Way) m.member).nodes) {
    266                                         if (n.incomplete || n.deleted) continue;
    267                                         Point p = nc.getPoint(n.eastNorth);
    268                                         if (first) {
    269                                                 path.moveTo(p.x, p.y);
    270                                                 first = false;
    271                                         } else {
    272                                                 path.lineTo(p.x, p.y);
    273                                         }
    274                                 }
    275 
    276                                 ((Graphics2D) g).draw(relatedWayStroke.createStrokedShape(path));
    277                         }
    278                 }
    279         }
    280 
    281         /**
    282         * Draw an number of the order of the two consecutive nodes within the
    283         * parents way
    284         */
    285         protected void drawOrderNumber(Point p1, Point p2, int orderNumber) {
    286                 if (isSegmentVisible(p1, p2) && isLargeSegment(p1, p2, segmentNumberSpace)) {
    287                         String on = Integer.toString(orderNumber);
    288                         int strlen = on.length();
    289                         int x = (p1.x+p2.x)/2 - 4*strlen;
    290                         int y = (p1.y+p2.y)/2 + 4;
    291 
    292                         if(virtualNodeSize != 0 && isLargeSegment(p1, p2, virtualNodeSpace))
    293                         {
    294                                 y = (p1.y+p2.y)/2 - virtualNodeSize - 3;
    295                         }
    296 
    297                         displaySegments(); // draw nodes on top!
    298                         Color c = g.getColor();
    299                         g.setColor(backgroundColor);
    300                         g.fillRect(x-1, y-12, 8*strlen+1, 14);
    301                         g.setColor(c);
    302                         g.drawString(on, x, y);
    303                 }
    304         }
    305 
    306         /**
    307         * Draw the node as small rectangle with the given color.
    308         *
    309         * @param n             The node to draw.
    310         * @param color The color of the node.
    311         */
    312         public void drawNode(Node n, Color color, int size, int radius, boolean fill) {
    313                 if (size > 1) {
    314                         Point p = nc.getPoint(n.eastNorth);
    315                         if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
    316                                         || (p.y > nc.getHeight()))
    317                                 return;
    318                         g.setColor(color);
    319                         if (fill) {
    320                                 g.fillRect(p.x - radius, p.y - radius, size, size);
    321                                 g.drawRect(p.x - radius, p.y - radius, size, size);
    322                         } else
    323                                 g.drawRect(p.x - radius, p.y - radius, size, size);
    324                 }
    325         }
    326 
    327         /**
    328         * Draw a line with the given color.
    329         */
    330         protected void drawSegment(Point p1, Point p2, Color col, boolean showDirection) {
    331                 if (col != currentColor) displaySegments(col);
    332 
    333                 if (isSegmentVisible(p1, p2)) {
    334                         currentPath.moveTo(p1.x, p1.y);
    335                         currentPath.lineTo(p2.x, p2.y);
    336 
    337                         if (showDirection) {
    338                                 double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
    339                                 currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
    340                                 currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
    341                                 currentPath.lineTo(p2.x, p2.y);
    342                         }
    343                 }
    344         }
    345 
    346         protected boolean isSegmentVisible(Point p1, Point p2) {
    347                 if ((p1.x < 0) && (p2.x < 0)) return false;
    348                 if ((p1.y < 0) && (p2.y < 0)) return false;
    349                 if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
    350                 if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
    351                 return true;
    352         }
    353 
    354         public void setGraphics(Graphics g) {
    355                 this.g = g;
    356         }
    357 
    358         public void setNavigatableComponent(NavigatableComponent nc) {
    359                 this.nc = nc;
    360         }
    361 
    362         protected void displaySegments() {
    363                 displaySegments(null);
    364         }
    365         protected void displaySegments(Color newColor) {
    366                 if (currentPath != null) {
    367                         g.setColor(currentColor);
    368                         ((Graphics2D) g).draw(currentPath);
    369                         currentPath = new GeneralPath();
    370                         currentColor = newColor;
    371                 }
    372         }
     34    public final static Color darkerblue = new Color(0,0,96);
     35    public final static Color darkblue = new Color(0,0,128);
     36    public final static Color darkgreen = new Color(0,128,0);
     37    public final static Color teal = new Color(0,128,128);
     38
     39    /**
     40    * The environment to paint to.
     41    */
     42    protected Graphics g;
     43    /**
     44    * MapView to get screen coordinates.
     45    */
     46    protected NavigatableComponent nc;
     47
     48    public boolean inactive;
     49
     50    protected static final double PHI = Math.toRadians(20);
     51
     52    /**
     53    * Preferences
     54    */
     55    protected Color inactiveColor;
     56    protected Color selectedColor;
     57    protected Color nodeColor;
     58    protected Color dfltWayColor;
     59    protected Color relationColor;
     60    protected Color untaggedWayColor;
     61    protected Color incompleteColor;
     62    protected Color backgroundColor;
     63    protected boolean showDirectionArrow;
     64    protected boolean showRelevantDirectionsOnly;
     65    protected boolean showOrderNumber;
     66    protected boolean fillSelectedNode;
     67    protected boolean fillUnselectedNode;
     68    protected int selectedNodeRadius;
     69    protected int unselectedNodeRadius;
     70    protected int selectedNodeSize;
     71    protected int unselectedNodeSize;
     72    protected int defaultSegmentWidth;
     73    protected int virtualNodeSize;
     74    protected int virtualNodeSpace;
     75    protected int segmentNumberSpace;
     76    protected int taggedNodeRadius;
     77    protected int taggedNodeSize;
     78
     79    /**
     80    * Draw subsequent segments of same color as one Path
     81    */
     82    protected Color currentColor = null;
     83    protected GeneralPath currentPath = new GeneralPath();
     84
     85    Rectangle bbox = new Rectangle();
     86
     87    protected void getSettings(Boolean virtual) {
     88        inactiveColor = Main.pref.getColor(marktr("inactive"), Color.DARK_GRAY);
     89        selectedColor = Main.pref.getColor(marktr("selected"), Color.WHITE);
     90        nodeColor = Main.pref.getColor(marktr("node"), Color.RED);
     91        dfltWayColor = Main.pref.getColor(marktr("way"), darkblue);
     92        relationColor = Main.pref.getColor(marktr("relation"), teal);
     93        untaggedWayColor = Main.pref.getColor(marktr("untagged way"), darkgreen);
     94        incompleteColor = Main.pref.getColor(marktr("incomplete way"), darkerblue);
     95        backgroundColor = Main.pref.getColor(marktr("background"), Color.BLACK);
     96        showDirectionArrow = Main.pref.getBoolean("draw.segment.direction");
     97        showRelevantDirectionsOnly = Main.pref.getBoolean("draw.segment.relevant_directions_only");
     98        showOrderNumber = Main.pref.getBoolean("draw.segment.order_number");
     99        selectedNodeRadius = Main.pref.getInteger("mappaint.node.selected-size", 5) / 2;
     100        selectedNodeSize = selectedNodeRadius * 2;
     101        unselectedNodeRadius = Main.pref.getInteger("mappaint.node.unselected-size", 3) / 2;
     102        unselectedNodeSize = unselectedNodeRadius * 2;
     103        taggedNodeRadius = Main.pref.getInteger("mappaint.node.tagged-size", 5) / 2;
     104        taggedNodeSize = taggedNodeRadius * 2;
     105        defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2);
     106        fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);
     107        fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
     108        virtualNodeSize = virtual ? Main.pref.getInteger("mappaint.node.virtual-size", 8) / 2 : 0;
     109        virtualNodeSpace = Main.pref.getInteger("mappaint.node.virtual-space", 70);
     110        segmentNumberSpace = Main.pref.getInteger("mappaint.segmentnumber.space", 40);
     111
     112        ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
     113            Main.pref.getBoolean("mappaint.use-antialiasing", false) ?
     114            RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
     115    }
     116
     117    public void visitAll(DataSet data, Boolean virtual) {
     118        getSettings(virtual);
     119        // draw tagged ways first, then untagged ways. takes
     120        // time to iterate through list twice, OTOH does not
     121        // require changing the colour while painting...
     122        for (final OsmPrimitive osm : data.relations)
     123            if (!osm.deleted && !osm.selected)
     124                osm.visit(this);
     125
     126        for (final OsmPrimitive osm : data.ways)
     127            if (!osm.deleted && !osm.selected && osm.tagged)
     128                osm.visit(this);
     129        displaySegments();
     130
     131        for (final OsmPrimitive osm : data.ways)
     132            if (!osm.deleted && !osm.selected && !osm.tagged)
     133                osm.visit(this);
     134        displaySegments();
     135
     136        for (final OsmPrimitive osm : data.getSelected())
     137            if (!osm.deleted)
     138                osm.visit(this);
     139        displaySegments();
     140
     141        for (final OsmPrimitive osm : data.nodes)
     142            if (!osm.deleted && !osm.selected)
     143                osm.visit(this);
     144        if(virtualNodeSize != 0)
     145        {
     146            currentColor = nodeColor;
     147            for (final OsmPrimitive osm : data.ways)
     148                if (!osm.deleted)
     149                    visitVirtual((Way)osm);
     150            displaySegments();
     151        }
     152    }
     153
     154    /**
     155    * Draw a small rectangle.
     156    * White if selected (as always) or red otherwise.
     157    *
     158    * @param n The node to draw.
     159    */
     160    public void visit(Node n) {
     161        if (n.incomplete) return;
     162
     163        if (inactive)
     164            drawNode(n, inactiveColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
     165        else if (n.selected)
     166            drawNode(n, selectedColor, selectedNodeSize, selectedNodeRadius, fillSelectedNode);
     167        else if(n.tagged)
     168            drawNode(n, nodeColor, taggedNodeSize, taggedNodeRadius, fillUnselectedNode);
     169        else
     170            drawNode(n, nodeColor, unselectedNodeSize, unselectedNodeRadius, fillUnselectedNode);
     171    }
     172
     173    public static Boolean isLargeSegment(Point p1, Point p2, int space)
     174    {
     175        int xd = p1.x-p2.x; if(xd < 0) xd = -xd;
     176        int yd = p1.y-p2.y; if(yd < 0) yd = -yd;
     177        return (xd+yd > space);
     178    }
     179
     180    public void visitVirtual(Way w) {
     181        Iterator<Node> it = w.nodes.iterator();
     182        if (it.hasNext()) {
     183            Point lastP = nc.getPoint(it.next().eastNorth);
     184            while(it.hasNext())
     185            {
     186                Point p = nc.getPoint(it.next().eastNorth);
     187                if(isSegmentVisible(lastP, p) && isLargeSegment(lastP, p, virtualNodeSpace))
     188                {
     189                    int x = (p.x+lastP.x)/2;
     190                    int y = (p.y+lastP.y)/2;
     191                    currentPath.moveTo(x-virtualNodeSize, y);
     192                    currentPath.lineTo(x+virtualNodeSize, y);
     193                    currentPath.moveTo(x, y-virtualNodeSize);
     194                    currentPath.lineTo(x, y+virtualNodeSize);
     195                }
     196                lastP = p;
     197            }
     198        }
     199    }
     200
     201    /**
     202    * Draw a darkblue line for all segments.
     203    * @param w The way to draw.
     204    */
     205    public void visit(Way w) {
     206        if (w.incomplete || w.nodes.size() < 2)
     207            return;
     208
     209        // show direction arrows, if draw.segment.relevant_directions_only is not set, the way is tagged with a direction key
     210        // (even if the tag is negated as in oneway=false) or the way is selected
     211
     212        boolean showThisDirectionArrow = w.selected
     213        || (showDirectionArrow && (!showRelevantDirectionsOnly || w.hasDirectionKeys));
     214        Color wayColor;
     215
     216        if (inactive) {
     217            wayColor = inactiveColor;
     218        } else if (!w.tagged) {
     219            wayColor = untaggedWayColor;
     220        } else {
     221            wayColor = dfltWayColor;
     222        }
     223
     224        Iterator<Node> it = w.nodes.iterator();
     225        if (it.hasNext()) {
     226            Point lastP = nc.getPoint(it.next().eastNorth);
     227            for (int orderNumber = 1; it.hasNext(); orderNumber++) {
     228                Point p = nc.getPoint(it.next().eastNorth);
     229                drawSegment(lastP, p, w.selected && !inactive ? selectedColor : wayColor, showThisDirectionArrow);
     230                if (showOrderNumber)
     231                    drawOrderNumber(lastP, p, orderNumber);
     232                lastP = p;
     233            }
     234        }
     235    }
     236
     237    private Stroke relatedWayStroke = new BasicStroke(
     238        4, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
     239    public void visit(Relation r) {
     240        if (r.incomplete) return;
     241
     242        Color col;
     243        if (inactive) {
     244            col = inactiveColor;
     245        } else if (r.selected) {
     246            col = selectedColor;
     247        } else {
     248            col = relationColor;
     249        }
     250        g.setColor(col);
     251
     252        for (RelationMember m : r.members) {
     253            if (m.member.incomplete || m.member.deleted) continue;
     254
     255            if (m.member instanceof Node) {
     256                Point p = nc.getPoint(((Node) m.member).eastNorth);
     257                if (p.x < 0 || p.y < 0
     258                    || p.x > nc.getWidth() || p.y > nc.getHeight()) continue;
     259
     260                g.drawOval(p.x-3, p.y-3, 6, 6);
     261            } else if (m.member instanceof Way) {
     262                GeneralPath path = new GeneralPath();
     263
     264                boolean first = true;
     265                for (Node n : ((Way) m.member).nodes) {
     266                    if (n.incomplete || n.deleted) continue;
     267                    Point p = nc.getPoint(n.eastNorth);
     268                    if (first) {
     269                        path.moveTo(p.x, p.y);
     270                        first = false;
     271                    } else {
     272                        path.lineTo(p.x, p.y);
     273                    }
     274                }
     275
     276                ((Graphics2D) g).draw(relatedWayStroke.createStrokedShape(path));
     277            }
     278        }
     279    }
     280
     281    /**
     282    * Draw an number of the order of the two consecutive nodes within the
     283    * parents way
     284    */
     285    protected void drawOrderNumber(Point p1, Point p2, int orderNumber) {
     286        if (isSegmentVisible(p1, p2) && isLargeSegment(p1, p2, segmentNumberSpace)) {
     287            String on = Integer.toString(orderNumber);
     288            int strlen = on.length();
     289            int x = (p1.x+p2.x)/2 - 4*strlen;
     290            int y = (p1.y+p2.y)/2 + 4;
     291
     292            if(virtualNodeSize != 0 && isLargeSegment(p1, p2, virtualNodeSpace))
     293            {
     294                y = (p1.y+p2.y)/2 - virtualNodeSize - 3;
     295            }
     296
     297            displaySegments(); // draw nodes on top!
     298            Color c = g.getColor();
     299            g.setColor(backgroundColor);
     300            g.fillRect(x-1, y-12, 8*strlen+1, 14);
     301            g.setColor(c);
     302            g.drawString(on, x, y);
     303        }
     304    }
     305
     306    /**
     307    * Draw the node as small rectangle with the given color.
     308    *
     309    * @param n     The node to draw.
     310    * @param color The color of the node.
     311    */
     312    public void drawNode(Node n, Color color, int size, int radius, boolean fill) {
     313        if (size > 1) {
     314            Point p = nc.getPoint(n.eastNorth);
     315            if ((p.x < 0) || (p.y < 0) || (p.x > nc.getWidth())
     316                    || (p.y > nc.getHeight()))
     317                return;
     318            g.setColor(color);
     319            if (fill) {
     320                g.fillRect(p.x - radius, p.y - radius, size, size);
     321                g.drawRect(p.x - radius, p.y - radius, size, size);
     322            } else
     323                g.drawRect(p.x - radius, p.y - radius, size, size);
     324        }
     325    }
     326
     327    /**
     328    * Draw a line with the given color.
     329    */
     330    protected void drawSegment(Point p1, Point p2, Color col, boolean showDirection) {
     331        if (col != currentColor) displaySegments(col);
     332
     333        if (isSegmentVisible(p1, p2)) {
     334            currentPath.moveTo(p1.x, p1.y);
     335            currentPath.lineTo(p2.x, p2.y);
     336
     337            if (showDirection) {
     338                double t = Math.atan2(p2.y-p1.y, p2.x-p1.x) + Math.PI;
     339                currentPath.lineTo((int)(p2.x + 10*Math.cos(t-PHI)), (int)(p2.y + 10*Math.sin(t-PHI)));
     340                currentPath.moveTo((int)(p2.x + 10*Math.cos(t+PHI)), (int)(p2.y + 10*Math.sin(t+PHI)));
     341                currentPath.lineTo(p2.x, p2.y);
     342            }
     343        }
     344    }
     345
     346    protected boolean isSegmentVisible(Point p1, Point p2) {
     347        if ((p1.x < 0) && (p2.x < 0)) return false;
     348        if ((p1.y < 0) && (p2.y < 0)) return false;
     349        if ((p1.x > nc.getWidth()) && (p2.x > nc.getWidth())) return false;
     350        if ((p1.y > nc.getHeight()) && (p2.y > nc.getHeight())) return false;
     351        return true;
     352    }
     353
     354    public void setGraphics(Graphics g) {
     355        this.g = g;
     356    }
     357
     358    public void setNavigatableComponent(NavigatableComponent nc) {
     359        this.nc = nc;
     360    }
     361
     362    protected void displaySegments() {
     363        displaySegments(null);
     364    }
     365    protected void displaySegments(Color newColor) {
     366        if (currentPath != null) {
     367            g.setColor(currentColor);
     368            ((Graphics2D) g).draw(currentPath);
     369            currentPath = new GeneralPath();
     370            currentColor = newColor;
     371        }
     372    }
    373373}
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/Visitor.java

    r627 r1169  
    99 * Implementation of the visitor scheme. Every OsmPrimitive can be visited by
    1010 * several different visitors.
    11  * 
     11 *
    1212 * @author imi
    1313 */
    1414public interface Visitor {
    15         void visit(Node n);
    16         void visit(Way w);
    17         void visit(Relation e);
     15    void visit(Node n);
     16    void visit(Way w);
     17    void visit(Relation e);
    1818}
Note: See TracChangeset for help on using the changeset viewer.