From 079de08aead67037ba00d1b5612ac9a0240166df Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 22 Jun 2011 04:59:28 +0200 Subject: Show panel when a player disappears during a game git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@575 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/WinPanel.java | 99 ++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 30 deletions(-) (limited to 'src/jrummikub/view/impl/WinPanel.java') diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java index 4d9aacc..888cf75 100644 --- a/src/jrummikub/view/impl/WinPanel.java +++ b/src/jrummikub/view/impl/WinPanel.java @@ -28,6 +28,8 @@ class WinPanel extends JPanel { private final static float MAX_BUTTON_FONT_SIZE = 12; private JLabel waitingLabel; + private JLabel connectionLostLabel; + private JButton newRoundButton; private JButton newGameButton; private JButton endProgramButton; @@ -50,6 +52,12 @@ class WinPanel extends JPanel { waitingLabel.setVerticalAlignment(JLabel.CENTER); add(waitingLabel); + connectionLostLabel = new JLabel( + "Die Verbindung zu einem Spieler ist abgebrochen."); + connectionLostLabel.setHorizontalAlignment(JLabel.CENTER); + connectionLostLabel.setVerticalAlignment(JLabel.CENTER); + add(connectionLostLabel); + newRoundButton = new JButton("Neue Runde"); newRoundButton.addActionListener(new ActionListener() { @Override @@ -117,44 +125,26 @@ class WinPanel extends JPanel { width = width / 2 + PANEL_MAX_WIDTH / 2; } - int buttonWidth; - int buttonHeight; - int buttonY; if (type == BottomPanelType.WIN_PANEL) { - buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3; - buttonHeight = height; - buttonY = y; - } else { - buttonWidth = (width - PANEL_SEPARATOR) / 2; - buttonHeight = height * 2 / 3 - PANEL_SEPARATOR; - buttonY = y + height - buttonHeight; + rescaleWinPanel(x, y, width, height); + } else if (type == BottomPanelType.NETWORK_WIN_PANEL) { + rescaleNetworkWinPanel(x, y, width, height); + } else if (type == BottomPanelType.NETWORK_CONNECTION_LOST_PANEL) { + rescaleNetworkConnectionLostPanel(x, y, width, height); } - int labelHeight = height - buttonHeight - PANEL_SEPARATOR; + } + + private void rescaleWinPanel(int x, int y, int width, int height) { + int buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3; + int buttonHeight = height; + int buttonY = y; float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; if (fontSize > MAX_BUTTON_FONT_SIZE) fontSize = MAX_BUTTON_FONT_SIZE; - if (type == BottomPanelType.WIN_PANEL) { - rescaleWinPanel(x, buttonWidth, buttonHeight, buttonY, fontSize); - } else if (type == BottomPanelType.NETWORK_WIN_PANEL) { - waitingLabel.setBounds(x, y, width, labelHeight); - waitingLabel.setVisible(true); - - newRoundButton.setVisible(false); - - newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight); - newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); - - endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, - buttonWidth, buttonHeight); - endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); - } - } - - private void rescaleWinPanel(int x, int buttonWidth, int buttonHeight, - int buttonY, float fontSize) { waitingLabel.setVisible(false); + connectionLostLabel.setVisible(false); newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight); newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); newRoundButton.setVisible(true); @@ -168,6 +158,55 @@ class WinPanel extends JPanel { endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); } + private void rescaleNetworkWinPanel(int x, int y, int width, int height) { + int buttonWidth = (width - PANEL_SEPARATOR) / 2; + int buttonHeight = height * 2 / 3 - PANEL_SEPARATOR; + int buttonY = y + height - buttonHeight; + int labelHeight = height - buttonHeight - PANEL_SEPARATOR; + + float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; + if (fontSize > MAX_BUTTON_FONT_SIZE) + fontSize = MAX_BUTTON_FONT_SIZE; + + waitingLabel.setBounds(x, y, width, labelHeight); + waitingLabel.setVisible(true); + connectionLostLabel.setVisible(false); + + newRoundButton.setVisible(false); + + newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight); + newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); + + endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, + buttonWidth, buttonHeight); + endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); + } + + private void rescaleNetworkConnectionLostPanel(int x, int y, int width, + int height) { + int buttonWidth = (width - PANEL_SEPARATOR) / 2; + int buttonHeight = height * 2 / 3 - PANEL_SEPARATOR; + int buttonY = y + height - buttonHeight; + int labelHeight = height - buttonHeight - PANEL_SEPARATOR; + + float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5; + if (fontSize > MAX_BUTTON_FONT_SIZE) + fontSize = MAX_BUTTON_FONT_SIZE; + + waitingLabel.setVisible(false); + connectionLostLabel.setBounds(x, y, width, labelHeight); + connectionLostLabel.setVisible(true); + + newRoundButton.setVisible(false); + + newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight); + newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); + + endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, + buttonWidth, buttonHeight); + endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize)); + } + void setType(BottomPanelType type) { this.type = type; rescale(); -- cgit v1.2.3