source: josm/trunk/src/org/openstreetmap/josm/gui/io/AbstractIOTask.java@ 3083

Last change on this file since 3083 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4/**
5 * This is an abstract task for uploading or saving a data layer.
6 *
7 */
8public abstract class AbstractIOTask implements Runnable {
9
10 /** indicates whether the task has been cancelled */
11 private boolean cancelled;
12 /** indicates whether the task has been failed */
13 private boolean failed;
14 /** the last exception caught */
15 private Exception lastException;
16
17 public AbstractIOTask() {
18 cancelled = false;
19 failed = false;
20 lastException = null;
21 }
22
23 /**
24 * Replies true if the task has been cancelled
25 *
26 * @return true if the task has been cancelled
27 */
28 public boolean isCancelled() {
29 return cancelled;
30 }
31
32 /**
33 * Set whether this task has been cancelled
34 *
35 * @param cancelled true, if the task has been cancelled; false otherwise
36 */
37 protected void setCancelled(boolean cancelled) {
38 this.cancelled = cancelled;
39 }
40
41 /**
42 * Replies true if the task has been failed
43 *
44 * @return true if the task has been failed
45 */
46 public boolean isFailed() {
47 return failed || lastException != null;
48 }
49
50 /**
51 * Sets whether the task has been failed
52 *
53 * @param failed whether the task has been failed
54 */
55 protected void setFailed(boolean failed) {
56 this.failed = failed;
57 }
58
59 /**
60 * Replies the last exception caught
61 *
62 * @return the last exception caught; null, if no exception was caught
63 */
64 public Exception getLastException() {
65 return lastException;
66 }
67
68 /**
69 * Sets the last exception caught
70 *
71 * @param lastException the last exception
72 */
73 protected void setLastException(Exception lastException) {
74 this.lastException = lastException;
75 }
76
77 /**
78 * Replies true if this task was successful, i.e. if it wasn't
79 * cancelled and didn't fail
80 *
81 * @return true if this task was successful
82 */
83 public boolean isSuccessful() {
84 return !isCancelled() && !isFailed();
85 }
86
87 /**
88 * Runs the task
89 */
90 public abstract void run();
91
92 /**
93 * Cancel the task
94 */
95 public abstract void cancel();
96}
Note: See TracBrowser for help on using the repository browser.