Skip to content

Commit

Permalink
change toolbar tooltip when Action accelerator key is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmipt committed Jan 12, 2024
1 parent ec33587 commit 1942bcc
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/studio/ui/Toolbar.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
};
}
}

0 comments on commit 1942bcc

Please sign in to comment.