Ignore:
Timestamp:
2017-04-28T14:36:21+02:00 (7 years ago)
Author:
michael2402
Message:

See #14120: Use a listener to get notified of way segment / virtual node highlight changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r11712 r12014  
    5050import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    5151import org.openstreetmap.josm.tools.JosmRuntimeException;
     52import org.openstreetmap.josm.tools.ListenerList;
    5253import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    5354import org.openstreetmap.josm.tools.Utils;
     
    156157    private Collection<WaySegment> highlightedVirtualNodes = new LinkedList<>();
    157158    private Collection<WaySegment> highlightedWaySegments = new LinkedList<>();
     159    private final ListenerList<HighlightUpdateListener> highlightUpdateListeners = ListenerList.create();
    158160
    159161    // Number of open calls to beginUpdate
     
    161163    // Events that occurred while dataset was locked but should be fired after write lock is released
    162164    private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<>();
    163 
    164     private int highlightUpdateCount;
    165165
    166166    private UploadPolicy uploadPolicy;
     
    267267    public Lock getReadLock() {
    268268        return lock.readLock();
    269     }
    270 
    271     /**
    272      * This method can be used to detect changes in highlight state of primitives. If highlighting was changed
    273      * then the method will return different number.
    274      * @return the current highlight counter
    275      */
    276     public int getHighlightUpdateCount() {
    277         return highlightUpdateCount;
    278269    }
    279270
     
    726717    public Collection<WaySegment> getHighlightedWaySegments() {
    727718        return Collections.unmodifiableCollection(highlightedWaySegments);
     719    }
     720
     721    /**
     722     * Adds a listener that gets notified whenever way segment / virtual nodes highlights change.
     723     * @param listener The Listener
     724     * @since 12014
     725     */
     726    public void addHighlightUpdateListener(HighlightUpdateListener listener) {
     727        highlightUpdateListeners.addListener(listener);
     728    }
     729
     730    /**
     731     * Removes a listener that was added with {@link #addHighlightUpdateListener(HighlightUpdateListener)}
     732     * @param listener The Listener
     733     * @since 12014
     734     */
     735    public void removeHighlightUpdateListener(HighlightUpdateListener listener) {
     736        highlightUpdateListeners.removeListener(listener);
    728737    }
    729738
     
    13351344
    13361345    void fireHighlightingChanged() {
    1337         highlightUpdateCount++;
     1346        HighlightUpdateListener.HighlightUpdateEvent e = new HighlightUpdateListener.HighlightUpdateEvent(this);
     1347        highlightUpdateListeners.fireEvent(l -> l.highlightUpdated(e));
    13381348    }
    13391349
Note: See TracChangeset for help on using the changeset viewer.