source: josm/trunk/src/org/openstreetmap/josm/data/osm/Node.java@ 1990

Last change on this file since 1990 was 1990, checked in by Gubaer, 15 years ago

fixed #3261: Use the "name:$CURRENT_LOCALE" name in the JOSM UI instead of "name" when it exists
new: new checkbox in LAF preferences for enabling/disabling localized names for primitives

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.osm;
3
4import java.util.Locale;
5
6import org.openstreetmap.josm.data.coor.CachedLatLon;
7import org.openstreetmap.josm.data.coor.EastNorth;
8import org.openstreetmap.josm.data.coor.LatLon;
9import org.openstreetmap.josm.data.osm.visitor.Visitor;
10import static org.openstreetmap.josm.tools.I18n.tr;
11
12/**
13 * One node data, consisting of one world coordinate waypoint.
14 *
15 * @author imi
16 */
17public final class Node extends OsmPrimitive {
18
19 private CachedLatLon coor;
20
21 public final void setCoor(LatLon coor) {
22 if(coor != null)
23 {
24 if(this.coor == null) {
25 this.coor = new CachedLatLon(coor);
26 } else {
27 this.coor.setCoor(coor);
28 }
29 }
30 }
31
32 public final LatLon getCoor() {
33 return coor;
34 }
35
36 public final void setEastNorth(EastNorth eastNorth) {
37 if(eastNorth != null)
38 {
39 if(coor != null) {
40 coor.setEastNorth(eastNorth);
41 } else {
42 coor = new CachedLatLon(eastNorth);
43 }
44 }
45 }
46
47 public final EastNorth getEastNorth() {
48 return coor != null ? coor.getEastNorth() : null;
49 }
50
51
52
53 /**
54 * Create an incomplete Node object
55 */
56 public Node(long id) {
57 this.id = id;
58 incomplete = true;
59 }
60
61 /**
62 * Create an identical clone of the argument (including the id)
63 */
64 public Node(Node clone) {
65 cloneFrom(clone);
66 }
67
68 public Node(LatLon latlon) {
69 setCoor(latlon);
70 }
71
72 public Node(EastNorth eastNorth) {
73 setEastNorth(eastNorth);
74 }
75
76 @Override public void visit(Visitor visitor) {
77 visitor.visit(this);
78 }
79
80 @Override public void cloneFrom(OsmPrimitive osm) {
81 super.cloneFrom(osm);
82 setCoor(((Node)osm).coor);
83 }
84
85 @Override public String toString() {
86 if (coor == null) return "{Node id="+id+"}";
87 return "{Node id="+id+",version="+version+",lat="+coor.lat()+",lon="+coor.lon()+"}";
88 }
89
90 @Override
91 public boolean hasEqualSemanticAttributes(OsmPrimitive other) {
92 if (other == null || ! (other instanceof Node) )
93 return false;
94 if (! super.hasEqualSemanticAttributes(other))
95 return false;
96 Node n = (Node)other;
97 if (coor == null && n.coor == null)
98 return true;
99 else if (coor != null && n.coor != null)
100 return coor.equals(n.coor);
101 else
102 return false;
103 }
104
105 public int compareTo(OsmPrimitive o) {
106 return o instanceof Node ? Long.valueOf(id).compareTo(o.id) : 1;
107 }
108
109 @Override
110 public String getDisplayName(NameFormatter formatter) {
111 return formatter.format(this);
112 }
113
114 @Override
115 public String getName() {
116 String name = super.getName();
117 if (name != null)
118 return name;
119 // no translation
120 return "node " + id;
121 }
122
123 @Override
124 public String getLocalName(){
125 String name = super.getLocalName();
126 if (name != null)
127 return name;
128 return tr("node {0}",id);
129 }
130}
Note: See TracBrowser for help on using the repository browser.