Ignore:
Timestamp:
2012-08-08T01:25:25+02:00 (12 years ago)
Author:
Don-vip
Message:

see #7280 - Change synchronization mechanism of MapView when being notified of paint preferences change.

The previous mechanism leads to a deadlock when the paint() method triggers itself a paint preference change, such as when a TMS layer wants to paint attribution.
This caused an HMI freeze of 1s and Bing layer to never display tiles at its first display without cached attribution.

File:
1 edited

Legend:

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

    r5384 r5406  
    2929
    3030import javax.swing.AbstractButton;
     31import javax.swing.ActionMap;
     32import javax.swing.InputMap;
    3133import javax.swing.JOptionPane;
    3234import javax.swing.JPanel;
     
    5658
    5759/**
    58  * This is a component used in the MapFrame for browsing the map. It use is to
    59  * provide the MapMode's enough capabilities to operate.
     60 * This is a component used in the {@link MapFrame} for browsing the map. It use is to
     61 * provide the MapMode's enough capabilities to operate.<br/><br/>
    6062 *
    61  * MapView hold meta-data about the data set currently displayed, as scale level,
     63 * {@code MapView} holds meta-data about the data set currently displayed, as scale level,
    6264 * center point viewed, what scrolling mode or editing mode is selected or with
    63  * what projection the map is viewed etc..
     65 * what projection the map is viewed etc..<br/><br/>
    6466 *
    65  * MapView is able to administrate several layers.
     67 * {@code MapView} is able to administrate several layers.
    6668 *
    6769 * @author imi
     
    7072
    7173    /**
    72      * Interface to notify listeners of the change of the active layer.
     74     * Interface to notify listeners of a layer change.
    7375     * @author imi
    7476     */
    7577    public interface LayerChangeListener {
     78       
     79        /**
     80         * Notifies this listener that the active layer has changed.
     81         * @param oldLayer The previous active layer
     82         * @param newLayer The new activer layer
     83         */
    7684        void activeLayerChange(Layer oldLayer, Layer newLayer);
     85       
     86        /**
     87         * Notifies this listener that a layer has been added.
     88         * @param newLayer The new added layer
     89         */
    7790        void layerAdded(Layer newLayer);
     91       
     92        /**
     93         * Notifies this listener that a layer has been removed.
     94         * @param oldLayer The old removed layer
     95         */
    7896        void layerRemoved(Layer oldLayer);
    7997    }
     
    131149    }
    132150
     151    /**
     152     * Adds an edit layer change listener
     153     *
     154     * @param listener the listener. Ignored if null or already registered.
     155     */
    133156    public static void addEditLayerChangeListener(EditLayerChangeListener listener) {
    134157        if (listener != null) {
     
    193216    private Rectangle lastClipBounds = new Rectangle();
    194217
     218    /**
     219     * Constructs a new {@code MapView}.
     220     * @param contentPane The content pane used to register shortcuts in its {@link InputMap} and {@link ActionMap}
     221     */
    195222    public MapView(final JPanel contentPane) {
    196223        Main.pref.addPreferenceChangeListener(this);
     
    269296     * Add a layer to the current MapView. The layer will be added at topmost
    270297     * position.
     298     * @param layer The layer to add
    271299     */
    272300    public void addLayer(Layer layer) {
     
    357385     * Remove the layer from the mapview. If the layer was in the list before,
    358386     * an LayerChange event is fired.
     387     * @param layer The layer to remove
    359388     */
    360389    public void removeLayer(Layer layer) {
     
    468497     * Draw the component.
    469498     */
    470     @Override public synchronized void paint(Graphics g) {
     499    @Override public void paint(Graphics g) {
    471500        if (BugReportExceptionHandler.exceptionHandlingInProgress())
    472501            return;
     
    486515        }
    487516
    488         boolean canUseBuffer = !paintPreferencesChanged && nonChangedLayers.size() <= nonChangedLayersCount &&
     517        boolean canUseBuffer;
     518       
     519        synchronized (this) {
     520            canUseBuffer = !paintPreferencesChanged;
     521        }
     522        canUseBuffer = canUseBuffer && nonChangedLayers.size() <= nonChangedLayersCount &&
    489523        lastViewID == getViewID() && lastClipBounds.contains(g.getClipBounds());
    490524        if (canUseBuffer) {
     
    841875    }
    842876
    843     public synchronized void preferenceChanged(PreferenceChangeEvent e) {
    844         paintPreferencesChanged = true;
     877    @Override
     878    public void preferenceChanged(PreferenceChangeEvent e) {
     879        synchronized (this) {
     880            paintPreferencesChanged = true;
     881        }
    845882    }
    846883
Note: See TracChangeset for help on using the changeset viewer.