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