Make keybound buttons cache their text, in case the keys are changed midgame

This commit is contained in:
Campbell Suter 2016-10-20 12:49:58 +13:00
parent b4dc47fbc9
commit cde9afa091
No known key found for this signature in database
GPG key ID: 754A66CCF3F73C0F

View file

@ -12,11 +12,11 @@ import mage.client.dialog.PreferencesDialog;
*/
public class KeyboundButton extends JButton {
private final String key;
private final String text;
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
public KeyboundButton(String key) {
this.key = key;
text = PreferencesDialog.getCachedKeyText(key);
}
@Override
@ -28,7 +28,6 @@ public class KeyboundButton extends JButton {
sg.setColor(Color.white);
sg.setFont(keyFont);
String text = PreferencesDialog.getCachedKeyText(key);
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
int centerX = (getWidth() - textWidth) / 2;