1 | package org.openstreetmap.josm.gui.layer;
|
---|
2 |
|
---|
3 | import java.awt.Graphics;
|
---|
4 |
|
---|
5 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
6 | import org.openstreetmap.josm.data.osm.LineSegment;
|
---|
7 | import org.openstreetmap.josm.data.osm.Node;
|
---|
8 | import org.openstreetmap.josm.data.osm.Track;
|
---|
9 | import org.openstreetmap.josm.gui.MapView;
|
---|
10 | import org.openstreetmap.josm.gui.engine.Engine;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Base class for all layer that depends on some DataSet.
|
---|
14 | * The dataset is final and so can not be changed later.
|
---|
15 | *
|
---|
16 | * @author imi
|
---|
17 | */
|
---|
18 | public abstract class DataLayer implements Layer {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * The dataSet this layer operates on.
|
---|
22 | */
|
---|
23 | protected final DataSet dataSet;
|
---|
24 | /**
|
---|
25 | * The engine used to draw the data.
|
---|
26 | */
|
---|
27 | protected final Engine engine;
|
---|
28 | /**
|
---|
29 | * The name of this layer.
|
---|
30 | */
|
---|
31 | private final String name;
|
---|
32 | /**
|
---|
33 | * The visibility state of the layer.
|
---|
34 | */
|
---|
35 | private boolean visible = true;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Construct the datalayer and fill the dataset.
|
---|
39 | * @param name The name of this layer. Returned by getName.
|
---|
40 | */
|
---|
41 | public DataLayer(DataSet dataSet, Engine engine, String name) {
|
---|
42 | if (dataSet == null || engine == null || name == null)
|
---|
43 | throw new NullPointerException();
|
---|
44 | this.name = name;
|
---|
45 | this.dataSet = dataSet;
|
---|
46 | this.engine = engine;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Paint the dataset using the engine set.
|
---|
51 | * @param mv The object that can translate GeoPoints to screen coordinates.
|
---|
52 | */
|
---|
53 | public void paint(Graphics g, MapView mv) {
|
---|
54 | engine.init(g, mv);
|
---|
55 |
|
---|
56 | for (Track t : dataSet.tracks())
|
---|
57 | engine.drawTrack(t);
|
---|
58 | for (LineSegment ls : dataSet.pendingLineSegments())
|
---|
59 | engine.drawPendingLineSegment(ls);
|
---|
60 | for (Node n : dataSet.nodes)
|
---|
61 | engine.drawNode(n);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Return the data set behind this data layer.
|
---|
66 | */
|
---|
67 | public DataSet getDataSet() {
|
---|
68 | return dataSet;
|
---|
69 | }
|
---|
70 |
|
---|
71 | public String getName() {
|
---|
72 | return name;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public boolean isVisible() {
|
---|
76 | return visible;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void setVisible(boolean visible) {
|
---|
80 | this.visible = visible;
|
---|
81 | }
|
---|
82 | }
|
---|