source: josm/trunk/src/org/openstreetmap/josm/gui/layer/Layer.java@ 608

Last change on this file since 608 was 608, checked in by framm, 16 years ago
  • new extrude mode allows creation of rectangular shapes
  • new AlignInRectangle function
  • additional information in status bar about length, heading, and angle of segment being drawn
  • helper line from last node to mouse cursor (disable with edit.helper-line=false)
File size: 3.6 KB
Line 
1// License: GPL. See LICENSE file for details.
2
3package org.openstreetmap.josm.gui.layer;
4
5import java.awt.Component;
6import java.awt.Graphics;
7import java.io.File;
8import java.util.Collection;
9import java.util.concurrent.CopyOnWriteArrayList;
10
11import javax.swing.Icon;
12
13import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
14import org.openstreetmap.josm.gui.MapView;
15import org.openstreetmap.josm.tools.Destroyable;
16
17/**
18 * A layer encapsulates the gui componente of one dataset and its representation.
19 *
20 * Some layers may display data directly importet 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 */
32abstract 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 * The name of this layer.
56 */
57 public String name;
58 /**
59 * If a file is associated with this layer, this variable should be set to it.
60 */
61 public File associatedFile;
62
63 /**
64 * Create the layer and fill in the necessary components.
65 */
66 public Layer(String name) {
67 this.name = name;
68 }
69
70 /**
71 * Paint the dataset using the engine set.
72 * @param mv The object that can translate GeoPoints to screen coordinates.
73 */
74 abstract public void paint(Graphics g, MapView mv);
75 /**
76 * Return a representative small image for this layer. The image must not
77 * be larger than 64 pixel in any dimension.
78 */
79 abstract public Icon getIcon();
80
81 /**
82 * @return A small tooltip hint about some statistics for this layer.
83 */
84 abstract public String getToolTipText();
85
86 /**
87 * Merges the given layer into this layer. Throws if the layer types are
88 * incompatible.
89 * @param from The layer that get merged into this one. After the merge,
90 * the other layer is not usable anymore and passing to one others
91 * mergeFrom should be one of the last things to do with a layer.
92 */
93 abstract public void mergeFrom(Layer from);
94
95 /**
96 * @param other The other layer that is tested to be mergable with this.
97 * @return Whether the other layer can be merged into this layer.
98 */
99 abstract public boolean isMergable(Layer other);
100
101 /**
102 * @return The bounding rectangle this layer occupies on screen when looking
103 * at x/y values or <code>null</code>, if infinite area or unknown
104 * area is occupied.
105 */
106 abstract public void visitBoundingBox(BoundingXYVisitor v);
107
108 abstract public Object getInfoComponent();
109
110 abstract public Component[] getMenuEntries();
111
112 /**
113 * Called, when the layer is removed from the mapview and is going to be
114 * destroyed.
115 *
116 * This is because the Layer constructor can not add itself safely as listener
117 * to the layerlist dialog, because there may be no such dialog yet (loaded
118 * via command line parameter).
119 */
120 public void destroy() {}
121}
Note: See TracBrowser for help on using the repository browser.