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.Bounds;
|
---|
11 | import org.openstreetmap.josm.data.GeoPoint;
|
---|
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 | // miscellous functions
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * If the projection supports any configuration, this function return
|
---|
53 | * the configuration panel. If no configuration needed,
|
---|
54 | * return <code>null</code>.
|
---|
55 | *
|
---|
56 | * The items on the configuration panel should not update the configuration
|
---|
57 | * directly, but remember changed settings so a call to commitConfigurationPanel
|
---|
58 | * can set them.
|
---|
59 | *
|
---|
60 | * This function also rolls back all changes to the configuration panel interna
|
---|
61 | * components.
|
---|
62 | */
|
---|
63 | abstract public JComponent getConfigurationPanel();
|
---|
64 | /**
|
---|
65 | * Commits any changes from components created by addToConfigurationPanel.
|
---|
66 | * The projection should now obtain the new settings. If any setting has
|
---|
67 | * changed, the implementation have to call to fireStateChanged to inform
|
---|
68 | * the listeners.
|
---|
69 | */
|
---|
70 | abstract public void commitConfigurationPanel();
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Initialize itself with the given bounding rectangle (regarding lat/lon).
|
---|
74 | *
|
---|
75 | * This function should initialize own parameters needed to do the
|
---|
76 | * projection at best effort.
|
---|
77 | *
|
---|
78 | * Init must not fire an state changed event, since it is usually called
|
---|
79 | * during the initialization of the mapFrame.
|
---|
80 | *
|
---|
81 | * This implementation does nothing. It is provided only for subclasses
|
---|
82 | * to initialize their data members.
|
---|
83 | */
|
---|
84 | public void init(Bounds b) {}
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Add an event listener to the state changed event queue. If passed
|
---|
88 | * <code>null</code>, nothing happens.
|
---|
89 | */
|
---|
90 | public final void addChangeListener(ChangeListener l) {
|
---|
91 | if (l != null)
|
---|
92 | listener.add(l);
|
---|
93 | }
|
---|
94 | /**
|
---|
95 | * Remove an event listener from the event queue. If passed
|
---|
96 | * <code>null</code>, nothing happens.
|
---|
97 | */
|
---|
98 | public final void removeChangeListener(ChangeListener l) {
|
---|
99 | listener.remove(l);
|
---|
100 | }
|
---|
101 | /**
|
---|
102 | * Fire an ChangeEvent to every listener on the queue.
|
---|
103 | */
|
---|
104 | public final void fireStateChanged() {
|
---|
105 | ChangeEvent e = null;
|
---|
106 | for(ChangeListener l : listener) {
|
---|
107 | if (e == null)
|
---|
108 | e = new ChangeEvent(this);
|
---|
109 | l.stateChanged(e);
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|