001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.layer;
003
004import java.awt.Graphics2D;
005
006import org.openstreetmap.josm.data.Bounds;
007import org.openstreetmap.josm.gui.MapView;
008
009/**
010 * This is a component that can be painted on the map view.
011 * <p>
012 * You might want to extend {@link AbstractMapViewPaintable} to ease implementation of this.
013 * <p>
014 * That class allows you to listen to paintable change events. Those methods may be moved here some time in the future.
015 */
016public interface MapViewPaintable {
017
018    /**
019     * This event is fired whenever the paintable got invalidated and needs repainting some time in the future.
020     * <p>
021     * Note: We might add an area in the future.
022     *
023     * @author Michael Zangl
024     */
025    class PaintableInvalidationEvent {
026        private final MapViewPaintable paintable;
027
028        /**
029         * Creates a new {@link PaintableInvalidationEvent}
030         * @param paintable The paintable that is invalidated.
031         */
032        public PaintableInvalidationEvent(MapViewPaintable paintable) {
033            this.paintable = paintable;
034        }
035
036        /**
037         * Gets the layer that was invalidated.
038         * @return The layer.
039         */
040        public MapViewPaintable getLayer() {
041            return paintable;
042        }
043
044        @Override
045        public String toString() {
046            return "LayerInvalidationEvent [layer=" + paintable + ']';
047        }
048    }
049
050    /**
051     * This is a listener that listens to {@link PaintableInvalidationEvent}s
052     * @author Michael Zangl
053     */
054    interface PaintableInvalidationListener {
055        /**
056         * Called whenever a {@link PaintableInvalidationEvent} is fired. This might be called from any thread.
057         * @param event The event
058         */
059        void paintablInvalidated(PaintableInvalidationEvent event);
060    }
061
062    /**
063     * Paint the dataset using the engine set.
064     * @param g Graphics
065     * @param mv The object that can translate GeoPoints to screen coordinates.
066     * @param bbox Bounding box
067     */
068    void paint(Graphics2D g, MapView mv, Bounds bbox);
069}