Package ghidra.util.task
Class TaskBuilder
- java.lang.Object
-
- ghidra.util.task.TaskBuilder
-
public class TaskBuilder extends java.lang.Object
A builder object that allows clients to launch tasks in the background, with a progress dialog representing the task.Using this class obviates the need for clients to create full class objects to implement the
Task
interface, which means less boiler-plate code.An example of usage:
MonitoredRunnable r = monitor -> doWork(parameter, monitor); new TaskBuilder("Task Title", r) .setHasProgress(true) .setCanCancel(true) .setStatusTextAlignment(SwingConstants.LEADING) .launchModal();
-
-
Constructor Summary
Constructors Constructor Description TaskBuilder(java.lang.String title, MonitoredRunnable runnable)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
launchModal()
Launches the task built by this builder, using a blocking modal dialog.TaskLauncher
launchNonModal()
Launches the task built by this builder, using a non-blocking dialog.TaskBuilder
setCanCancel(boolean canCancel)
Sets whether the task can be cancelled.TaskBuilder
setDialogWidth(int width)
The desired width of the dialog.TaskBuilder
setHasProgress(boolean hasProgress)
Sets whether this task reports progress.TaskBuilder
setLaunchDelay(int delay)
Sets the amount of time that will pass before showing the dialog.TaskBuilder
setParent(java.awt.Component parent)
Sets the component over which the task dialog will be shown.TaskBuilder
setStatusTextAlignment(int alignment)
Sets the horizontal text alignment of messages shown in the task dialog.
-
-
-
Constructor Detail
-
TaskBuilder
public TaskBuilder(java.lang.String title, MonitoredRunnable runnable)
Constructor.- Parameters:
title
- the required title for your task. This will appear as the title of the task dialogrunnable
- the runnable that will be called when the task is run
-
-
Method Detail
-
setHasProgress
public TaskBuilder setHasProgress(boolean hasProgress)
Sets whether this task reports progress. The default is true.- Parameters:
hasProgress
- true if the task reports progress- Returns:
- this builder
-
setCanCancel
public TaskBuilder setCanCancel(boolean canCancel)
Sets whether the task can be cancelled. The default is true.- Parameters:
canCancel
- true if the task can be cancelled.- Returns:
- this builder
-
setParent
public TaskBuilder setParent(java.awt.Component parent)
Sets the component over which the task dialog will be shown. The default is null, which shows the dialog over the active window.- Parameters:
parent
- the parent- Returns:
- this builder
-
setLaunchDelay
public TaskBuilder setLaunchDelay(int delay)
Sets the amount of time that will pass before showing the dialog. The default isTaskLauncher.INITIAL_DELAY
for non-modal tasks andTaskLauncher.INITIAL_MODAL_DELAY
for modal tasks.- Parameters:
delay
- the delay time- Returns:
- this builder
-
setDialogWidth
public TaskBuilder setDialogWidth(int width)
The desired width of the dialog. The default isTaskDialog.DEFAULT_WIDTH
.- Parameters:
width
- the width- Returns:
- this builder
-
setStatusTextAlignment
public TaskBuilder setStatusTextAlignment(int alignment)
Sets the horizontal text alignment of messages shown in the task dialog. The default isSwingConstants.CENTER
. Valid values areSwingConstants
LEADING, CENTER and TRAILING.- Parameters:
alignment
- the alignment- Returns:
- this builder
-
launchModal
public void launchModal()
Launches the task built by this builder, using a blocking modal dialog.
-
launchNonModal
public TaskLauncher launchNonModal()
Launches the task built by this builder, using a non-blocking dialog.- Returns:
- the launcher that launched the task
-
-