mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 14:57:15 +08:00
Merge branch 'GP-1-dragonmacher-task-dialog-no-chomp' into Ghidra_9.2
This commit is contained in:
@@ -26,13 +26,25 @@ import docking.DialogComponentProvider;
|
|||||||
import docking.DockingWindowManager;
|
import docking.DockingWindowManager;
|
||||||
import docking.tool.ToolConstants;
|
import docking.tool.ToolConstants;
|
||||||
import docking.widgets.OptionDialog;
|
import docking.widgets.OptionDialog;
|
||||||
import ghidra.util.*;
|
import ghidra.util.HelpLocation;
|
||||||
|
import ghidra.util.Swing;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
import ghidra.util.timer.GTimer;
|
import ghidra.util.timer.GTimer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialog that is displayed to show activity for a Task that is running outside of the
|
* Dialog that is displayed to show activity for a Task that is running outside of the
|
||||||
* Swing Thread.
|
* 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 {
|
public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
||||||
|
|
||||||
@@ -50,6 +62,8 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
private Component centerOnComp;
|
private Component centerOnComp;
|
||||||
private Runnable shouldCancelRunnable;
|
private Runnable shouldCancelRunnable;
|
||||||
private boolean taskDone;
|
private boolean taskDone;
|
||||||
|
private boolean supportsProgress;
|
||||||
|
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private JPanel activityPanel;
|
private JPanel activityPanel;
|
||||||
private TaskMonitorComponent monitorComponent;
|
private TaskMonitorComponent monitorComponent;
|
||||||
@@ -107,10 +121,11 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
boolean hasProgress) {
|
boolean hasProgress) {
|
||||||
super(title, isModal, true, canCancel, true);
|
super(title, isModal, true, canCancel, true);
|
||||||
this.centerOnComp = centerOnComp;
|
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);
|
monitorComponent = new TaskMonitorComponent(false, false);
|
||||||
activityPanel = new ChompingBitsAnimationPanel();
|
activityPanel = new ChompingBitsAnimationPanel();
|
||||||
|
|
||||||
@@ -135,7 +150,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
mainPanel = new JPanel(new BorderLayout());
|
mainPanel = new JPanel(new BorderLayout());
|
||||||
addWorkPanel(mainPanel);
|
addWorkPanel(mainPanel);
|
||||||
|
|
||||||
if (hasProgress) {
|
if (supportsProgress) {
|
||||||
installProgressMonitor();
|
installProgressMonitor();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -165,7 +180,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
* Adds the panel that contains the progress bar to the dialog
|
* Adds the panel that contains the progress bar to the dialog
|
||||||
*/
|
*/
|
||||||
private void installProgressMonitor() {
|
private void installProgressMonitor() {
|
||||||
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
|
Swing.runIfSwingOrRunLater(() -> {
|
||||||
mainPanel.removeAll();
|
mainPanel.removeAll();
|
||||||
mainPanel.add(monitorComponent, BorderLayout.CENTER);
|
mainPanel.add(monitorComponent, BorderLayout.CENTER);
|
||||||
repack();
|
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.
|
* dialog. This should only be called if the dialog has no need to display progress.
|
||||||
*/
|
*/
|
||||||
private void installActivityDisplay() {
|
private void installActivityDisplay() {
|
||||||
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
|
Swing.runIfSwingOrRunLater(() -> {
|
||||||
mainPanel.removeAll();
|
mainPanel.removeAll();
|
||||||
mainPanel.add(activityPanel, BorderLayout.CENTER);
|
mainPanel.add(activityPanel, BorderLayout.CENTER);
|
||||||
repack();
|
repack();
|
||||||
@@ -273,7 +288,7 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doShow() {
|
protected void doShow() {
|
||||||
SystemUtilities.runIfSwingOrPostSwingLater(() -> {
|
Swing.runIfSwingOrRunLater(() -> {
|
||||||
DockingWindowManager.showDialog(centerOnComp, TaskDialog.this);
|
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
|
@Override
|
||||||
public void initialize(long max) {
|
public void initialize(long max) {
|
||||||
if (monitorComponent.isIndeterminate()) {
|
|
||||||
// don't show the progress bar if we have already been marked as indeterminate (this
|
if (!supportsProgress) {
|
||||||
// allows us to prevent low-level algorithms from changing the display settings).
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +370,8 @@ public class TaskDialog extends DialogComponentProvider implements TaskMonitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setIndeterminate(final boolean indeterminate) {
|
public void setIndeterminate(boolean indeterminate) {
|
||||||
|
supportsProgress = !indeterminate;
|
||||||
monitorComponent.setIndeterminate(indeterminate);
|
monitorComponent.setIndeterminate(indeterminate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ public abstract class Task implements MonitoredRunnable {
|
|||||||
private boolean canCancel;
|
private boolean canCancel;
|
||||||
private boolean hasProgress;
|
private boolean hasProgress;
|
||||||
private boolean isModal;
|
private boolean isModal;
|
||||||
private boolean isInterruptible;
|
|
||||||
private boolean isForgettable;
|
|
||||||
protected boolean waitForTaskCompleted = false;
|
protected boolean waitForTaskCompleted = false;
|
||||||
private Set<TaskListener> listeners = new HashSet<>();
|
private Set<TaskListener> listeners = new HashSet<>();
|
||||||
protected TaskMonitor taskMonitor = TaskMonitor.DUMMY;
|
protected TaskMonitor taskMonitor = TaskMonitor.DUMMY;
|
||||||
@@ -164,10 +162,10 @@ public abstract class Task implements MonitoredRunnable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (waitForTaskCompleted) {
|
if (waitForTaskCompleted) {
|
||||||
SystemUtilities.runSwingNow(r);
|
Swing.runNow(r);
|
||||||
}
|
}
|
||||||
else {
|
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
|
* <P>Note: The run(TaskMonitor) method should not make any calls directly
|
||||||
* on Swing components, as these calls are not thread safe. Place Swing
|
* on Swing components, as these calls are not thread safe. Place Swing
|
||||||
* calls in a Runnable, then call {@link SystemUtilities#runSwingLater(Runnable)} or
|
* calls in a Runnable, then call {@link Swing#runLater(Runnable)} or
|
||||||
* {@link SystemUtilities#runSwingNow(Runnable)}to schedule the Runnable inside of
|
* {@link Swing#runNow(Runnable)}to schedule the Runnable inside of
|
||||||
* the AWT Event Thread.
|
* the AWT Event Thread.
|
||||||
*
|
*
|
||||||
* @param monitor The TaskMonitor that will monitor the executing Task
|
* @param monitor The TaskMonitor that will monitor the executing Task
|
||||||
|
|||||||
Reference in New Issue
Block a user