Use small font sizes for small buttons :D

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@57 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-02 01:08:44 +02:00
parent c241d98ed9
commit ebd0707133
2 changed files with 27 additions and 10 deletions

View file

@ -25,6 +25,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private final static int SIDE_PANEL_SEPARATOR = 10;
private final static float SIDE_PANEL_FIRST_LINE_HEIGHT = 0.375f;
private final static int SIDE_PANEL_MAX_WIDTH = 180;
private final static float MAX_BUTTON_FONT_SIZE = 12;
private final static DecimalFormat secondFormat = new DecimalFormat("00");
@ -88,7 +89,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
leftPanel.add(currentPlayerNameLabel);
sortByNumberButton = new JButton("<html><center>Sort by<br>number");
sortByNumberButton = new JButton("<html><center>Sort by number");
sortByNumberButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
@ -97,7 +98,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
});
leftPanel.add(sortByNumberButton);
sortByColorButton = new JButton("<html><center>Sort by<br>color");
sortByColorButton = new JButton("<html><center>Sort by color");
sortByColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
@ -121,14 +122,23 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
int buttonWidth = (width - SIDE_PANEL_SEPARATOR) / 2;
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE;
currentPlayerNameLabel.setBounds(x, y, width, firstLineHeight);
sortByNumberButton.setBounds(x, y + firstLineHeight
+ SIDE_PANEL_SEPARATOR, buttonWidth, height - SIDE_PANEL_SEPARATOR
- firstLineHeight);
sortByColorButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, height
- SIDE_PANEL_SEPARATOR - firstLineHeight);
+ SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
sortByColorButton
.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth,
buttonHeight);
sortByNumberButton.setFont(sortByNumberButton.getFont().deriveFont(
fontSize));
sortByColorButton.setFont(sortByColorButton.getFont().deriveFont(
fontSize));
}
});
}
@ -168,10 +178,17 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
int firstLineHeight = (int) ((height - SIDE_PANEL_SEPARATOR) * SIDE_PANEL_FIRST_LINE_HEIGHT);
int buttonWidth = width;
int buttonHeight = height - SIDE_PANEL_SEPARATOR - firstLineHeight;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE;
timeBar.setBounds(x, y, width, firstLineHeight);
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
width, height - SIDE_PANEL_SEPARATOR - firstLineHeight);
buttonWidth, buttonHeight);
endTurnButton.setFont(endTurnButton.getFont().deriveFont(
fontSize));
}
});
}

View file

@ -38,7 +38,7 @@ public class View extends JFrame implements IView {
super("JRummikub");
setLayout(null);
setSize(1000, 700);
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
table = new Table();