Changeset 2658 in josm for trunk/src


Ignore:
Timestamp:
2009-12-19T14:06:51+01:00 (12 years ago)
Author:
jttt
Message:

Do not update properties and selection dialogs when hidden

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

Legend:

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

    r2652 r2658  
    22package org.openstreetmap.josm.data.osm.event;
    33
    4 import java.util.ArrayList;
    5 import java.util.List;
    64import java.util.Queue;
     5import java.util.concurrent.CopyOnWriteArrayList;
    76import java.util.concurrent.LinkedBlockingQueue;
    87
     
    3231
    3332    private final Queue<AbstractDatasetChangedEvent> eventsInEDT = new LinkedBlockingQueue<AbstractDatasetChangedEvent>();
    34     private final List<DataSetListener> inEDTListeners = new ArrayList<DataSetListener>();
    35     private final List<DataSetListener> normalListeners = new ArrayList<DataSetListener>();
     33    private final CopyOnWriteArrayList<DataSetListener> inEDTListeners = new CopyOnWriteArrayList<DataSetListener>();
     34    private final CopyOnWriteArrayList<DataSetListener> normalListeners = new CopyOnWriteArrayList<DataSetListener>();
    3635    private final DataSetListener myListener = new DataSetListenerAdapter(this);
    3736
     
    4847    public void addDatasetListener(DataSetListener listener, boolean fireInEDT) {
    4948        if (fireInEDT) {
    50             inEDTListeners.add(listener);
     49            inEDTListeners.addIfAbsent(listener);
    5150        } else {
    52             normalListeners.add(listener);
     51            normalListeners.addIfAbsent(listener);
    5352        }
    5453    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r2626 r2658  
    1818import java.util.Collections;
    1919import java.util.LinkedList;
    20 import java.util.List;
    2120import java.util.NoSuchElementException;
    2221
     
    4645import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    4746import org.openstreetmap.josm.gui.SideButton;
    48 import org.openstreetmap.josm.gui.layer.Layer;
    4947import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5048import org.openstreetmap.josm.tools.Shortcut;
     
    5755 * @author imi
    5856 */
    59 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, MapView.LayerChangeListener {
     57public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener {
    6058
    6159    private static final int SELECTION_HISTORY_SIZE = 10;
     
    162160        }
    163161
    164         DataSet.selListeners.add(this);
    165         MapView.addLayerChangeListener(this);
     162        MapView.addEditLayerChangeListener(this);
    166163    }
    167164
    168165    @Override
    169166    public void tearDown() {
    170         MapView.removeLayerChangeListener(this);
     167        MapView.removeEditLayerChangeListener(this);
     168    }
     169
     170    @Override
     171    public void showNotify() {
     172        DataSet.selListeners.add(this);
     173        updateSelection();
     174    }
     175
     176    @Override
     177    public void hideNotify() {
    171178        DataSet.selListeners.remove(this);
    172179    }
     
    370377    }
    371378
    372     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    373         if (newLayer instanceof OsmDataLayer) {
    374             OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
    375             selectionChanged(dataLayer.data.getSelected());
     379    private void updateSelection() {
     380        if (Main.main.getCurrentDataSet() == null) {
     381            selectionChanged(Collections.<OsmPrimitive>emptyList());
    376382        } else {
    377             List<OsmPrimitive> selection = Collections.emptyList();
    378             selectionChanged(selection);
    379         }
    380     }
    381 
    382     public void layerAdded(Layer newLayer) {
    383         // do nothing
    384     }
    385 
    386     public void layerRemoved(Layer oldLayer) {
    387         // do nothing
     383            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     384        }
     385    }
     386
     387    public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     388        updateSelection();
    388389    }
    389390}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/ListOfUsedTags.java

    r2657 r2658  
    4747        else
    4848            return values;
     49    }
     50
     51    public void rebuildNecessary() {
     52        dirty = true;
    4953    }
    5054
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r2657 r2658  
    7171import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
    7272import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    73 import org.openstreetmap.josm.gui.layer.Layer;
    7473import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    7574import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
     
    9796 * @author imi
    9897 */
    99 public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.LayerChangeListener {
     98public class PropertiesDialog extends ToggleDialog implements SelectionChangedListener, MapView.EditLayerChangeListener {
    10099    /**
    101100     * Watches for double clicks and from editing or new property, depending on the
     
    145144    public void showNotify() {
    146145        DatasetEventManager.getInstance().addDatasetListener(listOfUsedTags, false);
     146        listOfUsedTags.rebuildNecessary();
     147        DataSet.selListeners.add(this);
     148        updateSelection();
    147149    }
    148150
     
    150152    public void hideNotify() {
    151153        DatasetEventManager.getInstance().removeDatasetListener(listOfUsedTags);
     154        DataSet.selListeners.remove(this);
    152155    }
    153156
     
    568571        add(buttonPanel, BorderLayout.SOUTH);
    569572
    570         DataSet.selListeners.add(this);
    571         MapView.addLayerChangeListener(this);
     573        MapView.addEditLayerChangeListener(this);
    572574    }
    573575
    574576    @Override
    575577    public void tearDown() {
    576         MapView.removeLayerChangeListener(this);
     578        MapView.removeEditLayerChangeListener(this);
    577579    }
    578580
     
    776778    }
    777779
     780    private void updateSelection() {
     781        if (Main.main.getCurrentDataSet() == null) {
     782            selectionChanged(Collections.<OsmPrimitive>emptyList());
     783        } else {
     784            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     785        }
     786    }
     787
    778788    /* ---------------------------------------------------------------------------------- */
    779     /* LayerChangeListener                                                                */
     789    /* EditLayerChangeListener                                                                */
    780790    /* ---------------------------------------------------------------------------------- */
    781     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
    782         if (newLayer instanceof OsmDataLayer) {
    783             OsmDataLayer dataLayer = (OsmDataLayer)newLayer;
    784             selectionChanged(dataLayer.data.getSelected());
    785         } else {
    786             List<OsmPrimitive> selection = Collections.emptyList();
    787             selectionChanged(selection);
    788         }
    789     }
    790 
    791     public void layerAdded(Layer newLayer) {
    792         // do nothing
    793     }
    794 
    795     public void layerRemoved(Layer oldLayer) {
    796         // do nothing
     791    public void editLayerChanged(OsmDataLayer oldLayer, OsmDataLayer newLayer) {
     792        updateSelection();
    797793    }
    798794
Note: See TracChangeset for help on using the changeset viewer.