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

Last change on this file since 11713 was 11713, checked in by Don-vip, 7 years ago

add Ant target to run PMD (only few rules for now), fix violations

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