|
111 | 111 |
|
112 | 112 | public class SwingTaskMonitorComponent { |
113 | 113 |
|
114 | | - private final JProgressBar globalProgressBar; // progress bar showing the global progression ( = progression of all tasks ). Clicking it toggles taskFrame visibility |
| 114 | + /** |
| 115 | + * Progress bar showing the global progression ( = progression of all tasks ). |
| 116 | + * Clicking it toggles taskFrame visibility. |
| 117 | + */ |
| 118 | + private final JProgressBar globalProgressBar; |
115 | 119 | private final int sizeGlobalProgressBar; |
116 | 120 |
|
117 | | - private final JFrame taskFrame; // a container for the taskTable, visibility toggled by clickable globalProgressBar |
118 | | - private final JTable taskTable; // JTable rendering each monitored task, contained in the taskFrame |
119 | | - private final TaskTableModel taskTableModel; // model of the taskTable |
| 121 | + /** |
| 122 | + * A container for the {@link #taskTable}, visibility toggled by clickable |
| 123 | + * {@link #globalProgressBar}. |
| 124 | + */ |
| 125 | + private final JFrame taskFrame; |
| 126 | + |
| 127 | + /** |
| 128 | + * {@link JTable} rendering each monitored task, contained in the |
| 129 | + * {@link #taskFrame}. |
| 130 | + */ |
| 131 | + private final JTable taskTable; |
| 132 | + |
| 133 | + /** Model of the {@link #taskTable}. */ |
| 134 | + private final TaskTableModel taskTableModel; |
120 | 135 |
|
121 | | - private final Boolean estimateTimeLeft; // flags whether each task should be timed |
122 | | - private Boolean confirmBeforeCancel; // flags whether the user should confirm when a task is clicked to be canceled. not final because this behaviour can be changed |
| 136 | + /** Flags whether each task should be timed. */ |
| 137 | + private final Boolean estimateTimeLeft; |
123 | 138 |
|
124 | | - private double globalProgression = 0; // store temporarily the current global progression - all tasks have an equal weight |
| 139 | + /** |
| 140 | + * Flags whether the user should confirm when a task is clicked to be |
| 141 | + * canceled. not final because this behaviour can be changed. |
| 142 | + */ |
| 143 | + private Boolean confirmBeforeCancel; |
125 | 144 |
|
126 | 145 | /** |
127 | | - * Construct a Swing Task Monitor component - clickable circular progress bar |
128 | | - * the component can be accessed with {@link SwingTaskMonitorComponent#getComponent()} |
| 146 | + * Stores temporarily the current global progression - all tasks have an equal |
| 147 | + * weight. |
| 148 | + */ |
| 149 | + private double globalProgression = 0; |
| 150 | + |
| 151 | + /** |
| 152 | + * Constructs a Swing Task Monitor component - clickable circular progress bar |
| 153 | + * the component can be accessed with |
| 154 | + * {@link SwingTaskMonitorComponent#getComponent()}. |
129 | 155 | * |
130 | | - * @param context scijava context |
131 | | - * @param estimateTimeLeft whether registered tasks should display an estimated remaining time |
132 | | - * @param confirmBeforeCancel flags whether a confirmation window should popup when cancelling a task, can be overridden with {@link SwingTaskMonitorComponent#disableCancelConfirmation()} and {@link SwingTaskMonitorComponent#enableCancelConfirmation()} |
| 156 | + * @param context SciJava context |
| 157 | + * @param estimateTimeLeft whether registered tasks should display an |
| 158 | + * estimated remaining time |
| 159 | + * @param confirmBeforeCancel flags whether a confirmation window should pop up |
| 160 | + * when canceling a task, can be overridden with |
| 161 | + * {@link SwingTaskMonitorComponent#disableCancelConfirmation()} and |
| 162 | + * {@link SwingTaskMonitorComponent#enableCancelConfirmation()} |
133 | 163 | * @param size of the circular progress bar (preferred size) |
134 | 164 | * @param undecorated defines whether taskFrame is undecorated or not |
135 | 165 | */ |
@@ -182,7 +212,8 @@ public void mouseClicked(MouseEvent e) { |
182 | 212 | taskTable.setRowHeight(65); |
183 | 213 | taskTable.setRowMargin(2); |
184 | 214 | taskTable.setDefaultRenderer(Task.class, new TaskRenderer(false)); |
185 | | - taskTable.getColumnModel().getColumn(1).setMaxWidth(30); // restrict size of second column to the size of the stop icon |
| 215 | + // restrict size of second column to the size of the stop icon |
| 216 | + taskTable.getColumnModel().getColumn(1).setMaxWidth(30); |
186 | 217 |
|
187 | 218 | // Scroll pane containing the JTable -> necessary when many tasks are displayed |
188 | 219 | JScrollPane scrollPane = new JScrollPane(taskTable); |
@@ -233,38 +264,51 @@ private void onEvent(final TaskEvent evt) { |
233 | 264 | } else { |
234 | 265 | taskTableModel.addOrUpdate(task); |
235 | 266 | } |
236 | | - globalProgressBar.setValue((int)(globalProgression*100)); // globalProgression has been updated during taskTableModel update |
| 267 | + // globalProgression has been updated during taskTableModel update |
| 268 | + globalProgressBar.setValue((int)(globalProgression*100)); |
237 | 269 | } |
238 | 270 |
|
239 | 271 | /** |
240 | | - * User confirmation required when cancelling a task by clicking the task table |
| 272 | + * User confirmation required when canceling a task by clicking the task table. |
241 | 273 | */ |
242 | 274 | public void enableCancelConfirmation() { |
243 | 275 | this.confirmBeforeCancel = true; |
244 | 276 | } |
245 | 277 |
|
246 | 278 | /** |
247 | | - * NO user confirmation required when cancelling a task by clicking the task table |
| 279 | + * NO user confirmation required when canceling a task by clicking the task table. |
248 | 280 | */ |
249 | 281 | public void disableCancelConfirmation() { |
250 | 282 | this.confirmBeforeCancel = false; |
251 | 283 | } |
252 | 284 |
|
253 | | - /* |
254 | | - * Task Table Model, serves to update the table according to the events received. Note |
255 | | - * that nothing is synchronized because every call is expected to happen from the |
256 | | - * event dispatch thread. It is thus single threaded, no race condition expected. |
| 285 | + /** |
| 286 | + * Task Table Model, serves to update the table according to the events |
| 287 | + * received. Note that nothing is synchronized because every call is expected |
| 288 | + * to happen from the event dispatch thread. It is thus single threaded, no |
| 289 | + * race condition expected. |
257 | 290 | */ |
258 | 291 | class TaskTableModel extends AbstractTableModel { |
259 | 292 |
|
260 | 293 | TaskTableModel() { |
261 | 294 | super(); |
262 | 295 | } |
263 | 296 |
|
264 | | - private List<Task> monitoredTasks = new ArrayList<>(); // indexed tasks |
265 | | - private Set<Task> tasksSet = new HashSet<>(); // unordered tasks -> faster task lookup (may be overkill) |
266 | | - private Map<Task,Double> previousCompletion = new HashMap<>(); // store the previous completion state of a certain task, before it was updated |
267 | | - private Map<Task, Instant> startTime = new HashMap<>(); // Start time -> stores when a task was added to this table model |
| 297 | + /** Indexed tasks. */ |
| 298 | + private List<Task> monitoredTasks = new ArrayList<>(); |
| 299 | + |
| 300 | + /** Unordered tasks → faster task lookup (may be overkill). */ |
| 301 | + private Set<Task> tasksSet = new HashSet<>(); |
| 302 | + |
| 303 | + /** |
| 304 | + * Store the previous completion state of a certain task, before it was |
| 305 | + * updated. |
| 306 | + */ |
| 307 | + private Map<Task,Double> previousCompletion = new HashMap<>(); |
| 308 | + |
| 309 | + /** Start time -> stores when a task was added to this table model. */ |
| 310 | + private Map<Task, Instant> startTime = new HashMap<>(); |
| 311 | + |
268 | 312 | int totalTasks = 0; |
269 | 313 | double totalProgression = 0; |
270 | 314 |
|
@@ -384,7 +428,7 @@ public Task getTask(int rowIndex) { |
384 | 428 | } |
385 | 429 |
|
386 | 430 | /* |
387 | | - * // From https://java-swing-tips.blogspot.com/2014/06/how-to-create-circular-progress.html |
| 431 | + * From https://java-swing-tips.blogspot.com/2014/06/how-to-create-circular-progress.html |
388 | 432 | * UI for circular progress bar |
389 | 433 | */ |
390 | 434 | static class ProgressCircleUI extends BasicProgressBarUI { |
@@ -437,7 +481,7 @@ class TaskRenderer implements TableCellRenderer { |
437 | 481 | JLabel labelTop = new JLabel(); // top label : task name and status |
438 | 482 | JProgressBar progressBar = new JProgressBar(); // standard linear progress bar |
439 | 483 | JLabel labelBottom = new JLabel(); // bottom label : task completion, and optionally time left |
440 | | - Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon"); // icon for cancelling task |
| 484 | + Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon"); // icon for canceling task |
441 | 485 | JLabel cancelTask; // container for errorIcon |
442 | 486 |
|
443 | 487 | public TaskRenderer(boolean isBordered) { |
|
0 commit comments