1 | package org.openstreetmap.josm.gui.engine;
|
---|
2 |
|
---|
3 | import java.awt.Graphics;
|
---|
4 | import java.beans.PropertyChangeEvent;
|
---|
5 | import java.beans.PropertyChangeListener;
|
---|
6 |
|
---|
7 | import org.openstreetmap.josm.data.GeoPoint;
|
---|
8 | import org.openstreetmap.josm.data.osm.LineSegment;
|
---|
9 | import org.openstreetmap.josm.data.osm.Node;
|
---|
10 | import org.openstreetmap.josm.data.osm.Track;
|
---|
11 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
12 | import org.openstreetmap.josm.gui.MapView;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Subclasses of Engine are able to draw map data on the screen. The layout and
|
---|
16 | * colors depend only on the engine used, but it may have an configuration panel.
|
---|
17 | *
|
---|
18 | * @author imi
|
---|
19 | */
|
---|
20 | abstract public class Engine implements PropertyChangeListener {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The projection method, this engine uses to render the graphics.
|
---|
24 | */
|
---|
25 | protected Projection projection;
|
---|
26 | /**
|
---|
27 | * The Graphics surface to draw on. This should be set before each painting
|
---|
28 | * sequence.
|
---|
29 | */
|
---|
30 | protected Graphics g;
|
---|
31 | /**
|
---|
32 | * The mapView, this engine was created for.
|
---|
33 | */
|
---|
34 | protected final MapView mv;
|
---|
35 |
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Creates an Engine from an MapView it belongs to.
|
---|
39 | * @param mapView The mapview this engine belongs to.
|
---|
40 | */
|
---|
41 | public Engine(MapView mapView) {
|
---|
42 | mv = mapView;
|
---|
43 | mv.addPropertyChangeListener(this);
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Called to initialize the Engine for a new drawing sequence.
|
---|
48 | * @param g
|
---|
49 | */
|
---|
50 | public void init(Graphics g) {
|
---|
51 | this.g = g;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Draw the background. The coordinates are given as hint (e.g. to draw
|
---|
56 | * an background image).
|
---|
57 | */
|
---|
58 | abstract public void drawBackground(GeoPoint ul, GeoPoint lr);
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Draw the node.
|
---|
62 | */
|
---|
63 | abstract public void drawNode(Node n);
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Draw the track.
|
---|
67 | */
|
---|
68 | abstract public void drawTrack(Track t);
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Draw the pending line segment. Non-pending line segments must be drawn
|
---|
72 | * within drawTrack.
|
---|
73 | */
|
---|
74 | abstract public void drawPendingLineSegment(LineSegment ls);
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Called when the projection method for the map changed. Subclasses with
|
---|
78 | * caches depending on the projection should empty the cache now.
|
---|
79 | */
|
---|
80 | public void propertyChange(PropertyChangeEvent e) {
|
---|
81 | if (e.getPropertyName().equals("projection"))
|
---|
82 | projection = (Projection)e.getNewValue();
|
---|
83 | }
|
---|
84 | }
|
---|