1 | package org.openstreetmap.josm.data.projection;
|
---|
2 |
|
---|
3 | import java.util.LinkedList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import javax.swing.JComponent;
|
---|
7 | import javax.swing.event.ChangeEvent;
|
---|
8 | import javax.swing.event.ChangeListener;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.GeoPoint;
|
---|
11 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Classes subclass this are able to convert lat/lon values to
|
---|
15 | * planear screen coordinates.
|
---|
16 | *
|
---|
17 | * @author imi
|
---|
18 | */
|
---|
19 | abstract public class Projection implements Cloneable {
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * The event list with all state chaned listener
|
---|
23 | */
|
---|
24 | List<ChangeListener> listener = new LinkedList<ChangeListener>();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Convert from lat/lon to northing/easting.
|
---|
28 | *
|
---|
29 | * @param p The geo point to convert. x/y members of the point are filled.
|
---|
30 | */
|
---|
31 | abstract public void latlon2xy(GeoPoint p);
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Convert from norting/easting to lat/lon.
|
---|
35 | *
|
---|
36 | * @param p The geo point to convert. lat/lon members of the point are filled.
|
---|
37 | */
|
---|
38 | abstract public void xy2latlon(GeoPoint p);
|
---|
39 |
|
---|
40 |
|
---|
41 | // description functions
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Describe the projection converter in one or two words.
|
---|
45 | */
|
---|
46 | @Override
|
---|
47 | abstract public String toString();
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Describe the projection converter. Give examples, where it is best to use
|
---|
51 | * and maybe a reference link to more information about the converter.
|
---|
52 | */
|
---|
53 | abstract public String description();
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | // miscellous functions
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * If the projection supports any configuration, this function return
|
---|
61 | * the configuration panel. If no configuration needed, return null.
|
---|
62 | *
|
---|
63 | * The items on the configuration panel should update the configuration
|
---|
64 | * directly, so the changes are instantly visible on screen.
|
---|
65 | */
|
---|
66 | abstract public JComponent getConfigurationPanel();
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Initialize itself with the given dataSet.
|
---|
70 | *
|
---|
71 | * This function should initialize own parameters needed to do the
|
---|
72 | * projection at best effort.
|
---|
73 | *
|
---|
74 | * Init must not fire an state changed event, since it is usually called
|
---|
75 | * during the initialization of the mapFrame.
|
---|
76 | *
|
---|
77 | * This implementation does nothing. It is provided only for subclasses
|
---|
78 | * to initialize their data members.
|
---|
79 | *
|
---|
80 | * @param dataSet
|
---|
81 | * The dataset, which will be displayed on screen. Later, all
|
---|
82 | * projections should be relative to the given dataset. Any
|
---|
83 | * reverse projections (xy2latlon) can be assumed to be in near
|
---|
84 | * distance to nodes of this dataset (that means, it is ok, if
|
---|
85 | * there is a conversion error, if the requested x/y to xy2latlon
|
---|
86 | * is far away from any coordinate in the dataset)
|
---|
87 | */
|
---|
88 | public void init(DataSet dataSet) {}
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Add an event listener to the state changed event queue. If passed
|
---|
92 | * <code>null</code>, nothing happens.
|
---|
93 | */
|
---|
94 | public final void addChangeListener(ChangeListener l) {
|
---|
95 | if (l != null)
|
---|
96 | listener.add(l);
|
---|
97 | }
|
---|
98 | /**
|
---|
99 | * Remove an event listener from the event queue. If passed
|
---|
100 | * <code>null</code>, nothing happens.
|
---|
101 | */
|
---|
102 | public final void removeChangeListener(ChangeListener l) {
|
---|
103 | listener.remove(l);
|
---|
104 | }
|
---|
105 | /**
|
---|
106 | * Fire an ChangeEvent to every listener on the queue.
|
---|
107 | */
|
---|
108 | public final void fireStateChanged() {
|
---|
109 | ChangeEvent e = null;
|
---|
110 | for(ChangeListener l : listener) {
|
---|
111 | if (e == null)
|
---|
112 | e = new ChangeEvent(this);
|
---|
113 | l.stateChanged(e);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|