From 1942bcc991d44a38477d97a398cbeba92c9b2c2d Mon Sep 17 00:00:00 2001 From: dzmipt Date: Fri, 12 Jan 2024 19:20:37 +0100 Subject: [PATCH] change toolbar tooltip when Action accelerator key is changed --- src/studio/ui/Toolbar.java | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/studio/ui/Toolbar.java b/src/studio/ui/Toolbar.java index 2d006722..faa143d0 100644 --- a/src/studio/ui/Toolbar.java +++ b/src/studio/ui/Toolbar.java @@ -1,20 +1,44 @@ package studio.ui; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import javax.swing.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; public class Toolbar extends JToolBar { + private static final Logger log = LogManager.getLogger(); + @Override public JButton add(Action a) { JButton btn = super.add(a); + updateTooltipTest(btn); + + return btn; + } + + private void updateTooltipTest(JButton btn) { + Action a = btn.getAction(); + String tooltip = (String)a.getValue(Action.SHORT_DESCRIPTION); KeyStroke accelerator = (KeyStroke) a.getValue(Action.ACCELERATOR_KEY); - if (accelerator == null) { - return btn; + if (accelerator != null) { + tooltip = Util.getTooltipWithAccelerator(tooltip, accelerator); } - - String tooltip = Util.getTooltipWithAccelerator((String)a.getValue(Action.SHORT_DESCRIPTION), accelerator); btn.setToolTipText(tooltip); - return btn; + } + + @Override + protected PropertyChangeListener createActionChangeListener(JButton b) { + return new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == Action.ACCELERATOR_KEY) { + updateTooltipTest(b); + } + } + }; } }