Changeset 10809 in josm


Ignore:
Timestamp:
2016-08-15T17:40:22+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13175 - Use invalidation event instead of isChanged() (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r10788 r10809  
    752752
    753753        highlightedVirtualNodes = waySegments;
    754         // can't use fireHighlightingChanged because it requires an OsmPrimitive
    755         highlightUpdateCount++;
     754        fireHighlightingChanged();
    756755    }
    757756
     
    765764
    766765        highlightedWaySegments = waySegments;
    767         // can't use fireHighlightingChanged because it requires an OsmPrimitive
    768         highlightUpdateCount++;
     766        fireHighlightingChanged();
    769767    }
    770768
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r10806 r10809  
    2626import java.util.Collections;
    2727import java.util.HashMap;
     28import java.util.IdentityHashMap;
    2829import java.util.LinkedHashSet;
    2930import java.util.List;
     
    148149    private class LayerInvalidatedListener implements PaintableInvalidationListener {
    149150        private boolean ignoreRepaint;
     151
     152        private final Set<MapViewPaintable> invalidatedLayers = Collections.newSetFromMap(new IdentityHashMap<MapViewPaintable, Boolean>());
     153
    150154        @Override
    151155        public void paintableInvalidated(PaintableInvalidationEvent event) {
     156            invalidate(event.getLayer());
     157        }
     158
     159        public synchronized void invalidate(MapViewPaintable mapViewPaintable) {
    152160            ignoreRepaint = true;
     161            invalidatedLayers.add(mapViewPaintable);
    153162            repaint();
    154163        }
     
    158167         * @param p The paintable.
    159168         */
    160         public void addTo(MapViewPaintable p) {
     169        public synchronized void addTo(MapViewPaintable p) {
    161170            if (p instanceof AbstractMapViewPaintable) {
    162171                ((AbstractMapViewPaintable) p).addInvalidationListener(this);
     
    168177         * @param p The paintable.
    169178         */
    170         public void removeFrom(MapViewPaintable p) {
     179        public synchronized void removeFrom(MapViewPaintable p) {
    171180            if (p instanceof AbstractMapViewPaintable) {
    172181                ((AbstractMapViewPaintable) p).removeInvalidationListener(this);
    173182            }
     183            invalidatedLayers.remove(p);
    174184        }
    175185
     
    183193            }
    184194            ignoreRepaint = false;
     195        }
     196
     197        /**
     198         * Retrieves a set of all layers that have been marked as invalid since the last call to this method.
     199         * @return The layers
     200         */
     201        protected synchronized Set<MapViewPaintable> collectInvalidatedLayers() {
     202            Set<MapViewPaintable> layers = Collections.newSetFromMap(new IdentityHashMap<MapViewPaintable, Boolean>());
     203            layers.addAll(invalidatedLayers);
     204            invalidatedLayers.clear();
     205            return layers;
    185206        }
    186207    }
     
    504525    // Layers that wasn't changed since last paint
    505526    private final transient List<Layer> nonChangedLayers = new ArrayList<>();
    506     private transient Layer changedLayer;
    507527    private int lastViewID;
    508528    private boolean paintPreferencesChanged = true;
     
    842862
    843863        int nonChangedLayersCount = 0;
     864        Set<MapViewPaintable> invalidated = invalidatedListener.collectInvalidatedLayers();
    844865        for (Layer l: visibleLayers) {
    845             if (l.isChanged() || l == changedLayer) {
     866            if (l.isChanged() || invalidated.contains(l)) {
    846867                break;
    847868            } else {
     
    900921
    901922        nonChangedLayers.clear();
    902         changedLayer = null;
    903923        for (int i = 0; i < nonChangedLayersCount; i++) {
    904924            nonChangedLayers.add(visibleLayers.get(i));
     
    12051225            Layer l = (Layer) evt.getSource();
    12061226            if (l.isVisible()) {
    1207                 changedLayer = l;
    1208                 repaint();
     1227                invalidatedListener.invalidate(l);
    12091228            }
    12101229        }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java

    r10805 r10809  
    5151import javax.swing.JSeparator;
    5252import javax.swing.JTextField;
     53import javax.swing.Timer;
    5354
    5455import org.openstreetmap.gui.jmapviewer.AttributionSupport;
     
    137138     */
    138139    public int currentZoomLevel;
    139     private boolean needRedraw;
    140140
    141141    private final AttributionSupport attribution = new AttributionSupport();
     
    158158    protected T tileSource;
    159159    protected TileLoader tileLoader;
     160
     161    /**
     162     * A timer that is used to delay invalidation events if required.
     163     */
     164    private final Timer invalidateLaterTimer = new Timer(100, e -> this.invalidate());
    160165
    161166    private final MouseAdapter adapter = new MouseAdapter() {
     
    264269        }
    265270        tile.setLoaded(success);
    266         needRedraw = true;
    267         if (Main.map != null) {
    268             Main.map.repaint(100);
    269         }
     271        invalidateLater();
    270272        if (Main.isDebugEnabled()) {
    271273            Main.debug("tileLoadingFinished() tile: " + tile + " success: " + success);
     
    297299     */
    298300    protected void redraw() {
    299         needRedraw = true;
    300         if (isVisible()) Main.map.repaint();
    301     }
    302 
    303     @Override
    304     public void invalidate() {
    305         needRedraw = true;
    306         super.invalidate();
     301        invalidate();
    307302    }
    308303
     
    10301025    public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
    10311026        boolean done = (infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0;
    1032         needRedraw = true;
    10331027        if (Main.isDebugEnabled()) {
    10341028            Main.debug("imageUpdate() done: " + done + " calling repaint");
    10351029        }
    1036         Main.map.repaint(done ? 0 : 100);
     1030
     1031        if (done) {
     1032            invalidate();
     1033        } else {
     1034            invalidateLater();
     1035        }
    10371036        return !done;
     1037    }
     1038
     1039    /**
     1040     * Invalidate the layer at a time in the future so taht the user still sees the interface responsive.
     1041     */
     1042    private void invalidateLater() {
     1043        GuiHelper.runInEDT(() -> {
     1044            if (!invalidateLaterTimer.isRunning()) {
     1045                invalidateLaterTimer.setRepeats(false);
     1046                invalidateLaterTimer.start();
     1047            }
     1048        });
    10381049    }
    10391050
     
    17531764    @Override
    17541765    public boolean isChanged() {
    1755         return needRedraw;
     1766        // we use #invalidate()
     1767        return false;
    17561768    }
    17571769
     
    18991911            ProjectionBounds pb = graphics.getClipBounds().getProjectionBounds();
    19001912
    1901             needRedraw = false; // TEMPORARY
    1902 
    19031913            drawInViewArea(graphics.getDefaultGraphics(), graphics.getMapView(), pb);
    19041914        }
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r10611 r10809  
    426426     *
    427427     * @return True if layer was changed since last paint
    428      */
     428     * @deprecated This is not supported by multiple map views.
     429     * Fire an {@link #invalidate()} to trigger a repaint.
     430     * Let this method return false if you only use invalidation events.
     431     */
     432    @Deprecated
    429433    public boolean isChanged() {
    430434        return true;
Note: See TracChangeset for help on using the changeset viewer.