Make the text on the playing buttons update with the current keybinds

This commit is contained in:
Campbell Suter 2016-10-19 09:44:20 +13:00
parent d9ebceec20
commit 5ea636126f
No known key found for this signature in database
GPG key ID: 754A66CCF3F73C0F
9 changed files with 61 additions and 14 deletions

View file

@ -0,0 +1,46 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.components;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JButton;
import mage.client.dialog.PreferencesDialog;
/**
*
* @author Campbell Suter <znix@znix.xyz>
*/
public class KeyboundButton extends JButton {
private final String key;
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
public KeyboundButton(String key) {
this.key = key;
}
@Override
protected void paintComponent(Graphics g) {
if (ui != null && g != null) {
Graphics sg = g.create();
try {
ui.update(sg, this);
sg.setColor(Color.white);
sg.setFont(keyFont);
String text = PreferencesDialog.getCachedKeyText(key);
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
int centerX = (getWidth() - textWidth) / 2;
sg.drawString(text, centerX, 28);
} finally {
sg.dispose();
}
}
}
}