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

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

Javadoc for gui.progress package

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