From 9ad7f0822eb66972f740fb3da58c85d7a555d549 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 16 May 2011 20:49:11 +0200 Subject: Add hand row controls to view git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@241 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/PlayerPanel.java | 63 +++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 9 deletions(-) (limited to 'src/jrummikub/view/impl/PlayerPanel.java') diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index ce8b8ec..20fb05a 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -28,6 +28,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 HAND_ROW_BUTTON_RATIO = 0.03f; private final static float MAX_BUTTON_FONT_SIZE = 12; private final static DecimalFormat secondFormat = new DecimalFormat("00"); @@ -39,6 +40,8 @@ class PlayerPanel extends JPanel implements IPlayerPanel { private JLabel currentPlayerNameLabel; private JButton sortByGroupsButton; private JButton sortByRunsButton; + private JButton handRowUpButton; + private JButton handRowDownButton; private JProgressBar timeBar; private JButton endTurnButton; @@ -132,6 +135,26 @@ class PlayerPanel extends JPanel implements IPlayerPanel { rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET, SIDE_PANEL_INSET)); + handRowUpButton = new JButton("
\u25B2"); + handRowUpButton.setMargin(new Insets(0, 0, 0, 0)); + handRowUpButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + hand.rowUp(); + } + }); + rightPanel.add(handRowUpButton); + + handRowDownButton = new JButton("
\u25BC"); + handRowDownButton.setMargin(new Insets(0, 0, 0, 0)); + handRowDownButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + hand.rowDown(); + } + }); + rightPanel.add(handRowDownButton); + timeBar = new JProgressBar(0, 60); timeBar.setStringPainted(true); rightPanel.add(timeBar); @@ -141,7 +164,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { endTurnButton.setMargin(new Insets(0, 0, 0, 0)); endTurnButton.addActionListener(new ActionListener() { @Override - public void actionPerformed(ActionEvent arg0) { + public void actionPerformed(ActionEvent e) { endTurnEvent.emit(); } }); @@ -156,16 +179,28 @@ class PlayerPanel extends JPanel implements IPlayerPanel { int x = insets.left, y = insets.top, width = getWidth() - insets.left - insets.right, height = getHeight() - insets.top - insets.bottom; int boardWidth = hand.getWidth(); - int panelWidth = (width - boardWidth) / 2; + int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO); + int meanPanelWidth = (width - boardWidth) / 2; + int leftPanelWidth = meanPanelWidth - handButtonWidth / 2; + int rightPanelWidth = meanPanelWidth + handButtonWidth / 2; - leftPanel.setBounds(x, y, panelWidth, height); - hand.setBounds(x + panelWidth, y, boardWidth, height); - rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height); + leftPanel.setBounds(x, y, leftPanelWidth, height); + hand.setBounds(x + leftPanelWidth, y, boardWidth, height); + rightPanel.setBounds(x + leftPanelWidth + boardWidth, y, rightPanelWidth, + height); leftPanel.validate(); rightPanel.validate(); } + void updateButtons() { + handRowUpButton.setEnabled(hand.canRowUp()); + handRowUpButton.setForeground(hand.canRowUp() ? Color.BLACK : Color.GRAY); + handRowDownButton.setEnabled(hand.canRowDown()); + handRowDownButton.setForeground(hand.canRowDown() ? Color.BLACK + : Color.GRAY); + } + /** * Creates a new PlayerPanel instance */ @@ -175,7 +210,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { createLeftPanel(); add(leftPanel); - hand = new HandPanel(); + hand = new HandPanel(this); add(hand); createRightPanel(); @@ -227,10 +262,12 @@ class PlayerPanel extends JPanel implements IPlayerPanel { private class RightPanelResizeListener extends ComponentAdapter { @Override public void componentResized(ComponentEvent e) { + int handButtonWidth = (int) (getWidth() * HAND_ROW_BUTTON_RATIO); + Insets insets = rightPanel.getInsets(); - int x = insets.left, y = insets.top, width = rightPanel.getWidth() - - insets.left - insets.right, height = rightPanel.getHeight() - - insets.top - insets.bottom; + int x = insets.left + handButtonWidth, y = insets.top, width = rightPanel + .getWidth() - insets.left - insets.right - handButtonWidth, height = rightPanel + .getHeight() - insets.top - insets.bottom; if (width > SIDE_PANEL_MAX_WIDTH) { x += (width - SIDE_PANEL_MAX_WIDTH) / 4; @@ -244,6 +281,14 @@ class PlayerPanel extends JPanel implements IPlayerPanel { if (fontSize > MAX_BUTTON_FONT_SIZE) fontSize = MAX_BUTTON_FONT_SIZE; + handRowUpButton.setBounds(0, 0, handButtonWidth, getHeight() / 2); + handRowUpButton.setFont(handRowUpButton.getFont().deriveFont( + fontSize * 1.5f)); + handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth, + getHeight() / 2); + handRowDownButton.setFont(handRowDownButton.getFont().deriveFont( + fontSize * 1.5f)); + timeBar.setBounds(x, y, width, firstLineHeight); endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); -- cgit v1.2.3