Changeset 12014 in josm


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.

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
3 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
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractMapViewPaintable.java

    r10600 r12014  
    8888    /**
    8989     * This needs to be called whenever the content of this view was invalidated.
     90     * It triggers a repaint of the components that display this layer.
    9091     */
    9192    public void invalidate() {
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r11893 r12014  
    6666import org.openstreetmap.josm.data.osm.DataSetMerger;
    6767import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
     68import org.openstreetmap.josm.data.osm.HighlightUpdateListener;
    6869import org.openstreetmap.josm.data.osm.IPrimitive;
    6970import org.openstreetmap.josm.data.osm.Node;
     
    117118 * @since 17
    118119 */
    119 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener {
     120public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener, HighlightUpdateListener {
    120121    private static final int HATCHED_SIZE = 15;
    121122    /** Property used to know if this layer has to be saved on disk */
     
    126127    private boolean requiresSaveToFile;
    127128    private boolean requiresUploadToServer;
    128     private int highlightUpdateCount;
    129129
    130130    /**
     
    364364        data.addDataSetListener(new DataSetListenerAdapter(this));
    365365        data.addDataSetListener(MultipolygonCache.getInstance());
     366        data.addHighlightUpdateListener(this);
    366367        DataSet.addSelectionListener(this);
    367368        if (name != null && name.startsWith(createLayerName("")) && Character.isDigit(
     
    400401     */
    401402    @Override public void paint(final Graphics2D g, final MapView mv, Bounds box) {
    402         highlightUpdateCount = data.getHighlightUpdateCount();
    403 
    404403        boolean active = mv.getLayerManager().getActiveLayer() == this;
    405404        boolean inactive = !active && Main.pref.getBoolean("draw.data.inactive_color", true);
     
    908907
    909908    @Override
    910     public boolean isChanged() {
    911         return highlightUpdateCount != data.getHighlightUpdateCount();
    912     }
    913 
    914     @Override
    915909    public void onPostSaveToFile() {
    916910        setRequiresSaveToFile(false);
     
    952946        super.destroy();
    953947        DataSet.removeSelectionListener(this);
     948        data.removeHighlightUpdateListener(this);
    954949    }
    955950
     
    11021097        return v.getBounds();
    11031098    }
     1099
     1100    @Override
     1101    public void highlightUpdated(HighlightUpdateEvent e) {
     1102        invalidate();
     1103    }
    11041104}
Note: See TracChangeset for help on using the changeset viewer.