001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.layer; 003 004import java.util.concurrent.CopyOnWriteArrayList; 005 006/** 007 * This class implements the invalidation listener mechanism suggested by {@link MapViewPaintable}. 008 * 009 * @author Michael Zangl 010 * @since 10031 011 */ 012public abstract class AbstractMapViewPaintable implements MapViewPaintable { 013 014 /** 015 * A list of invalidation listeners to call when this layer is invalidated. 016 */ 017 private final CopyOnWriteArrayList<PaintableInvalidationListener> invalidationListeners = new CopyOnWriteArrayList<>(); 018 019 /** 020 * Adds a new paintable invalidation listener. 021 * @param l The listener to add. 022 */ 023 public void addInvalidationListener(PaintableInvalidationListener l) { 024 invalidationListeners.add(l); 025 } 026 027 /** 028 * Removes an added paintable invalidation listener. 029 * @param l The listener to remove. 030 */ 031 public void removeInvalidationListener(PaintableInvalidationListener l) { 032 invalidationListeners.remove(l); 033 } 034 035 /** 036 * This needs to be called whenever the content of this view was invalidated. 037 */ 038 public void invalidate() { 039 for (PaintableInvalidationListener l : invalidationListeners) { 040 l.paintablInvalidated(new PaintableInvalidationEvent(this)); 041 } 042 } 043}