From cc4e5d87263a27efb6cf3b94f56ae5680270cf45 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Tue, 3 Jul 2018 17:26:30 +0100 Subject: [PATCH] JAL-3048 allow a default response handler to be set --- src/jalview/util/dialogrunner/DialogRunner.java | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/jalview/util/dialogrunner/DialogRunner.java b/src/jalview/util/dialogrunner/DialogRunner.java index fc99b2d..9f23832 100644 --- a/src/jalview/util/dialogrunner/DialogRunner.java +++ b/src/jalview/util/dialogrunner/DialogRunner.java @@ -62,6 +62,10 @@ public class DialogRunner implements DialogRunnerI } } responses.clear(); + if (defaultResponse != null) + { + defaultResponse.reset(); + } firstRunWasCalled = false; } @@ -193,6 +197,12 @@ public class DialogRunner implements DialogRunnerI if (laction == null) { + if (defaultResponse != null) + { + defaultResponse.ourTrigger = response; + defaultResponse.wasRun = true; + defaultResponse.run(); + } System.err.println("Doing nothing for " + response); return; } @@ -224,4 +234,33 @@ public class DialogRunner implements DialogRunnerI List responses = new ArrayList<>(); + RunResponse defaultResponse = null; + + /** + * Convenience wrapper for setting default response to a runnable + * + * @param runnable + */ + public void setDefaultResponse(Runnable runnable) + { + defaultResponse = new RunResponse(runnable) + { + @Override + public void run() + { + runnable.run(); + } + }; + } + + /** + * Default responses are called once, with ourTrigger set to the unHandled + * response received + * + * @param runnable + */ + public void setDefaultResponse(RunResponse runnable) + { + defaultResponse = runnable; + } } -- 1.7.10.2