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 | public final int DEFAULT_TICKS = 10000;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Can be used with {@link #worked(int)} and {@link #createSubTaskMonitor(int, boolean)} to
|
---|
42 | * express that the task should use all remaining ticks
|
---|
43 | */
|
---|
44 | public final int ALL_TICKS = -1;
|
---|
45 |
|
---|
46 | void beginTask(String title);
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Starts this progress monitor. Must be called exactly once
|
---|
50 | * @param title
|
---|
51 | * @param ticks
|
---|
52 | */
|
---|
53 | void beginTask(String title, int ticks);
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Finish this progress monitor, close the dialog or inform the parent progress monitor
|
---|
57 | * that it can continue with other tasks. Must be called at least once (if called multiply times
|
---|
58 | * then further calls are ignored)
|
---|
59 | */
|
---|
60 |
|
---|
61 | void finishTask();
|
---|
62 | /**
|
---|
63 | * Can be used if method receive ProgressMonitor but it's not interested progress monitoring.
|
---|
64 | * Basically replaces {@link #beginTask(String)} and {@link #finishTask()}
|
---|
65 | *
|
---|
66 | * This method can be also used in finally section if method expects that some exception
|
---|
67 | * might prevent it from passing progressMonitor away. If {@link #beginTask(String)} was
|
---|
68 | * already called then this method does nothing.
|
---|
69 | */
|
---|
70 | void invalidate();
|
---|
71 |
|
---|
72 | /**
|
---|
73 | *
|
---|
74 | * @param ticks Number of total work units
|
---|
75 | */
|
---|
76 | void setTicksCount(int ticks);
|
---|
77 | /**
|
---|
78 | *
|
---|
79 | * @param ticks Number of work units already done
|
---|
80 | */
|
---|
81 | void setTicks(int ticks);
|
---|
82 |
|
---|
83 | int getTicks();
|
---|
84 | int getTicksCount();
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Increase number of already done work units by ticks
|
---|
88 | * @param ticks
|
---|
89 | */
|
---|
90 | void worked(int ticks);
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Subtask that will show progress running back and forth
|
---|
94 | * @param title Can be null, in that case task title is not changed
|
---|
95 | */
|
---|
96 | void indeterminateSubTask(String title);
|
---|
97 | /**
|
---|
98 | * Normal subtask
|
---|
99 | * @param title Can be null, in that case task title is not changed
|
---|
100 | */
|
---|
101 | void subTask(String title);
|
---|
102 | /**
|
---|
103 | * Shows additional text
|
---|
104 | */
|
---|
105 | void setCustomText(String text);
|
---|
106 | /**
|
---|
107 | * Show extra text after normal task title. Hack for ProgressInputStream to show number of kB
|
---|
108 | * already downloaded
|
---|
109 | * @param text
|
---|
110 | */
|
---|
111 | void setExtraText(String text);
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Creates subtasks monitor.
|
---|
115 | * @param ticks Number of work units that should be done when subtask finishes
|
---|
116 | * @param internal If true then subtask can't modify task title/custom text
|
---|
117 | */
|
---|
118 | ProgressMonitor createSubTaskMonitor(int ticks, boolean internal);
|
---|
119 |
|
---|
120 | boolean isCanceled();
|
---|
121 | void cancel();
|
---|
122 | void addCancelListener(CancelListener listener);
|
---|
123 | void removeCancelListener(CancelListener listener);
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Appends a message to the log managed by the progress monitor.
|
---|
127 | *
|
---|
128 | * @param message the log message. Ignored if null or white space only.
|
---|
129 | */
|
---|
130 | void appendLogMessage(String message);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Should be used only by PleaseWaitRunnable. If taskId <> null then "In background" button will be shown
|
---|
134 | * @param taskId
|
---|
135 | */
|
---|
136 | void setProgressTaskId(ProgressTaskId taskId);
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Should be used only by PleaseWaitRunnable
|
---|
140 | * @param taskId
|
---|
141 | */
|
---|
142 | ProgressTaskId getProgressTaskId();
|
---|
143 |
|
---|
144 | /**
|
---|
145 | *
|
---|
146 | * @return component suitable as parent for dialogs that wants to be shown in front of progress dialog
|
---|
147 | */
|
---|
148 | Component getWindowParent();
|
---|
149 | }
|
---|