001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.layer;
003
004import java.awt.Graphics2D;
005
006import org.openstreetmap.josm.gui.MapView;
007import org.openstreetmap.josm.gui.MapViewState.MapViewRectangle;
008
009/**
010 * This class provides layers with access to drawing on the map view.
011 * <p>
012 * It contains information about the state of the map view.
013 * <p>
014 * In the future, it may add support for parallel drawing or layer caching.
015 * <p>
016 * It is intended to be used during {@link MapView#paint(java.awt.Graphics)}
017 * @author Michael Zangl
018 * @since 10458
019 */
020public class MapViewGraphics {
021
022    private final Graphics2D graphics;
023    private final MapView mapView;
024    private final MapViewRectangle clipBounds;
025
026    /**
027     * Constructs a new {@code MapViewGraphics}.
028     * @param mapView map view
029     * @param graphics default graphics
030     * @param clipBounds clip bounds for this graphics instance
031     */
032    public MapViewGraphics(MapView mapView, Graphics2D graphics, MapViewRectangle clipBounds) {
033        this.mapView = mapView;
034        this.graphics = graphics;
035        this.clipBounds = clipBounds;
036    }
037
038    /**
039     * Gets the {@link Graphics2D} you should use to paint on this graphics object. It may already have some data painted on it.
040     * You should paint your layer data on this graphics.
041     * @return The {@link Graphics2D} instance.
042     */
043    public Graphics2D getDefaultGraphics() {
044        return graphics;
045    }
046
047    /**
048     * Gets the {@link MapView} that is the base to this draw call.
049     * @return The map view.
050     */
051    public MapView getMapView() {
052        return mapView;
053    }
054
055    /**
056     * Gets the clip bounds for this graphics instance.
057     * @return The clip bounds.
058     */
059    public MapViewRectangle getClipBounds() {
060        return clipBounds;
061    }
062}