From: Jim Procter Date: Tue, 3 Jul 2018 16:26:30 +0000 (+0100) Subject: JAL-3048 allow a default response handler to be set X-Git-Tag: Release_2_11_4_0~45^2~18^2~595^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cc4e5d87263a27efb6cf3b94f56ae5680270cf45;p=jalview.git JAL-3048 allow a default response handler to be set --- 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; + } }