1 | // License: GPL. For details, see Readme.txt file.
|
---|
2 | package org.openstreetmap.gui.jmapviewer;
|
---|
3 |
|
---|
4 | import java.awt.geom.Point2D;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.io.ObjectInputStream;
|
---|
7 | import java.io.ObjectOutputStream;
|
---|
8 | import java.util.Objects;
|
---|
9 |
|
---|
10 | import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * This class encapsulates a Point2D.Double and provide access
|
---|
14 | * via <tt>lat</tt> and <tt>lon</tt>.
|
---|
15 | *
|
---|
16 | * @author Jan Peter Stotz
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public class Coordinate implements ICoordinate {
|
---|
20 | private transient Point2D.Double data;
|
---|
21 |
|
---|
22 | public Coordinate(double lat, double lon) {
|
---|
23 | data = new Point2D.Double(lon, lat);
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public double getLat() {
|
---|
28 | return data.y;
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Override
|
---|
32 | public void setLat(double lat) {
|
---|
33 | data.y = lat;
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public double getLon() {
|
---|
38 | return data.x;
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void setLon(double lon) {
|
---|
43 | data.x = lon;
|
---|
44 | }
|
---|
45 |
|
---|
46 | private void writeObject(ObjectOutputStream out) throws IOException {
|
---|
47 | out.writeObject(data.x);
|
---|
48 | out.writeObject(data.y);
|
---|
49 | }
|
---|
50 |
|
---|
51 | private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
---|
52 | data = new Point2D.Double();
|
---|
53 | data.x = (Double) in.readObject();
|
---|
54 | data.y = (Double) in.readObject();
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public String toString() {
|
---|
59 | return "Coordinate[" + data.y + ", " + data.x + ']';
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public int hashCode() {
|
---|
64 | int hash = 3;
|
---|
65 | hash = 61 * hash + Objects.hashCode(this.data);
|
---|
66 | return hash;
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public boolean equals(Object obj) {
|
---|
71 | if (obj == null) {
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 | if (getClass() != obj.getClass()) {
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 | final Coordinate other = (Coordinate) obj;
|
---|
78 | return Objects.equals(this.data, other.data);
|
---|
79 | }
|
---|
80 | }
|
---|