source: josm/trunk/src/org/openstreetmap/josm/gui/progress/CancelHandler.java@ 12540

Last change on this file since 12540 was 12369, checked in by michael2402, 7 years ago

Javadoc for gui.progress package

  • Property svn:eol-style set to native
File size: 1.4 KB
RevLine 
[1811]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.progress;
3
4import java.util.ArrayList;
5import java.util.List;
6
7import org.openstreetmap.josm.gui.progress.ProgressMonitor.CancelListener;
8
[12369]9/**
10 * A handler that notifies all listeners that a given operation was canceled.
11 */
[1811]12public class CancelHandler {
13
14 private boolean isCanceled;
[9078]15 private final List<CancelListener> listeners = new ArrayList<>();
[1811]16
[12369]17 /**
18 * Cancels the operation. This call is ignored if the operation was already canceled.
19 */
[1811]20 public synchronized void cancel() {
21 if (!isCanceled) {
22 isCanceled = true;
23 for (CancelListener listener:listeners) {
24 listener.operationCanceled();
25 }
26 }
27 }
28
[12369]29 /**
30 * Checks if the operation was canceled
31 * @return <code>true</code> if {@link #cancel()} was called.
32 */
[1811]33 public synchronized boolean isCanceled() {
34 return isCanceled;
35 }
36
[12369]37 /**
38 * Adds a new cancel listener
39 * @param listener The listener to add
40 */
[1811]41 public synchronized void addCancelListener(CancelListener listener) {
42 listeners.add(listener);
43 }
44
[12369]45 /**
46 * Removes a cancel listener
47 * @param listener The listener to remove
48 */
[1811]49 public synchronized void removeCancelListener(CancelListener listener) {
50 listeners.remove(listener);
51 }
52
53}
Note: See TracBrowser for help on using the repository browser.