Changeset 18004 in josm
- Timestamp:
- 2021-07-12T02:41:41+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r17999 r18004 36 36 import org.openstreetmap.josm.data.osm.Way; 37 37 import org.openstreetmap.josm.data.osm.WaySegment; 38 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;39 import org.openstreetmap.josm.data.osm.event.DataChangedEvent;40 import org.openstreetmap.josm.data.osm.event.DataSetListener;41 import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;42 import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;43 import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;44 import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;45 import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;46 import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;47 38 import org.openstreetmap.josm.gui.ExtendedDialog; 48 39 import org.openstreetmap.josm.gui.MainApplication; … … 155 146 156 147 if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) { 157 final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel ectedNodes, sel);148 final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel); 158 149 dialog.toggleEnable("way.split.segment-selection-dialog"); 159 150 if (!dialog.toggleCheckState()) { … … 174 165 static class SegmentToKeepSelectionDialog extends ExtendedDialog { 175 166 static final AtomicInteger DISPLAY_COUNT = new AtomicInteger(); 167 final transient Way selectedWay; 168 final transient List<Way> newWays; 176 169 final JList<Way> list; 177 transient Way selectedWay;178 transient List<Way> newWays;179 transient Way wayToKeep;180 170 final transient List<OsmPrimitive> selection; 181 final transient List<Node> selectedNodes; 182 private final SplitWayDataSetListener dataSetListener; 183 184 SegmentToKeepSelectionDialog(Way selectedWay, List<Way> newWays, Way wayToKeep, List<Node> selectedNodes, List<OsmPrimitive> selection) { 171 final transient Way wayToKeep; 172 173 SegmentToKeepSelectionDialog(Way selectedWay, List<Way> newWays, Way wayToKeep, List<OsmPrimitive> selection) { 185 174 super(MainApplication.getMainFrame(), tr("Which way segment should reuse the history of {0}?", selectedWay.getId()), 186 175 new String[]{tr("Ok"), tr("Cancel")}, true); … … 188 177 this.selectedWay = selectedWay; 189 178 this.newWays = newWays; 190 this.selectedNodes = selectedNodes;191 179 this.selection = selection; 192 180 this.wayToKeep = wayToKeep; 193 181 this.list = new JList<>(newWays.toArray(new Way[0])); 194 this.dataSetListener = new SplitWayDataSetListener();195 selectedWay.getDataSet().addDataSetListener(dataSetListener);196 197 182 configureList(); 198 183 … … 225 210 226 211 protected void setHighlightedWaySegments(Collection<WaySegment> segments) { 227 DataSet ds = selectedWay.getDataSet(); 228 if (ds != null) { 229 ds.setHighlightedWaySegments(segments); 230 MainApplication.getMap().mapView.repaint(); 231 } 212 selectedWay.getDataSet().setHighlightedWaySegments(segments); 213 MainApplication.getMap().mapView.repaint(); 232 214 } 233 215 … … 239 221 list.setSelectedValue(wayToKeep, true); 240 222 } else { 241 DataSet ds = selectedWay.getDataSet();242 if (ds != null) {243 ds.removeDataSetListener(dataSetListener);244 }245 223 setHighlightedWaySegments(Collections.emptyList()); 246 224 DISPLAY_COUNT.decrementAndGet(); … … 255 233 super.buttonAction(buttonIndex, evt); 256 234 toggleSaveState(); // necessary since #showDialog() does not handle it due to the non-modal dialog 257 if (getValue() == 1 && selectedWay.getDataSet() != null) {235 if (getValue() == 1) { 258 236 doSplitWay(selectedWay, list.getSelectedValue(), newWays, selection); 259 237 } 260 }261 262 private class SplitWayDataSetListener implements DataSetListener {263 264 @Override265 public void primitivesAdded(PrimitivesAddedEvent event) {266 }267 268 @Override269 public void primitivesRemoved(PrimitivesRemovedEvent event) {270 if (event.getPrimitives().stream().anyMatch(p -> p instanceof Way)) {271 updateWaySegments();272 }273 }274 275 @Override276 public void tagsChanged(TagsChangedEvent event) {}277 278 @Override279 public void nodeMoved(NodeMovedEvent event) {}280 281 @Override282 public void wayNodesChanged(WayNodesChangedEvent event) {283 updateWaySegments();284 }285 286 @Override287 public void relationMembersChanged(RelationMembersChangedEvent event) {}288 289 @Override290 public void otherDatasetChange(AbstractDatasetChangedEvent event) {}291 292 @Override293 public void dataChanged(DataChangedEvent event) {}294 295 private void updateWaySegments() {296 if (!selectedWay.isUsable()) {297 setVisible(false);298 return;299 }300 newWays = SplitWayCommand.createNewWaysFromChunks(selectedWay,301 SplitWayCommand.buildSplitChunks(selectedWay, selectedNodes));302 if (list.getSelectedIndex() < newWays.size()) {303 wayToKeep = newWays.get(list.getSelectedIndex());304 } else {305 wayToKeep = SplitWayCommand.Strategy.keepLongestChunk().determineWayToKeep(newWays);306 }307 list.setListData(newWays.toArray(new Way[0]));308 list.setSelectedValue(wayToKeep, true);309 }310 311 238 } 312 239 }
Note:
See TracChangeset
for help on using the changeset viewer.