From ebd0707133d6c2023ee7e608b7661640f993e2f8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 2 May 2011 01:08:44 +0200 Subject: 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 --- src/jrummikub/view/impl/PlayerPanel.java | 35 ++++++++++++++++++++++++-------- src/jrummikub/view/impl/View.java | 2 +- 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index ef8b4f6..6bc3d09 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -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("
Sort by
number"); + sortByNumberButton = new JButton("
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("
Sort by
color"); + sortByColorButton = new JButton("
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)); } }); } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index a23e5e2..0eabd43 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -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(); -- cgit v1.2.3