From 8bc28b02d90efb379cf4e804c2ba8ef2d7f0f794 Mon Sep 17 00:00:00 2001 From: dev747368 <48332326+dev747368@users.noreply.github.com> Date: Fri, 30 Jun 2023 11:05:23 -0400 Subject: [PATCH] GP-3597 add methods to combine calling increment and checkCancelled, etc Add methods to combine calling increment+checkCancelled andinitialize+setMessage --- .../java/ghidra/util/task/TaskMonitor.java | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/task/TaskMonitor.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/task/TaskMonitor.java index af895e3872..75d947e38b 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/task/TaskMonitor.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/task/TaskMonitor.java @@ -88,6 +88,17 @@ public interface TaskMonitor { */ public void initialize(long max); + /** + * Initializes the progress value to 0, sets the max value and message of this monitor. + * + * @param max maximum value for progress + * @param message the message to display + */ + default public void initialize(long max, String message) { + initialize(max); + setMessage(message); + } + /** * Set the progress maximum value *
@@ -133,11 +144,41 @@ public interface TaskMonitor { } /** - * A convenience method to increment the current progress by the given value + * Increases the progress value by 1. + */ + default public void incrementProgress() { + incrementProgress(1); + } + + /** + * Changes the progress value by the specified amount. + * * @param incrementAmount The amount by which to increment the progress */ public void incrementProgress(long incrementAmount); + /** + * Increases the progress value by 1, and checks if this monitor has been cancelled. + * + * @throws CancelledException if monitor has been cancelled + */ + default public void increment() throws CancelledException { + checkCancelled(); + incrementProgress(1); + } + + /** + * Changes the progress value by the specified amount, and checks if this monitor has + * been cancelled. + * + * @param incrementAmount The amount by which to increment the progress + * @throws CancelledException if monitor has been cancelled + */ + default public void increment(long incrementAmount) throws CancelledException { + checkCancelled(); + incrementProgress(incrementAmount); + } + /** * Returns the current progress value or {@link #NO_PROGRESS_VALUE} if there is no value set * @return the current progress value or {@link #NO_PROGRESS_VALUE} if there is no value set