From 86eeace6738c4715857df6730dff41e788918b43 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 22 Jun 2011 05:58:15 +0200 Subject: Renamed WinPanel to RoundEndPanel git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@578 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/RoundEndPanel.java | 218 +++++++++++++++++++++++++++++ src/jrummikub/view/impl/View.java | 20 +-- src/jrummikub/view/impl/WinPanel.java | 218 ----------------------------- 3 files changed, 228 insertions(+), 228 deletions(-) create mode 100644 src/jrummikub/view/impl/RoundEndPanel.java delete mode 100644 src/jrummikub/view/impl/WinPanel.java diff --git a/src/jrummikub/view/impl/RoundEndPanel.java b/src/jrummikub/view/impl/RoundEndPanel.java new file mode 100644 index 0000000..20951e9 --- /dev/null +++ b/src/jrummikub/view/impl/RoundEndPanel.java @@ -0,0 +1,218 @@ +package jrummikub.view.impl; + +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +import jrummikub.util.Event; +import jrummikub.util.IEvent; +import jrummikub.view.IView.BottomPanelType; + +/** + * A panel that is displayed when a player has won + */ +@SuppressWarnings("serial") +class RoundEndPanel extends JPanel { + private final static int PANEL_INSET = 15; + private final static int PANEL_SEPARATOR = 10; + @SuppressWarnings("unused") + private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f; + private final static int PANEL_MAX_WIDTH = 180; + private final static float MAX_BUTTON_FONT_SIZE = 12; + + private JLabel waitingLabel; + private JLabel connectionLostLabel; + + private JButton newRoundButton; + private JButton newGameButton; + private JButton endProgramButton; + + private Event endProgramEvent = new Event(); + private Event newGameEvent = new Event(); + private Event newRoundEvent = new Event(); + private BottomPanelType type; + + /** + * Creates a new WinPanel + */ + RoundEndPanel() { + setLayout(null); + setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET, + PANEL_INSET)); + + waitingLabel = new JLabel("Warte auf Host..."); + waitingLabel.setHorizontalAlignment(JLabel.CENTER); + 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); + + createButtons(); + } + + private void createButtons() { + newRoundButton = new JButton("Neue Runde"); + newRoundButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + newRoundEvent.emit(); + } + }); + add(newRoundButton); + + newGameButton = new JButton("Neues Spiel"); + newGameButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + newGameEvent.emit(); + } + }); + add(newGameButton); + + endProgramButton = new JButton("Programm verlassen"); + endProgramButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + endProgramEvent.emit(); + } + }); + add(endProgramButton); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + rescale(); + } + }); + } + + /** + * The new round event is emitted when the player wants to start a new round + * + * @return the event + */ + IEvent getNewRoundEvent() { + return newRoundEvent; + } + + IEvent getNewGameEvent() { + return newGameEvent; + } + + /** + * The end program is emitted when the player wants to quit the program + * + * @return the event + */ + IEvent getEndProgramEvent() { + return endProgramEvent; + } + + private void rescale() { + Insets insets = getInsets(); + int x = insets.left, y = insets.top, width = getWidth() - insets.left + - insets.right, height = getHeight() - insets.top - insets.bottom; + + if (width > PANEL_MAX_WIDTH) { + x += (width - PANEL_MAX_WIDTH) / 4; + width = width / 2 + PANEL_MAX_WIDTH / 2; + } + + if (type == BottomPanelType.WIN_PANEL) { + 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); + } + } + + 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; + + waitingLabel.setVisible(false); + connectionLostLabel.setVisible(false); + newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight); + newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); + newRoundButton.setVisible(true); + + newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, + buttonWidth, buttonHeight); + newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); + + endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), + buttonY, buttonWidth, buttonHeight); + 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(); + } +} diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 962ecf0..34ae800 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -66,7 +66,7 @@ public class View extends JFrame implements IView { private PlayerPanel playerPanel; private StartTurnPanel startTurnPanel; private PausePanel pausePanel; - private WinPanel winPanel; + private RoundEndPanel roundEndPanel; private SettingsPanel settingsPanel; private LoginPanel loginPanel; private ScorePanel scorePanel; @@ -408,9 +408,9 @@ public class View extends JFrame implements IView { pausePanel.setVisible(false); mainLayer.add(pausePanel); - winPanel = new WinPanel(); - winPanel.setVisible(false); - mainLayer.add(winPanel); + roundEndPanel = new RoundEndPanel(); + roundEndPanel.setVisible(false); + mainLayer.add(roundEndPanel); sidePanel = new SidePanel(); sidePanel.setVisible(false); @@ -460,7 +460,7 @@ public class View extends JFrame implements IView { } startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight); pausePanel.setBounds(0, tableHeight, width, playerPanelHeight); - winPanel.setBounds(0, tableHeight, width, playerPanelHeight); + roundEndPanel.setBounds(0, tableHeight, width, playerPanelHeight); rescaleSubpanel(settingsPanel, 1 / 2.0, 1 / 2.0, 475, 300); rescaleSubpanel(scorePanel, 3 / 4.0, 1 / 2.0, 450, 300); @@ -606,17 +606,17 @@ public class View extends JFrame implements IView { @Override public IEvent getNewRoundEvent() { - return winPanel.getNewRoundEvent(); + return roundEndPanel.getNewRoundEvent(); } @Override public IEvent getNewGameEvent() { - return winPanel.getNewGameEvent(); + return roundEndPanel.getNewGameEvent(); } @Override public IEvent getEndProgramEvent() { - return winPanel.getEndProgramEvent(); + return roundEndPanel.getEndProgramEvent(); } @SuppressWarnings("unchecked") @@ -673,8 +673,8 @@ public class View extends JFrame implements IView { boolean showWinPanel = (type == BottomPanelType.WIN_PANEL || type == BottomPanelType.NETWORK_WIN_PANEL || type == BottomPanelType.NETWORK_CONNECTION_LOST_PANEL); - winPanel.setType(type); - winPanel.setVisible(showWinPanel); + roundEndPanel.setType(type); + roundEndPanel.setVisible(showWinPanel); playerPanel.setVisible((!showStartTurnPanel) && (!showWinPanel) && type != null); diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java deleted file mode 100644 index 21ea239..0000000 --- a/src/jrummikub/view/impl/WinPanel.java +++ /dev/null @@ -1,218 +0,0 @@ -package jrummikub.view.impl; - -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import jrummikub.util.Event; -import jrummikub.util.IEvent; -import jrummikub.view.IView.BottomPanelType; - -/** - * A panel that is displayed when a player has won - */ -@SuppressWarnings("serial") -class WinPanel extends JPanel { - private final static int PANEL_INSET = 15; - private final static int PANEL_SEPARATOR = 10; - @SuppressWarnings("unused") - private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f; - private final static int PANEL_MAX_WIDTH = 180; - private final static float MAX_BUTTON_FONT_SIZE = 12; - - private JLabel waitingLabel; - private JLabel connectionLostLabel; - - private JButton newRoundButton; - private JButton newGameButton; - private JButton endProgramButton; - - private Event endProgramEvent = new Event(); - private Event newGameEvent = new Event(); - private Event newRoundEvent = new Event(); - private BottomPanelType type; - - /** - * Creates a new WinPanel - */ - WinPanel() { - setLayout(null); - setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET, - PANEL_INSET)); - - waitingLabel = new JLabel("Warte auf Host..."); - waitingLabel.setHorizontalAlignment(JLabel.CENTER); - 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); - - createButtons(); - } - - private void createButtons() { - newRoundButton = new JButton("Neue Runde"); - newRoundButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - newRoundEvent.emit(); - } - }); - add(newRoundButton); - - newGameButton = new JButton("Neues Spiel"); - newGameButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - newGameEvent.emit(); - } - }); - add(newGameButton); - - endProgramButton = new JButton("Programm verlassen"); - endProgramButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - endProgramEvent.emit(); - } - }); - add(endProgramButton); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - rescale(); - } - }); - } - - /** - * The new round event is emitted when the player wants to start a new round - * - * @return the event - */ - IEvent getNewRoundEvent() { - return newRoundEvent; - } - - IEvent getNewGameEvent() { - return newGameEvent; - } - - /** - * The end program is emitted when the player wants to quit the program - * - * @return the event - */ - IEvent getEndProgramEvent() { - return endProgramEvent; - } - - private void rescale() { - Insets insets = getInsets(); - int x = insets.left, y = insets.top, width = getWidth() - insets.left - - insets.right, height = getHeight() - insets.top - insets.bottom; - - if (width > PANEL_MAX_WIDTH) { - x += (width - PANEL_MAX_WIDTH) / 4; - width = width / 2 + PANEL_MAX_WIDTH / 2; - } - - if (type == BottomPanelType.WIN_PANEL) { - 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); - } - } - - 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; - - waitingLabel.setVisible(false); - connectionLostLabel.setVisible(false); - newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight); - newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize)); - newRoundButton.setVisible(true); - - newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY, - buttonWidth, buttonHeight); - newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize)); - - endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), - buttonY, buttonWidth, buttonHeight); - 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