|
18 | 18 | import java.util.TreeSet; |
19 | 19 | import java.util.concurrent.ForkJoinPool; |
20 | 20 | import java.util.concurrent.ForkJoinTask; |
| 21 | +import java.util.concurrent.atomic.AtomicBoolean; |
21 | 22 | import java.util.stream.Collectors; |
22 | 23 |
|
23 | 24 | import org.openstreetmap.josm.data.Bounds; |
@@ -213,37 +214,26 @@ private static void mergeDataSets(final DataSet original, final List<ForkJoinTas |
213 | 214 | } |
214 | 215 | } |
215 | 216 |
|
216 | | - private static boolean confirmBigDownload(List<Bounds> realBounds) { |
217 | | - final var confirmation = new ConfirmBigDownload(realBounds); |
218 | | - GuiHelper.runInEDTAndWait(confirmation); |
219 | | - return confirmation.confirmed(); |
220 | | - } |
221 | | - |
222 | | - private static class ConfirmBigDownload implements Runnable { |
223 | | - Boolean bool; |
224 | | - final List<?> realBounds; |
225 | | - |
226 | | - public ConfirmBigDownload(List<?> realBounds) { |
227 | | - this.realBounds = realBounds; |
228 | | - } |
229 | | - |
230 | | - @Override |
231 | | - public void run() { |
232 | | - bool = ConditionalOptionPaneUtil.showConfirmationDialog(MapWithAIPlugin.NAME.concat(".alwaysdownload"), |
233 | | - null, |
| 217 | + /** |
| 218 | + * Confirm a large download |
| 219 | + * |
| 220 | + * @param realBounds The list of bounds that will be downloaded |
| 221 | + * @return {@code true} if the user still wants to download data |
| 222 | + */ |
| 223 | + private static synchronized boolean confirmBigDownload(List<Bounds> realBounds) { |
| 224 | + final var confirmation = new AtomicBoolean(false); |
| 225 | + // This is not a separate class since we don't want to show multiple |
| 226 | + // confirmation dialogs |
| 227 | + // which is why this method is synchronized. |
| 228 | + GuiHelper.runInEDTAndWait(() -> { |
| 229 | + final var confirmed = ConditionalOptionPaneUtil.showConfirmationDialog( |
| 230 | + MapWithAIPlugin.NAME.concat(".alwaysdownload"), null, |
234 | 231 | tr("You are going to make {0} requests to the MapWithAI server. This may take some time. <br /> Continue?", |
235 | 232 | realBounds.size()), |
236 | 233 | null, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, JOptionPane.YES_OPTION); |
237 | | - } |
238 | | - |
239 | | - /** |
240 | | - * Check if the user confirmed the download |
241 | | - * |
242 | | - * @return {@code true} if the user wants to continue |
243 | | - */ |
244 | | - public boolean confirmed() { |
245 | | - return bool; |
246 | | - } |
| 234 | + confirmation.set(confirmed); |
| 235 | + }); |
| 236 | + return confirmation.get(); |
247 | 237 | } |
248 | 238 |
|
249 | 239 | /** |
|
0 commit comments