Merge branch 'GP-1-dragonmacher-task-dialog-no-chomp' into Ghidra_9.2

This commit is contained in:
dragonmacher
2020-09-30 16:16:53 -04:00
2 changed files with 31 additions and 18 deletions
@@ -26,13 +26,25 @@ import docking.DialogComponentProvider;
import docking.DockingWindowManager;
import docking.tool.ToolConstants;
import docking.widgets.OptionDialog;
import ghidra.util.*;
import ghidra.util.HelpLocation;
import ghidra.util.Swing;
import ghidra.util.exception.CancelledException;
import ghidra.util.timer.GTimer;
/**
* Dialog that is displayed to show activity for a Task that is running outside of the
* Swing Thread.
*
* <p>Implementation note:
* if this class is constructed with a {@code hasProgrees} value of {@code false},
* then an activity component will be shown, not a progress monitor. Any calls to update
* progress will not affect the display. However, the display can be converted to use progress
* by first calling {@link #setIndeterminate(boolean)} with a {@code false} value and then calling
* {@link #initialize(long)}. Once this has happened, this dialog will no longer use the
* activity display--the progress bar is in effect for the duration of this dialog's usage.
*
* <p>This dialog can be toggled between indeterminate mode and progress mode via calls to
* {@link #setIndeterminate(boolean)}.
*/
public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
@@ -50,6 +62,8 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
private Component centerOnComp;
private Runnable shouldCancelRunnable;
private boolean taskDone;
private boolean supportsProgress;
private JPanel mainPanel;
private JPanel activityPanel;
private TaskMonitorComponent monitorComponent;
@@ -107,10 +121,11 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
boolean hasProgress) {
super(title, isModal, true, canCancel, true);
this.centerOnComp = centerOnComp;
setup(canCancel, hasProgress);
this.supportsProgress = hasProgress;
setup(canCancel);
}
private void setup(boolean canCancel, boolean hasProgress) {
private void setup(boolean canCancel) {
monitorComponent = new TaskMonitorComponent(false, false);
activityPanel = new ChompingBitsAnimationPanel();
@@ -135,7 +150,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
mainPanel = new JPanel(new BorderLayout());
addWorkPanel(mainPanel);
if (hasProgress) {
if (supportsProgress) {
installProgressMonitor();
}
else {
@@ -165,7 +180,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
* Adds the panel that contains the progress bar to the dialog
*/
private void installProgressMonitor() {
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
Swing.runIfSwingOrRunLater(() -> {
mainPanel.removeAll();
mainPanel.add(monitorComponent, BorderLayout.CENTER);
repack();
@@ -177,7 +192,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
* dialog. This should only be called if the dialog has no need to display progress.
*/
private void installActivityDisplay() {
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
Swing.runIfSwingOrRunLater(() -> {
mainPanel.removeAll();
mainPanel.add(activityPanel, BorderLayout.CENTER);
repack();
@@ -273,7 +288,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
}
protected void doShow() {
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
Swing.runIfSwingOrRunLater(() -> {
DockingWindowManager.showDialog(centerOnComp, TaskDialog.this);
});
}
@@ -302,7 +317,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
}
};
SystemUtilities.runSwingNow(disposeTask);
Swing.runNow(disposeTask);
}
//==================================================================================================
@@ -332,9 +347,8 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
@Override
public void initialize(long max) {
if (monitorComponent.isIndeterminate()) {
// don't show the progress bar if we have already been marked as indeterminate (this
// allows us to prevent low-level algorithms from changing the display settings).
if (!supportsProgress) {
return;
}
@@ -356,7 +370,8 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
}
@Override
public void setIndeterminate(final boolean indeterminate) {
public void setIndeterminate(boolean indeterminate) {
supportsProgress = !indeterminate;
monitorComponent.setIndeterminate(indeterminate);
}
@@ -31,8 +31,6 @@ public abstract class Task implements MonitoredRunnable {
private boolean canCancel;
private boolean hasProgress;
private boolean isModal;
private boolean isInterruptible;
private boolean isForgettable;
protected boolean waitForTaskCompleted = false;
private Set<TaskListener> listeners = new HashSet<>();
protected TaskMonitor taskMonitor = TaskMonitor.DUMMY;
@@ -164,10 +162,10 @@ public abstract class Task implements MonitoredRunnable {
};
if (waitForTaskCompleted) {
SystemUtilities.runSwingNow(r);
Swing.runNow(r);
}
else {
SystemUtilities.runSwingLater(r);
Swing.runLater(r);
}
}
@@ -176,8 +174,8 @@ public abstract class Task implements MonitoredRunnable {
*
* <P>Note: The run(TaskMonitor) method should not make any calls directly
* on Swing components, as these calls are not thread safe. Place Swing
* calls in a Runnable, then call {@link SystemUtilities#runSwingLater(Runnable)} or
* {@link SystemUtilities#runSwingNow(Runnable)}to schedule the Runnable inside of
* calls in a Runnable, then call {@link Swing#runLater(Runnable)} or
* {@link Swing#runNow(Runnable)}to schedule the Runnable inside of
* the AWT Event Thread.
*
* @param monitor The TaskMonitor that will monitor the executing Task