1 | // License: GPL. See LICENSE file for details.
|
---|
2 |
|
---|
3 | package org.openstreetmap.josm.gui.layer;
|
---|
4 |
|
---|
5 | import java.awt.Component;
|
---|
6 | import java.awt.Graphics;
|
---|
7 | import java.io.File;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.concurrent.CopyOnWriteArrayList;
|
---|
10 |
|
---|
11 | import javax.swing.Icon;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
|
---|
14 | import org.openstreetmap.josm.gui.MapView;
|
---|
15 | import org.openstreetmap.josm.tools.Destroyable;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * A layer encapsulates the gui component of one dataset and its representation.
|
---|
19 | *
|
---|
20 | * Some layers may display data directly imported from OSM server. Other only
|
---|
21 | * display background images. Some can be edited, some not. Some are static and
|
---|
22 | * other changes dynamically (auto-updated).
|
---|
23 | *
|
---|
24 | * Layers can be visible or not. Most actions the user can do applies only on
|
---|
25 | * selected layers. The available actions depend on the selected layers too.
|
---|
26 | *
|
---|
27 | * All layers are managed by the MapView. They are displayed in a list to the
|
---|
28 | * right of the screen.
|
---|
29 | *
|
---|
30 | * @author imi
|
---|
31 | */
|
---|
32 | abstract public class Layer implements Destroyable, MapViewPaintable {
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Interface to notify listeners of the change of the active layer.
|
---|
36 | * @author imi
|
---|
37 | */
|
---|
38 | public interface LayerChangeListener {
|
---|
39 | void activeLayerChange(Layer oldLayer, Layer newLayer);
|
---|
40 | void layerAdded(Layer newLayer);
|
---|
41 | void layerRemoved(Layer oldLayer);
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * The listener of the active layer changes. You may register/deregister yourself
|
---|
46 | * while an LayerChangeListener - action is executed.
|
---|
47 | */
|
---|
48 | public static final Collection<LayerChangeListener> listeners = new CopyOnWriteArrayList<LayerChangeListener>();
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * The visibility state of the layer.
|
---|
52 | */
|
---|
53 | public boolean visible = true;
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * The layer should be handled as a background layer in automatic handling
|
---|
57 | */
|
---|
58 | public boolean background = false;
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * The name of this layer.
|
---|
62 | */
|
---|
63 | public String name;
|
---|
64 | /**
|
---|
65 | * If a file is associated with this layer, this variable should be set to it.
|
---|
66 | */
|
---|
67 | private File associatedFile;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Create the layer and fill in the necessary components.
|
---|
71 | */
|
---|
72 | public Layer(String name) {
|
---|
73 | this.name = name;
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Paint the dataset using the engine set.
|
---|
78 | * @param mv The object that can translate GeoPoints to screen coordinates.
|
---|
79 | */
|
---|
80 | abstract public void paint(Graphics g, MapView mv);
|
---|
81 | /**
|
---|
82 | * Return a representative small image for this layer. The image must not
|
---|
83 | * be larger than 64 pixel in any dimension.
|
---|
84 | */
|
---|
85 | abstract public Icon getIcon();
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * @return A small tooltip hint about some statistics for this layer.
|
---|
89 | */
|
---|
90 | abstract public String getToolTipText();
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Merges the given layer into this layer. Throws if the layer types are
|
---|
94 | * incompatible.
|
---|
95 | * @param from The layer that get merged into this one. After the merge,
|
---|
96 | * the other layer is not usable anymore and passing to one others
|
---|
97 | * mergeFrom should be one of the last things to do with a layer.
|
---|
98 | */
|
---|
99 | abstract public void mergeFrom(Layer from);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * @param other The other layer that is tested to be mergable with this.
|
---|
103 | * @return Whether the other layer can be merged into this layer.
|
---|
104 | */
|
---|
105 | abstract public boolean isMergable(Layer other);
|
---|
106 |
|
---|
107 | abstract public void visitBoundingBox(BoundingXYVisitor v);
|
---|
108 |
|
---|
109 | abstract public Object getInfoComponent();
|
---|
110 |
|
---|
111 | abstract public Component[] getMenuEntries();
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Called, when the layer is removed from the mapview and is going to be
|
---|
115 | * destroyed.
|
---|
116 | *
|
---|
117 | * This is because the Layer constructor can not add itself safely as listener
|
---|
118 | * to the layerlist dialog, because there may be no such dialog yet (loaded
|
---|
119 | * via command line parameter).
|
---|
120 | */
|
---|
121 | public void destroy() {}
|
---|
122 |
|
---|
123 | public File getAssociatedFile() { return associatedFile; }
|
---|
124 | public void setAssociatedFile(File file) { associatedFile = file; }
|
---|
125 | }
|
---|