Skip to content

Commit beb0b23

Browse files
committed
SwingTaskMonitorComponent: fix Eclipse warnings
1 parent 0f87f2f commit beb0b23

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

src/main/java/org/scijava/ui/swing/task/SwingTaskMonitorComponent.java

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void addOrUpdate(Task task) {
335335
previousCompletion.put(task,currentProgression);
336336
totalProgression+=currentProgression;
337337
}
338-
globalProgression = totalProgression/(double) totalTasks;
338+
globalProgression = totalProgression / totalTasks;
339339
}
340340

341341
void removeTask(Task task) {
@@ -351,7 +351,7 @@ void removeTask(Task task) {
351351
if(totalTasks==0) {
352352
globalProgression = 0;
353353
} else {
354-
globalProgression = totalProgression/(double)totalTasks;
354+
globalProgression = totalProgression / totalTasks;
355355
}
356356
if (estimateTimeLeft) startTime.remove(task);
357357
}
@@ -361,18 +361,18 @@ String getEstimateTimeMessage(Task task) {
361361
if (tasksSet.contains(task)) {
362362
if (task.getProgressMaximum() == 0) {
363363
return "? remaining";
364-
} else {
365-
Instant now = Instant.now();
366-
Duration elapsedTime = Duration.between(startTime.get(task), now);
367-
double completion = previousCompletion.get(task);
368-
if (completion==0) return "? remaining";
369-
double elapsedTimeInS = elapsedTime.getSeconds();
370-
double totalTimeInS = elapsedTime.getSeconds()*1.0/completion;
371-
double remainingTimeInS = totalTimeInS-elapsedTimeInS;
372-
Duration duration = Duration.ofSeconds((long)remainingTimeInS);
373-
return humanReadableFormat(duration)+" remaining";
374364
}
375-
} else return "";
365+
Instant now = Instant.now();
366+
Duration elapsedTime = Duration.between(startTime.get(task), now);
367+
double completion = previousCompletion.get(task);
368+
if (completion==0) return "? remaining";
369+
double elapsedTimeInS = elapsedTime.getSeconds();
370+
double totalTimeInS = elapsedTime.getSeconds()*1.0/completion;
371+
double remainingTimeInS = totalTimeInS-elapsedTimeInS;
372+
Duration duration = Duration.ofSeconds((long)remainingTimeInS);
373+
return humanReadableFormat(duration)+" remaining";
374+
}
375+
return "";
376376
}
377377

378378
@Override
@@ -423,7 +423,8 @@ public Object getValueAt(int rowIndex, int columnIndex) {
423423
public Task getTask(int rowIndex) {
424424
if (rowIndex<monitoredTasks.size()) {
425425
return monitoredTasks.get(rowIndex);
426-
} else return null;
426+
}
427+
return null;
427428
}
428429
}
429430

@@ -495,38 +496,38 @@ public TaskRenderer(boolean isBordered) {
495496
cell.add(labelTop,"height ::14, span");
496497
cell.add(progressBar,"height ::3, span");
497498
cell.add(labelBottom, "height ::14");
498-
cancelTask = new JLabel(errorIcon, JLabel.CENTER);
499+
cancelTask = new JLabel(errorIcon, SwingConstants.CENTER);
499500
cancelTask.setOpaque(true);
500501
cancelTask.setBackground(cell.getBackground());
501502
}
502503

504+
@Override
503505
public Component getTableCellRendererComponent(
504506
JTable table, Object tk,
505507
boolean isSelected, boolean hasFocus,
506508
int row, int column) {
507509
if (column==1) {
508510
return cancelTask; // second column : stop icon
511+
}
512+
// first column : task information
513+
Task task = (Task) tk;
514+
String status = task.getStatusMessage();
515+
labelTop.setText(task.getName() + " " + ((status != null) ? status : ""));
516+
if (estimateTimeLeft) {
517+
labelBottom.setText(format(task.getProgressValue()) + "/" + format(task.getProgressMaximum()) + " - " + taskTableModel.getEstimateTimeMessage(task));
509518
} else {
510-
// first column : task information
511-
Task task = (Task) tk;
512-
String status = task.getStatusMessage();
513-
labelTop.setText(task.getName() + " " + ((status != null) ? status : ""));
514-
if (estimateTimeLeft) {
515-
labelBottom.setText(format(task.getProgressValue()) + "/" + format(task.getProgressMaximum()) + " - " + taskTableModel.getEstimateTimeMessage(task));
516-
} else {
517-
labelBottom.setText(format(task.getProgressValue()) + "/" + format(task.getProgressMaximum()));
518-
}
519-
if (task.getProgressMaximum() == 0) {
520-
progressBar.setMaximum(100);
521-
progressBar.setValue(50);
522-
} else {
523-
int progress = (int) ((100 * task.getProgressValue()) / task.getProgressMaximum());
524-
progressBar.setMaximum(100);
525-
progressBar.setValue(progress);
526-
}
527-
cell.setToolTipText(task.getStatusMessage()); // tool tip text = current task status
528-
return cell;
519+
labelBottom.setText(format(task.getProgressValue()) + "/" + format(task.getProgressMaximum()));
520+
}
521+
if (task.getProgressMaximum() == 0) {
522+
progressBar.setMaximum(100);
523+
progressBar.setValue(50);
524+
} else {
525+
int progress = (int) ((100 * task.getProgressValue()) / task.getProgressMaximum());
526+
progressBar.setMaximum(100);
527+
progressBar.setValue(progress);
529528
}
529+
cell.setToolTipText(task.getStatusMessage()); // tool tip text = current task status
530+
return cell;
530531
}
531532

532533
}

0 commit comments

Comments
 (0)