Changeset 18004 in josm


Ignore:
Timestamp:
2021-07-12T02:41:41+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21102 - see #20935 - revert r17999

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r17999 r18004  
    3636import org.openstreetmap.josm.data.osm.Way;
    3737import 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;
    4738import org.openstreetmap.josm.gui.ExtendedDialog;
    4839import org.openstreetmap.josm.gui.MainApplication;
     
    155146
    156147            if (ExpertToggleAction.isExpert() && !selectedWay.isNew()) {
    157                 final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, selectedNodes, sel);
     148                final ExtendedDialog dialog = new SegmentToKeepSelectionDialog(selectedWay, newWays, wayToKeep, sel);
    158149                dialog.toggleEnable("way.split.segment-selection-dialog");
    159150                if (!dialog.toggleCheckState()) {
     
    174165    static class SegmentToKeepSelectionDialog extends ExtendedDialog {
    175166        static final AtomicInteger DISPLAY_COUNT = new AtomicInteger();
     167        final transient Way selectedWay;
     168        final transient List<Way> newWays;
    176169        final JList<Way> list;
    177         transient Way selectedWay;
    178         transient List<Way> newWays;
    179         transient Way wayToKeep;
    180170        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) {
    185174            super(MainApplication.getMainFrame(), tr("Which way segment should reuse the history of {0}?", selectedWay.getId()),
    186175                    new String[]{tr("Ok"), tr("Cancel")}, true);
     
    188177            this.selectedWay = selectedWay;
    189178            this.newWays = newWays;
    190             this.selectedNodes = selectedNodes;
    191179            this.selection = selection;
    192180            this.wayToKeep = wayToKeep;
    193181            this.list = new JList<>(newWays.toArray(new Way[0]));
    194             this.dataSetListener = new SplitWayDataSetListener();
    195             selectedWay.getDataSet().addDataSetListener(dataSetListener);
    196 
    197182            configureList();
    198183
     
    225210
    226211        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();
    232214        }
    233215
     
    239221                list.setSelectedValue(wayToKeep, true);
    240222            } else {
    241                 DataSet ds = selectedWay.getDataSet();
    242                 if (ds != null) {
    243                     ds.removeDataSetListener(dataSetListener);
    244                 }
    245223                setHighlightedWaySegments(Collections.emptyList());
    246224                DISPLAY_COUNT.decrementAndGet();
     
    255233            super.buttonAction(buttonIndex, evt);
    256234            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) {
    258236                doSplitWay(selectedWay, list.getSelectedValue(), newWays, selection);
    259237            }
    260         }
    261 
    262         private class SplitWayDataSetListener implements DataSetListener {
    263 
    264             @Override
    265             public void primitivesAdded(PrimitivesAddedEvent event) {
    266             }
    267 
    268             @Override
    269             public void primitivesRemoved(PrimitivesRemovedEvent event) {
    270                 if (event.getPrimitives().stream().anyMatch(p -> p instanceof Way)) {
    271                     updateWaySegments();
    272                 }
    273             }
    274 
    275             @Override
    276             public void tagsChanged(TagsChangedEvent event) {}
    277 
    278             @Override
    279             public void nodeMoved(NodeMovedEvent event) {}
    280 
    281             @Override
    282             public void wayNodesChanged(WayNodesChangedEvent event) {
    283                 updateWaySegments();
    284             }
    285 
    286             @Override
    287             public void relationMembersChanged(RelationMembersChangedEvent event) {}
    288 
    289             @Override
    290             public void otherDatasetChange(AbstractDatasetChangedEvent event) {}
    291 
    292             @Override
    293             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 
    311238        }
    312239    }
Note: See TracChangeset for help on using the changeset viewer.