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