source: josm/trunk/src/org/openstreetmap/josm/gui/progress/ProgressMonitor.java@ 12259

Last change on this file since 12259 was 12259, checked in by bastiK, 7 years ago

see #14794 - javadoc

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.progress;
3
4import java.awt.Component;
5
6/**
7 * An interface for displaying the progress of a task.
8 * <p>
9 * Typical use case is:
10 * <pre>
11 * monitor.beginTask()
12 * try {
13 * .. do some work
14 * monitor.worked()
15 * monitor.subTask()/monitor.intermediateTask()
16 * .. do some work
17 * monitor.worked()
18 * } finally {
19 * monitor.finishTask();
20 * }
21 * </pre>
22 *
23 * {@link #subTask(String)} and {@link #indeterminateSubTask(String)} has nothing to do with logical
24 * structure of the work, they just show task title to the user.
25 * <p>
26 * If task consists of multiple tasks then {@link #createSubTaskMonitor(int, boolean)} may be used. It
27 * will create new ProgressMonitor, then can be passed to the subtask. Subtask doesn't know whether
28 * it runs standalone or as a part of other task. Progressbar will be updated so that total progress is
29 * shown, not just progress of the subtask
30 * <p>
31 * All ProgressMonitor implementations should be thread safe.
32 *
33 */
34public interface ProgressMonitor {
35
36 @FunctionalInterface
37 interface CancelListener {
38 void operationCanceled();
39 }
40
41 /** Ticks count used, when no other value is supplied */
42 int DEFAULT_TICKS = 10_000;
43
44 /**
45 * Can be used with {@link #worked(int)} and {@link #createSubTaskMonitor(int, boolean)} to
46 * express that the task should use all remaining ticks
47 */
48 int ALL_TICKS = -1;
49
50 /**
51 * Starts this progress monitor. Must be called exactly once
52 * Ticks count is set to default value
53 * @param title title text of the task
54 */
55 void beginTask(String title);
56
57 /**
58 * Starts this progress monitor. Must be called exactly once
59 * @param title title text of the task
60 * @param ticks number of work units (see {@link #setTicksCount(int ticks)})
61 */
62 void beginTask(String title, int ticks);
63
64 /**
65 * Finish this progress monitor, close the dialog or inform the parent progress monitor
66 * that it can continue with other tasks. Must be called at least once (if called multiply times
67 * then further calls are ignored)
68 */
69 void finishTask();
70
71 /**
72 * Can be used if method receive ProgressMonitor but it's not interested progress monitoring.
73 * Basically replaces {@link #beginTask(String)} and {@link #finishTask()}
74 *
75 * This method can be also used in finally section if method expects that some exception
76 * might prevent it from passing progressMonitor away. If {@link #beginTask(String)} was
77 * already called then this method does nothing.
78 */
79 void invalidate();
80
81 /**
82 * Set the total number of work units
83 * @param ticks Number of total work units
84 */
85 void setTicksCount(int ticks);
86
87 /**
88 * Get the total number of work units
89 * @return Number of total work units
90 */
91 int getTicksCount();
92
93 /**
94 * Set the current number of work units
95 * @param ticks Number of work units already done
96 */
97 void setTicks(int ticks);
98
99 /**
100 * Get the current number of work units
101 * @return Number of work units already done
102 */
103 int getTicks();
104
105 /**
106 * Increase number of already done work units by ticks
107 * @param ticks number of ticks to add
108 */
109 void worked(int ticks);
110
111 /**
112 * Subtask that will show progress running back and forth
113 * @param title Can be {@code null}, in that case task title is not changed
114 */
115 void indeterminateSubTask(String title);
116
117 /**
118 * Normal subtask
119 * @param title Can be {@code null}, in that case task title is not changed
120 */
121 void subTask(String title);
122
123 /**
124 * Shows additional text
125 * @param text custom text
126 */
127 void setCustomText(String text);
128
129 /**
130 * Show extra text after normal task title. Hack for ProgressInputStream to show number of kB already downloaded
131 * @param text extra text
132 */
133 void setExtraText(String text);
134
135 /**
136 * Creates subtasks monitor.
137 * @param ticks Number of work units that should be done when subtask finishes
138 * @param internal If true then subtask can't modify task title/custom text
139 * @return subtasks monitor
140 */
141 ProgressMonitor createSubTaskMonitor(int ticks, boolean internal);
142
143 /**
144 * Returns the state of user aborts
145 * @return {@code true} if user aborted operation
146 */
147 boolean isCanceled();
148
149 /**
150 * Abort current operation, usually called when user somehow requested an abort
151 */
152 void cancel();
153
154 /**
155 * Add listener for user abort action
156 * @param listener the listener for cancel operation
157 */
158 void addCancelListener(CancelListener listener);
159
160 /**
161 * Remove listener for user abort action
162 * @param listener the listener for cancel operation
163 */
164 void removeCancelListener(CancelListener listener);
165
166 /**
167 * Appends a message to the log managed by the progress monitor.
168 *
169 * @param message the log message. Ignored if null or white space only.
170 */
171 void appendLogMessage(String message);
172
173 /**
174 * Set the task ID of the progress dialog
175 * Should be used only by PleaseWaitRunnable. If taskId {@code <> null} then "In background" button will be shown
176 * @param taskId the task ID
177 */
178 void setProgressTaskId(ProgressTaskId taskId);
179
180 /**
181 * Returns the task ID of the progress dialog
182 * Should be used only by PleaseWaitRunnable
183 * @return the task ID
184 */
185 ProgressTaskId getProgressTaskId();
186
187 /**
188 * Return the parent windows of progress dialog
189 * @return component suitable as parent for dialogs that wants to be shown in front of progress dialog
190 */
191 Component getWindowParent();
192}
Note: See TracBrowser for help on using the repository browser.