Changeset 8552 in josm for trunk/src


Ignore:
Timestamp:
2015-07-01T21:11:45+02:00 (9 years ago)
Author:
bastiK
Message:

applied #11632 - Synchronized access to temporary layers and added a getter. (based on patch by michael2402)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r8551 r8552  
    2626import java.util.Collections;
    2727import java.util.Comparator;
    28 import java.util.LinkedList;
     28import java.util.LinkedHashSet;
    2929import java.util.List;
    30 import java.util.ListIterator;
     30import java.util.Set;
    3131import java.util.concurrent.CopyOnWriteArrayList;
    3232import java.util.concurrent.locks.ReentrantReadWriteLock;
     
    3535import javax.swing.ActionMap;
    3636import javax.swing.InputMap;
     37import javax.swing.JComponent;
    3738import javax.swing.JFrame;
    3839import javax.swing.JPanel;
     
    268269    public MouseEvent lastMEvent = new MouseEvent(this, 0, 0, 0, 0, 0, 0, false); // In case somebody reads it before first mouse move
    269270
    270     private final transient List<MapViewPaintable> temporaryLayers = new LinkedList<>();
     271    /**
     272     * Temporary layers (selection rectangle, etc.) that are never cached and
     273     * drawn on top of regular layers.
     274     * Access must be synchronized.
     275     */
     276    private final transient Set<MapViewPaintable> temporaryLayers = new LinkedHashSet<>();
    271277
    272278    private transient BufferedImage nonChangedLayersBuffer;
     
    782788        }
    783789
    784         for (MapViewPaintable mvp : temporaryLayers) {
    785             mvp.paint(tempG, this, box);
     790        synchronized (temporaryLayers) {
     791            for (MapViewPaintable mvp : temporaryLayers) {
     792                mvp.paint(tempG, this, box);
     793            }
    786794        }
    787795
     
    10631071    }
    10641072
     1073    /**
     1074     * Adds a new temporary layer.
     1075     * <p>
     1076     * A temporary layer is a layer that is painted above all normal layers. Layers are painted in the order they are added.
     1077     *
     1078     * @param mvp The layer to paint.
     1079     * @return <code>true</code> if the layer was added.
     1080     */
    10651081    public boolean addTemporaryLayer(MapViewPaintable mvp) {
    1066         if (temporaryLayers.contains(mvp)) return false;
    1067         return temporaryLayers.add(mvp);
    1068     }
    1069 
     1082        synchronized (temporaryLayers) {
     1083            return temporaryLayers.add(mvp);
     1084        }
     1085    }
     1086
     1087    /**
     1088     * Removes a layer previously added as temporary layer.
     1089     * @param mvp The layer to remove.
     1090     * @return <code>true</code> if that layer was removed.
     1091     */
    10701092    public boolean removeTemporaryLayer(MapViewPaintable mvp) {
    1071         return temporaryLayers.remove(mvp);
     1093        synchronized (temporaryLayers) {
     1094            return temporaryLayers.remove(mvp);
     1095        }
     1096    }
     1097
     1098    /**
     1099     * Gets a list of temporary layers.
     1100     * @return The layers in the order they are added.
     1101     */
     1102    public List<MapViewPaintable> getTemporaryLayers() {
     1103        synchronized (temporaryLayers) {
     1104            return Collections.unmodifiableList(new ArrayList<>(temporaryLayers));
     1105        }
    10721106    }
    10731107
     
    11401174        }
    11411175        nonChangedLayers.clear();
    1142         temporaryLayers.clear();
     1176        synchronized (temporaryLayers) {
     1177            temporaryLayers.clear();
     1178        }
    11431179    }
    11441180
Note: See TracChangeset for help on using the changeset viewer.