- Timestamp:
- 2015-07-05T18:20:17+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapView.java
r8557 r8573 27 27 import java.util.Collections; 28 28 import java.util.Comparator; 29 import java.util.EnumSet; 29 30 import java.util.LinkedHashSet; 30 31 import java.util.List; … … 407 408 layerLock.writeLock().lock(); 408 409 layerLock.readLock().lock(); 409 boolean fireSetActiveLayer = false;410 EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class); 410 411 Layer oldActiveLayer = activeLayer; 412 OsmDataLayer oldEditLayer = editLayer; 411 413 try { 412 414 try { … … 433 435 if (isOsmDataLayer || oldActiveLayer == null) { 434 436 // autoselect the new layer 435 fireSetActiveLayer = setActiveLayer(layer, true);437 listenersToFire.addAll(setActiveLayer(layer, true)); 436 438 } 437 439 } finally { … … 443 445 ((OsmDataLayer) layer).addLayerStateChangeListener(this); 444 446 } 445 if (fireSetActiveLayer) { 446 onActiveLayerChanged(oldActiveLayer); 447 } 447 onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire); 448 448 layer.addPropertyChangeListener(this); 449 449 Main.addProjectionChangeListener(layer); … … 452 452 layerLock.readLock().unlock(); 453 453 } 454 if (! fireSetActiveLayer) {454 if (!listenersToFire.isEmpty()) { 455 455 repaint(); 456 456 } … … 531 531 */ 532 532 public void removeLayer(Layer layer) { 533 boolean fireEditLayerChanged;534 boolean fireSetActiveLayer = false;535 533 layerLock.writeLock().lock(); 536 534 layerLock.readLock().lock(); 537 535 536 EnumSet<LayerListenerType> listenersToFire = EnumSet.noneOf(LayerListenerType.class); 537 Layer oldActiveLayer = activeLayer; 538 538 OsmDataLayer oldEditLayer = editLayer; 539 Layer oldActiveLayer = activeLayer;540 541 539 try { 542 540 try { … … 546 544 return; 547 545 548 fireEditLayerChanged= setEditLayer(layersList);546 listenersToFire = setEditLayer(layersList); 549 547 550 548 if (layer == activeLayer) { 551 fireSetActiveLayer = setActiveLayer(determineNextActiveLayer(layersList), false);549 listenersToFire.addAll(setActiveLayer(determineNextActiveLayer(layersList), false)); 552 550 } 553 551 … … 562 560 layerLock.writeLock().unlock(); 563 561 } 564 if (fireEditLayerChanged) { 565 onEditLayerChanged(oldEditLayer); 566 } 567 if (fireSetActiveLayer) { 568 onActiveLayerChanged(oldActiveLayer); 569 } 562 onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire); 570 563 fireLayerRemoved(layer); 571 564 layer.removePropertyChangeListener(this); … … 611 604 layerLock.writeLock().lock(); 612 605 layerLock.readLock().lock(); 613 boolean fireEditLayerChanged; 606 EnumSet<LayerListenerType> listenersToFire; 607 Layer oldActiveLayer = activeLayer; 614 608 OsmDataLayer oldEditLayer = editLayer; 615 609 try { … … 626 620 layers.add(pos, layer); 627 621 } 628 fireEditLayerChanged= setEditLayer(layers);622 listenersToFire = setEditLayer(layers); 629 623 } finally { 630 624 layerLock.writeLock().unlock(); 631 625 } 632 if (fireEditLayerChanged) { 633 onEditLayerChanged(editLayer); 634 } 626 onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire); 635 627 AudioPlayer.reset(); 636 628 } finally { … … 946 938 * You must own a write {@link #layerLock} when calling this method. 947 939 * @param layersList A list to select that layer from. 948 * @return <code>true</code> if the edit layer was really changed and the listeners should be informed.949 */ 950 private booleansetEditLayer(List<Layer> layersList) {940 * @return A list of change listeners that should be fired using {@link #onActiveEditLayerChanged(Layer, OsmDataLayer, EnumSet)} 941 */ 942 private EnumSet<LayerListenerType> setEditLayer(List<Layer> layersList) { 951 943 final OsmDataLayer newEditLayer = findNewEditLayer(layersList); 952 944 … … 959 951 960 952 editLayer = newEditLayer; 961 return true;953 return EnumSet.of(LayerListenerType.EDIT_LAYER_CHANGE); 962 954 } else { 963 return false;955 return EnumSet.noneOf(LayerListenerType.class); 964 956 } 965 957 … … 994 986 layerLock.writeLock().lock(); 995 987 layerLock.readLock().lock(); 988 EnumSet<LayerListenerType> listenersToFire; 996 989 Layer oldActiveLayer = activeLayer; 997 try {998 boolean fireSetActiveLayer;990 OsmDataLayer oldEditLayer = editLayer; 991 try { 999 992 try { 1000 fireSetActiveLayer= setActiveLayer(layer, true);993 listenersToFire = setActiveLayer(layer, true); 1001 994 } finally { 1002 995 layerLock.writeLock().unlock(); 1003 996 } 1004 if (fireSetActiveLayer) { 1005 onActiveLayerChanged(oldActiveLayer); 1006 } 997 onActiveEditLayerChanged(oldActiveLayer, oldEditLayer, listenersToFire); 1007 998 } finally { 1008 999 layerLock.readLock().unlock(); … … 1015 1006 * @param layer The layer to be active. 1016 1007 * @param setEditLayer if this is <code>true</code>, the edit layer is also set. 1017 * @return {@code true} if the active layer has changed, {@code false otherwise}1018 */ 1019 private booleansetActiveLayer(final Layer layer, boolean setEditLayer) {1008 * @return A list of change listeners that should be fired using {@link #onActiveEditLayerChanged(Layer, OsmDataLayer, EnumSet)} 1009 */ 1010 private EnumSet<LayerListenerType> setActiveLayer(final Layer layer, boolean setEditLayer) { 1020 1011 if (layer != null && !layers.contains(layer)) 1021 1012 throw new IllegalArgumentException(tr("Layer ''{0}'' must be in list of layers", layer.toString())); 1022 1013 1023 1014 if (layer == activeLayer) 1024 return false;1015 return EnumSet.noneOf(LayerListenerType.class); 1025 1016 1026 1017 activeLayer = layer; 1018 EnumSet<LayerListenerType> listenersToFire = EnumSet.of(LayerListenerType.ACTIVE_LAYER_CHANGE); 1027 1019 if (setEditLayer) { 1028 setEditLayer(layers);1029 } 1030 1031 return true;1020 listenersToFire.addAll(setEditLayer(layers)); 1021 } 1022 1023 return listenersToFire; 1032 1024 } 1033 1025 … … 1043 1035 } finally { 1044 1036 layerLock.readLock().unlock(); 1037 } 1038 } 1039 1040 private enum LayerListenerType { 1041 ACTIVE_LAYER_CHANGE, 1042 EDIT_LAYER_CHANGE 1043 } 1044 1045 /** 1046 * This is called whenever one of active layer/edit layer or both may have been changed, 1047 * @param oldActive The old active layer 1048 * @param oldEdit The old edit layer. 1049 * @param listenersToFire A mask of listeners to fire using {@link LayerListenerType}s 1050 */ 1051 private void onActiveEditLayerChanged(final Layer oldActive, final OsmDataLayer oldEdit, EnumSet<LayerListenerType> listenersToFire) { 1052 if (listenersToFire.contains(LayerListenerType.EDIT_LAYER_CHANGE)) { 1053 onEditLayerChanged(oldEdit); 1054 } 1055 if (listenersToFire.contains(LayerListenerType.ACTIVE_LAYER_CHANGE)) { 1056 onActiveLayerChanged(oldActive); 1045 1057 } 1046 1058 }
Note:
See TracChangeset
for help on using the changeset viewer.