Ticket #19199: 19199.threading.patch

File 19199.threading.patch, 1.8 KB (added by taylor.smock, 5 years ago)

Add threading

  • src/org/openstreetmap/josm/actions/SimplifyWayAction.java

     
    4646import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    4747import org.openstreetmap.josm.gui.MainApplication;
    4848import org.openstreetmap.josm.gui.Notification;
     49import org.openstreetmap.josm.gui.util.GuiHelper;
    4950import org.openstreetmap.josm.spi.preferences.Config;
    5051import org.openstreetmap.josm.spi.preferences.IPreferences;
    5152import org.openstreetmap.josm.tools.GBC;
     
    514515                UndoRedoHandler.getInstance().undo();
    515516            }
    516517            double threshold = errorModel.getNumber().doubleValue();
     518            MainApplication.worker.submit(() -> updateNodesToRemove(this.ways, threshold));
     519        }
     520
     521        private synchronized void updateNodesToRemove(List<Way> ways, double threshold) {
     522            if (lastCommand != null && lastCommand.equals(UndoRedoHandler.getInstance().getLastCommand())) {
     523                GuiHelper.runInEDTAndWait(() -> UndoRedoHandler.getInstance().undo());
     524            }
    517525            int removeNodes = simplifyWaysCountNodesRemoved(ways, threshold);
     526            GuiHelper.runInEDTAndWait(() -> {
    518527            nodesToRemove.setText(trn(
    519528                    "(about {0} node to remove)",
    520529                    "(about {0} nodes to remove)", removeNodes, removeNodes));
     530            });
    521531            lastCommand = SimplifyWayAction.buildSimplifyWaysCommand(ways, threshold);
    522532            if (lastCommand != null) {
    523                 UndoRedoHandler.getInstance().add(lastCommand);
     533                GuiHelper.runInEDTAndWait(() -> UndoRedoHandler.getInstance().add(lastCommand));
    524534            }
    525535        }
    526536    }