- Timestamp:
- 2020-03-21T21:27:36+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r16048 r16187 592 592 // revert all executed commands 593 593 ds = executedCmds.getFirst().getAffectedDataSet(); 594 ds. beginUpdate();595 while (!executedCmds.isEmpty()) {596 executedCmds.removeLast().undoCommand();597 }598 ds.endUpdate();594 ds.update(() -> { 595 while (!executedCmds.isEmpty()) { 596 executedCmds.removeLast().undoCommand(); 597 } 598 }); 599 599 } 600 600 } … … 1748 1748 @Override 1749 1749 public void undoCommand() { 1750 getAffectedDataSet().beginUpdate(); 1751 super.undoCommand(); 1752 getAffectedDataSet().endUpdate(); 1750 getAffectedDataSet().update(super::undoCommand); 1753 1751 } 1754 1752 1755 1753 @Override 1756 1754 public boolean executeCommand() { 1757 getAffectedDataSet().beginUpdate(); 1758 boolean rc = super.executeCommand(); 1759 getAffectedDataSet().endUpdate(); 1760 return rc; 1755 return getAffectedDataSet().update(super::executeCommand); 1761 1756 } 1762 1757 } -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r15676 r16187 12 12 import javax.swing.JOptionPane; 13 13 14 import org.openstreetmap.josm.command.Command;15 14 import org.openstreetmap.josm.command.MoveCommand; 16 15 import org.openstreetmap.josm.data.UndoRedoHandler; … … 98 97 } 99 98 100 @Override 101 public void actionPerformed(ActionEvent event) { 102 DataSet ds = getLayerManager().getEditDataSet(); 103 104 if (!MainApplication.isDisplayingMapView() || ds == null) 105 return; 106 107 // find out how many "real" units the objects have to be moved in order to 108 // achive an 1-pixel movement 109 110 MapView mapView = MainApplication.getMap().mapView; 99 /** 100 * Find out how many "real" units the objects have to be moved in order to achieve an 1-pixel movement 101 * @param mapView map view 102 * @return move offset 103 */ 104 private EastNorth getOffset(MapView mapView) { 111 105 EastNorth en1 = mapView.getEastNorth(100, 100); 112 106 EastNorth en2 = mapView.getEastNorth(101, 101); … … 131 125 } 132 126 127 return new EastNorth(distx, disty); 128 } 129 130 @Override 131 public void actionPerformed(ActionEvent event) { 132 DataSet ds = getLayerManager().getEditDataSet(); 133 134 if (!MainApplication.isDisplayingMapView() || ds == null) 135 return; 136 137 MapView mapView = MainApplication.getMap().mapView; 138 final EastNorth dist = getOffset(mapView); 139 133 140 Collection<OsmPrimitive> selection = ds.getSelected(); 134 141 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 135 142 136 Command c = UndoRedoHandler.getInstance().getLastCommand(); 137 138 ds.beginUpdate(); 139 try { 143 MoveCommand cmd = ds.update(c -> { 144 MoveCommand moveCmd; 140 145 if (c instanceof MoveCommand && ds.equals(c.getAffectedDataSet()) 141 146 && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 142 ((MoveCommand) c).moveAgain(distx, disty); 147 moveCmd = (MoveCommand) c; 148 moveCmd.moveAgain(dist.east(), dist.north()); 143 149 } else { 144 c = new MoveCommand(ds, selection, distx, disty);145 UndoRedoHandler.getInstance().add( c);150 moveCmd = new MoveCommand(ds, selection, dist.east(), dist.north()); 151 UndoRedoHandler.getInstance().add(moveCmd); 146 152 } 147 } finally { 148 ds.endUpdate(); 149 } 153 return moveCmd; 154 }, UndoRedoHandler.getInstance().getLastCommand()); 150 155 151 156 for (Node n : affectedNodes) { 152 157 if (n.isLatLonKnown() && n.isOutSideWorld()) { 153 158 // Revert move 154 ((MoveCommand) c).moveAgain(-distx, -disty);159 cmd.moveAgain(-dist.east(), -dist.north()); 155 160 JOptionPane.showMessageDialog( 156 161 MainApplication.getMainFrame(), -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r15586 r16187 172 172 public void actionPerformed(ActionEvent e) { 173 173 DataSet ds = getLayerManager().getEditDataSet(); 174 ds.beginUpdate(); 175 try { 174 ds.update(() -> { 176 175 List<Way> ways = ds.getSelectedWays().stream() 177 176 .filter(p -> !p.isIncomplete()) … … 195 194 simplifyWays(ways, err); 196 195 } 197 } finally { 198 ds.endUpdate(); 199 } 196 }); 200 197 } 201 198 -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r15735 r16187 247 247 248 248 private static void addRemoveSelection(DataSet ds, OsmPrimitive toAdd, OsmPrimitive toRemove) { 249 ds.beginUpdate(); // to prevent the selection listener to screw around with the state 250 try { 249 ds.update(() -> { // to prevent the selection listener to screw around with the state 251 250 addSelection(ds, toAdd); 252 251 clearSelection(ds, toRemove); 253 } finally { 254 ds.endUpdate(); 255 } 252 }); 256 253 } 257 254 -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r16177 r16187 712 712 if (mode == Mode.MOVE) { 713 713 if (startEN == null) return false; // fix #8128 714 ds.beginUpdate();715 try {714 return ds.update(() -> { 715 MoveCommand moveCmd = null; 716 716 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 717 ((MoveCommand) c).saveCheckpoint(); 718 ((MoveCommand) c).applyVectorTo(currentEN); 717 moveCmd = (MoveCommand) c; 718 moveCmd.saveCheckpoint(); 719 moveCmd.applyVectorTo(currentEN); 719 720 } else if (!selection.isEmpty()) { 720 c= new MoveCommand(selection, startEN, currentEN);721 UndoRedoHandler.getInstance().add( c);721 moveCmd = new MoveCommand(selection, startEN, currentEN); 722 UndoRedoHandler.getInstance().add(moveCmd); 722 723 } 723 724 for (Node n : affectedNodes) { 724 725 if (n.isOutSideWorld()) { 725 726 // Revert move 726 if ( c instanceof MoveCommand) {727 ((MoveCommand) c).resetToCheckpoint();727 if (moveCmd != null) { 728 moveCmd.resetToCheckpoint(); 728 729 } 729 730 // TODO: We might use a simple notification in the lower left corner. … … 737 738 } 738 739 } 739 } finally { 740 ds.endUpdate(); 741 } 740 return true; 741 }); 742 742 } else { 743 743 startEN = currentEN; // drag can continue after scaling/rotation … … 747 747 } 748 748 749 ds.beginUpdate(); 750 try { 749 return ds.update(() -> { 751 750 if (mode == Mode.ROTATE) { 752 751 if (c instanceof RotateCommand && affectedNodes.equals(((RotateCommand) c).getTransformedNodes())) { … … 767 766 MainApplication.getMap().statusLine.setDist(ways); 768 767 } 769 } finally { 770 ds.endUpdate(); 771 } 772 } 773 return true; 768 return true; 769 }); 770 } 774 771 } 775 772 … … 910 907 Collection<Node> affectedNodes = AllNodesVisitor.getAllNodes(selection); 911 908 Command c = getLastCommandInDataset(ds); 912 ds.beginUpdate(); 913 try { 909 ds.update(() -> { 914 910 if (c instanceof MoveCommand && affectedNodes.equals(((MoveCommand) c).getParticipatingPrimitives())) { 915 911 Node selectedNode = selNodes.iterator().next(); … … 919 915 targetEN.getY() - selectedEN.getY()); 920 916 } 921 } finally { 922 ds.endUpdate(); 923 } 917 }); 924 918 } 925 919 -
trunk/src/org/openstreetmap/josm/command/PurgeCommand.java
r13513 r16187 84 84 @Override 85 85 public boolean executeCommand() { 86 getAffectedDataSet().beginUpdate(); 87 try { 86 getAffectedDataSet().update(() -> { 88 87 purgedConflicts.get().clear(); 89 88 // unselect primitives in advance to not fire a selection change for every one of them … … 116 115 } 117 116 getAffectedDataSet().clearMappaintCache(); 118 } finally { 119 getAffectedDataSet().endUpdate(); 120 } 117 }); 121 118 return true; 122 119 } … … 127 124 return; 128 125 129 getAffectedDataSet().beginUpdate(); 130 try { 126 getAffectedDataSet().update(() -> { 131 127 for (OsmPrimitive osm : toPurge) { 132 128 PrimitiveData data = makeIncompleteDataByPrimId.get(osm); … … 147 143 } 148 144 getAffectedDataSet().clearMappaintCache(); 149 } finally { 150 getAffectedDataSet().endUpdate(); 151 } 145 }); 152 146 } 153 147 -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r16119 r16187 24 24 import java.util.function.Function; 25 25 import java.util.function.Predicate; 26 import java.util.function.Supplier; 26 27 import java.util.stream.Collectors; 27 28 import java.util.stream.Stream; … … 256 257 public DataSet(OsmPrimitive... osmPrimitives) { 257 258 this(); 258 beginUpdate(); 259 try { 259 update(() -> { 260 260 for (OsmPrimitive o : osmPrimitives) { 261 261 addPrimitive(o); 262 262 } 263 } finally { 264 endUpdate(); 265 } 263 }); 266 264 } 267 265 … … 499 497 Objects.requireNonNull(primitive, "primitive"); 500 498 checkModifiable(); 501 beginUpdate(); 502 try { 499 update(() -> { 503 500 if (getPrimitiveById(primitive) != null) 504 501 throw new DataIntegrityProblemException( … … 511 508 store.addPrimitive(primitive); 512 509 firePrimitivesAdded(Collections.singletonList(primitive), false); 513 } finally { 514 endUpdate(); 515 } 510 }); 516 511 } 517 512 … … 528 523 public void removePrimitive(PrimitiveId primitiveId) { 529 524 checkModifiable(); 530 beginUpdate(); 531 try { 525 update(() -> { 532 526 OsmPrimitive primitive = getPrimitiveByIdChecked(primitiveId); 533 527 if (primitive == null) … … 535 529 removePrimitiveImpl(primitive); 536 530 firePrimitivesRemoved(Collections.singletonList(primitive), false); 537 } finally { 538 endUpdate(); 539 } 531 }); 540 532 } 541 533 … … 552 544 void removePrimitive(OsmPrimitive primitive) { 553 545 checkModifiable(); 554 beginUpdate(); 555 try { 546 update(() -> { 556 547 removePrimitiveImpl(primitive); 557 548 firePrimitivesRemoved(Collections.singletonList(primitive), false); 558 } finally { 559 endUpdate(); 560 } 549 }); 561 550 } 562 551 … … 804 793 public Set<Way> unlinkNodeFromWays(Node node) { 805 794 checkModifiable(); 806 Set<Way> result = new HashSet<>(); 807 beginUpdate(); 808 try { 795 return update(() -> { 796 Set<Way> result = new HashSet<>(); 809 797 for (Way way : node.getParentWays()) { 810 798 List<Node> wayNodes = way.getNodes(); … … 818 806 } 819 807 } 820 } finally { 821 endUpdate(); 822 } 823 return result; 808 return result; 809 }); 824 810 } 825 811 … … 833 819 public Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive) { 834 820 checkModifiable(); 835 Set<Relation> result = new HashSet<>(); 836 beginUpdate(); 837 try { 821 return update(() -> { 822 Set<Relation> result = new HashSet<>(); 838 823 for (Relation relation : getRelations()) { 839 824 List<RelationMember> members = relation.getMembers(); … … 854 839 } 855 840 } 856 } finally { 857 endUpdate(); 858 } 859 return result; 841 return result; 842 }); 860 843 } 861 844 … … 869 852 public Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) { 870 853 checkModifiable(); 871 Set<OsmPrimitive> result = new HashSet<>(); 872 beginUpdate(); 873 try { 854 return update(() -> { 855 Set<OsmPrimitive> result = new HashSet<>(); 874 856 if (referencedPrimitive instanceof Node) { 875 857 result.addAll(unlinkNodeFromWays((Node) referencedPrimitive)); 876 858 } 877 859 result.addAll(unlinkPrimitiveFromRelations(referencedPrimitive)); 878 } finally { 879 endUpdate(); 880 } 881 return result; 860 return result; 861 }); 882 862 } 883 863 … … 979 959 } 980 960 961 /** 962 * Performs the update runnable between {@link #beginUpdate()} / {@link #endUpdate()} calls. 963 * @param runnable update action 964 * @since 16187 965 */ 966 public void update(Runnable runnable) { 967 beginUpdate(); 968 try { 969 runnable.run(); 970 } finally { 971 endUpdate(); 972 } 973 } 974 975 /** 976 * Performs the update function between {@link #beginUpdate()} / {@link #endUpdate()} calls. 977 * @param function update function 978 * @param t function argument 979 * @param <T> argument type 980 * @param <R> result type 981 * @return function result 982 * @since 16187 983 */ 984 public <T, R> R update(Function<T, R> function, T t) { 985 beginUpdate(); 986 try { 987 return function.apply(t); 988 } finally { 989 endUpdate(); 990 } 991 } 992 993 /** 994 * Performs the update supplier between {@link #beginUpdate()} / {@link #endUpdate()} calls. 995 * @param supplier update supplier 996 * @param <R> result type 997 * @return supplier result 998 * @since 16187 999 */ 1000 public <R> R update(Supplier<R> supplier) { 1001 beginUpdate(); 1002 try { 1003 return supplier.get(); 1004 } finally { 1005 endUpdate(); 1006 } 1007 } 1008 981 1009 private void fireEventToListeners(AbstractDatasetChangedEvent event) { 982 1010 for (DataSetListener listener : listeners) { … … 1044 1072 * Invalidates the internal cache of projected east/north coordinates. 1045 1073 * 1046 * This method can be invoked after the globally configured projection method 1047 * changed. 1074 * This method can be invoked after the globally configured projection method changed. 1048 1075 */ 1049 1076 public void invalidateEastNorthCache() { 1050 1077 if (ProjectionRegistry.getProjection() == null) 1051 1078 return; // sanity check 1052 beginUpdate(); 1053 try { 1054 for (Node n : getNodes()) { 1055 n.invalidateEastNorthCache(); 1056 } 1057 } finally { 1058 endUpdate(); 1059 } 1079 update(() -> getNodes().forEach(Node::invalidateEastNorthCache)); 1060 1080 } 1061 1081 … … 1064 1084 */ 1065 1085 public void cleanupDeletedPrimitives() { 1066 beginUpdate(); 1067 try { 1086 update(() -> { 1068 1087 Collection<OsmPrimitive> toCleanUp = getPrimitives( 1069 1088 primitive -> primitive.isDeleted() && (!primitive.isVisible() || primitive.isNew())); … … 1076 1095 firePrimitivesRemoved(toCleanUp, false); 1077 1096 } 1078 } finally { 1079 endUpdate(); 1080 } 1097 }); 1081 1098 } 1082 1099 … … 1091 1108 //TODO: Report listeners that are still active (should be none) 1092 1109 checkModifiable(); 1093 beginUpdate(); 1094 try { 1110 update(() -> { 1095 1111 clearSelection(); 1096 1112 for (OsmPrimitive primitive : allPrimitives) { … … 1099 1115 store.clear(); 1100 1116 allPrimitives.clear(); 1101 } finally { 1102 endUpdate(); 1103 } 1117 }); 1104 1118 } 1105 1119 -
trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java
r15418 r16187 424 424 progressMonitor.beginTask(tr("Merging data..."), sourceDataSet.allPrimitives().size()); 425 425 } 426 targetDataSet.beginUpdate(); 427 try { 426 targetDataSet.update(() -> { 428 427 List<? extends OsmPrimitive> candidates = new ArrayList<>(targetDataSet.getNodes()); 429 428 for (Node node: sourceDataSet.getNodes()) { … … 481 480 targetDataSet.lock(); 482 481 } 483 } finally { 484 targetDataSet.endUpdate(); 485 } 482 }); 486 483 if (progressMonitor != null) { 487 484 progressMonitor.finishTask(); -
trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java
r15390 r16187 110 110 ds.beginUpdate(); 111 111 try { 112 113 112 final Collection<OsmPrimitive> all = ds.allNonDeletedCompletePrimitives(); 114 113 … … 158 157 List<OsmPrimitive> deselect = new ArrayList<>(); 159 158 160 ds.beginUpdate(); 161 try { 159 ds.update(() -> { 162 160 for (int i = 0; i < 2; i++) { 163 161 for (OsmPrimitive primitive: primitives) { … … 190 188 } 191 189 } 192 } finally { 193 ds.endUpdate(); 194 } 190 }); 195 191 196 192 if (!deselect.isEmpty()) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r15586 r16187 694 694 */ 695 695 private void tryUndo() { 696 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 697 int i = fixCommands.size() - 1; 698 ds.beginUpdate(); 699 for (; i >= 0; i--) { 700 fixCommands.get(i).undoCommand(); 701 } 702 ds.endUpdate(); 703 } 704 696 MainApplication.getLayerManager().getActiveDataSet().update(() -> { 697 for (int i = fixCommands.size() - 1; i >= 0; i--) { 698 fixCommands.get(i).undoCommand(); 699 } 700 }); 701 } 705 702 } 706 703 … … 723 720 @Override 724 721 public void undoCommand() { 725 getAffectedDataSet().beginUpdate(); 726 super.undoCommand(); 727 getAffectedDataSet().endUpdate(); 722 getAffectedDataSet().update(super::undoCommand); 728 723 } 729 724 730 725 @Override 731 726 public boolean executeCommand() { 732 getAffectedDataSet().beginUpdate(); 733 boolean rc = super.executeCommand(); 734 getAffectedDataSet().endUpdate(); 735 return rc; 727 return getAffectedDataSet().update(super::executeCommand); 736 728 } 737 729 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r16080 r16187 652 652 // if uploaded, clean the modified flags as well 653 653 data.cleanupDeletedPrimitives(); 654 data.beginUpdate(); 655 try { 654 data.update(() -> { 656 655 for (OsmPrimitive p: data.allPrimitives()) { 657 656 if (processed.contains(p)) { … … 659 658 } 660 659 } 661 } finally { 662 data.endUpdate(); 663 } 660 }); 664 661 } 665 662
Note:
See TracChangeset
for help on using the changeset viewer.