source: josm/trunk/src/org/openstreetmap/josm/gui/layer/MapViewPaintable.java@ 17318

Last change on this file since 17318 was 16553, checked in by Don-vip, 4 years ago

see #19334 - javadoc fixes + protected constructors for abstract classes

  • Property svn:eol-style set to native
File size: 5.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer;
3
4import java.awt.Graphics2D;
5
6import org.openstreetmap.josm.data.Bounds;
7import org.openstreetmap.josm.gui.MapView;
8
9/**
10 * This is a component that can be painted on the map view.
11 * <p>
12 * You might want to extend {@link AbstractMapViewPaintable} to ease implementation of this.
13 * <p>
14 * That class allows you to listen to paintable change events. Those methods may be moved here some time in the future.
15 * @since 608 (creation)
16 * @since 10600 (functional interface)
17 */
18@FunctionalInterface
19public interface MapViewPaintable {
20
21 /**
22 * This event is fired whenever the paintable got invalidated and needs repainting some time in the future.
23 * <p>
24 * Note: We might add an area in the future.
25 *
26 * @author Michael Zangl
27 */
28 class PaintableInvalidationEvent {
29 private final MapViewPaintable paintable;
30
31 /**
32 * Creates a new {@link PaintableInvalidationEvent}
33 * @param paintable The paintable that is invalidated.
34 */
35 public PaintableInvalidationEvent(MapViewPaintable paintable) {
36 this.paintable = paintable;
37 }
38
39 /**
40 * Gets the layer that was invalidated.
41 * @return The layer.
42 */
43 public MapViewPaintable getLayer() {
44 return paintable;
45 }
46
47 @Override
48 public String toString() {
49 return "LayerInvalidationEvent [layer=" + paintable + ']';
50 }
51 }
52
53 /**
54 * This is a listener that listens to {@link PaintableInvalidationEvent}s
55 * @author Michael Zangl
56 * @since 10600 (functional interface)
57 */
58 @FunctionalInterface
59 interface PaintableInvalidationListener {
60 /**
61 * Called whenever a {@link PaintableInvalidationEvent} is fired. This might be called from any thread.
62 * @param event The event
63 * @since 10600 (renamed)
64 */
65 void paintableInvalidated(PaintableInvalidationEvent event);
66 }
67
68 /**
69 * Gets a new LayerPainter that paints this {@link MapViewPaintable} to the given map view.
70 *
71 * @author Michael Zangl
72 * @since 10458
73 */
74 interface LayerPainter {
75
76 /**
77 * Paints the given layer.
78 * <p>
79 * This can be called in any thread at any time. You will not receive parallel calls for the same map view but you can receive parallel
80 * calls if you use the same {@link LayerPainter} for different map views.
81 * @param graphics The graphics object of the map view you should use.
82 * It provides you with a content pane, the bounds and the view state.
83 */
84 void paint(MapViewGraphics graphics);
85
86 /**
87 * Called when the layer is removed from the map view and this painter is not used any more.
88 * <p>
89 * This method is called once on the painter returned by {@link Layer#attachToMapView}
90 * @param event The event.
91 */
92 void detachFromMapView(MapViewEvent event);
93 }
94
95 /**
96 * A event that is fired whenever the map view is attached or detached from any layer.
97 * @author Michael Zangl
98 * @see Layer#attachToMapView
99 * @since 10458
100 */
101 class MapViewEvent {
102 private final MapView mapView;
103 private final boolean temporaryLayer;
104
105 /**
106 * Create a new {@link MapViewEvent}
107 * @param mapView The map view
108 * @param temporaryLayer <code>true</code> if this layer is in the temporary layer list of the view.
109 */
110 public MapViewEvent(MapView mapView, boolean temporaryLayer) {
111 super();
112 this.mapView = mapView;
113 this.temporaryLayer = temporaryLayer;
114 }
115
116 /**
117 * Gets the map view.
118 * @return The map view.
119 */
120 public MapView getMapView() {
121 return mapView;
122 }
123
124 /**
125 * Determines if this {@link MapViewPaintable} is used as a temporary layer
126 * @return true if this {@code MapViewPaintable} is used as a temporary layer.
127 */
128 public boolean isTemporaryLayer() {
129 return temporaryLayer;
130 }
131
132 @Override
133 public String toString() {
134 return "AttachToMapViewEvent [mapView=" + mapView + ", temporaryLayer=" + temporaryLayer + "]";
135 }
136 }
137
138 /**
139 * Paint the dataset using the engine set.
140 * @param g Graphics
141 * @param mv The object that can translate GeoPoints to screen coordinates.
142 * @param bbox Bounding box
143 */
144 void paint(Graphics2D g, MapView mv, Bounds bbox);
145
146 /**
147 * Adds a new paintable invalidation listener.
148 * @param l The listener to add.
149 * @since 12107
150 */
151 default void addInvalidationListener(PaintableInvalidationListener l) {
152 }
153
154 /**
155 * Removes an added paintable invalidation listener. May throw an exception if the listener is added twice.
156 * @param l The listener to remove.
157 * @since 12107
158 */
159 default void removeInvalidationListener(PaintableInvalidationListener l) {
160 }
161
162}
Note: See TracBrowser for help on using the repository browser.