From afa28a5f997f1353988bfba2c223eadea9737340 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sat, 7 Nov 2020 11:57:24 -0500 Subject: Return the bound action for SimpleKeyedButton In case anyone wants it, SimpleKeyedButton now returns the created action when it is set --- base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'base/src/main') diff --git a/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java b/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java index 0c40fbe..976b259 100644 --- a/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java +++ b/base/src/main/java/bjc/utils/gui/SimpleKeyedButton.java @@ -59,8 +59,9 @@ public class SimpleKeyedButton extends JButton { * @param aevListener * The listener that handles the implementation of the * action. + * @return The action that was bound to the button. */ - public void setGlobalDefaultKeystroke(String eventName, String keystroke, + public Action setGlobalDefaultKeystroke(String eventName, String keystroke, Consumer aevListener) { Action act = new KeyedButtonAction(eventName, aevListener); KeyStroke stroke = KeyStroke.getKeyStroke(keystroke); @@ -69,6 +70,8 @@ public class SimpleKeyedButton extends JButton { this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(stroke, eventName); this.getActionMap().put(eventName, act); this.setText(label); + + return act; } /** @@ -82,8 +85,9 @@ public class SimpleKeyedButton extends JButton { * @param aevListener * The listener that handles the implementation of the * action. + * @return The action that was bound to the button. */ - public void addGlobalKeystroke(String eventName, String keystroke, + public Action addGlobalKeystroke(String eventName, String keystroke, Consumer aevListener) { Action act = new KeyedButtonAction(eventName, aevListener); KeyStroke stroke = KeyStroke.getKeyStroke(keystroke); @@ -91,5 +95,7 @@ public class SimpleKeyedButton extends JButton { this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(stroke, eventName); this.getActionMap().put(eventName, act); this.setText(label); + + return act; } } -- cgit v1.2.3