summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/PlayerPanel.java
diff options
context:
space:
mode:
authorBennet Gerlach <bennet_gerlach@web.de>2011-05-04 15:40:34 +0200
committerBennet Gerlach <bennet_gerlach@web.de>2011-05-04 15:40:34 +0200
commite39a539ee38a1413aac9f09a556a9ca4a181bc39 (patch)
tree7dfaf1623cf6e8f620790f150f14a9c124ad9938 /src/jrummikub/view/impl/PlayerPanel.java
parenta0a32b4f2df05b973c3f235508ef52b510873e19 (diff)
downloadJRummikub-e39a539ee38a1413aac9f09a556a9ca4a181bc39.tar
JRummikub-e39a539ee38a1413aac9f09a556a9ca4a181bc39.zip
Added StartTurnPanel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@102 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/PlayerPanel.java')
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java432
1 files changed, 215 insertions, 217 deletions
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 10bd111..111ec1a 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -23,221 +23,219 @@ import jrummikub.view.IPlayerPanel;
*/
@SuppressWarnings("serial")
class PlayerPanel extends JPanel implements IPlayerPanel {
- private final static int SIDE_PANEL_INSET = 15;
- 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");
-
- private HandPanel hand;
-
- private JPanel leftPanel, rightPanel;
-
- private JLabel currentPlayerNameLabel;
- private JButton sortByGroupsButton;
- private JButton sortByRunsButton;
- private JProgressBar timeBar;
- private JButton endTurnButton;
-
- private Event sortByGroupsEvent = new Event();
- private Event sortByRunsEvent = new Event();
- private Event endTurnEvent = new Event();
-
- @Override
- public HandPanel getHandPanel() {
- return hand;
- }
-
- @Override
- public void setCurrentPlayerName(String playerName) {
- currentPlayerNameLabel.setText(playerName);
- }
-
- @Override
- public void setTimeLeft(int time) {
- timeBar.setValue(time);
- timeBar.setString(Integer.toString(time / 60) + ":"
- + secondFormat.format(time % 60));
- }
-
- @Override
- public IEvent getSortByGroupsEvent() {
- return sortByGroupsEvent;
- }
-
- @Override
- public IEvent getSortByRunsEvent() {
- return sortByRunsEvent;
- }
-
- @Override
- public IEvent getEndTurnEvent() {
- return endTurnEvent;
- }
-
- private void createLeftPanel() {
- leftPanel = new JPanel();
- leftPanel.setLayout(null);
- leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
- SIDE_PANEL_INSET, SIDE_PANEL_INSET));
-
- currentPlayerNameLabel = new JLabel();
- currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
- currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
- currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
- currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
- leftPanel.add(currentPlayerNameLabel);
-
- sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
- sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
- sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
- sortByGroupsButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- sortByGroupsEvent.emit();
- }
- });
- leftPanel.add(sortByGroupsButton);
-
- sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
- sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
- sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
- sortByRunsButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- sortByRunsEvent.emit();
- }
- });
- leftPanel.add(sortByRunsButton);
-
- leftPanel.addComponentListener(new LeftPanelResizeListener());
- }
-
- private void createRightPanel() {
- rightPanel = new JPanel();
- rightPanel.setLayout(null);
- rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
- SIDE_PANEL_INSET, SIDE_PANEL_INSET));
-
- timeBar = new JProgressBar(0, 60);
- timeBar.setStringPainted(true);
- rightPanel.add(timeBar);
-
- endTurnButton = new JButton("Zug beenden");
- endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
- endTurnButton.setMargin(new Insets(0, 0, 0, 0));
- endTurnButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- endTurnEvent.emit();
- }
- });
-
- rightPanel.add(endTurnButton);
-
- rightPanel.addComponentListener(new RightPanelResizeListener());
- }
-
- 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;
- int boardWidth = hand.getWidth();
- int panelWidth = (width - boardWidth) / 2;
-
- leftPanel.setBounds(x, y, panelWidth, height);
- hand.setBounds(x + panelWidth, y, boardWidth, height);
- rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
-
- leftPanel.validate();
- rightPanel.validate();
- }
-
- /**
- * Creates a new PlayerPanel instance
- */
- PlayerPanel() {
- setLayout(null);
-
- createLeftPanel();
- add(leftPanel);
-
- hand = new HandPanel();
- add(hand);
-
- createRightPanel();
- add(rightPanel);
-
- ComponentListener rescaleListener = new ComponentAdapter() {
- @Override
- public void componentResized(ComponentEvent e) {
- rescale();
- }
- };
-
- addComponentListener(rescaleListener);
- hand.addComponentListener(rescaleListener);
- }
-
- private class LeftPanelResizeListener extends ComponentAdapter {
- @Override
- public void componentResized(ComponentEvent e) {
- Insets insets = leftPanel.getInsets();
- int x = insets.left, y = insets.top, width = leftPanel.getWidth()
- - insets.left - insets.right, height = leftPanel.getHeight()
- - insets.top - insets.bottom;
-
- if (width > SIDE_PANEL_MAX_WIDTH) {
- x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
- width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
- }
-
- 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);
- sortByGroupsButton.setBounds(x, y + firstLineHeight
- + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
- sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
- + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
-
- sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
- fontSize));
- sortByRunsButton.setFont(sortByRunsButton.getFont()
- .deriveFont(fontSize));
- }
- }
-
- private class RightPanelResizeListener extends ComponentAdapter {
- @Override
- public void componentResized(ComponentEvent e) {
- 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;
-
- if (width > SIDE_PANEL_MAX_WIDTH) {
- x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
- width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
- }
-
- 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,
- buttonWidth, buttonHeight);
- endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
- }
- }
+ private final static int SIDE_PANEL_INSET = 15;
+ 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");
+
+ private HandPanel hand;
+
+ private JPanel leftPanel, rightPanel;
+
+ private JLabel currentPlayerNameLabel;
+ private JButton sortByGroupsButton;
+ private JButton sortByRunsButton;
+ private JProgressBar timeBar;
+ private JButton endTurnButton;
+
+ private Event sortByGroupsEvent = new Event();
+ private Event sortByRunsEvent = new Event();
+ private Event endTurnEvent = new Event();
+
+ @Override
+ public HandPanel getHandPanel() {
+ return hand;
+ }
+
+ void setCurrentPlayerName(String playerName) {
+ currentPlayerNameLabel.setText(playerName);
+ }
+
+ @Override
+ public void setTimeLeft(int time) {
+ timeBar.setValue(time);
+ timeBar.setString(Integer.toString(time / 60) + ":"
+ + secondFormat.format(time % 60));
+ }
+
+ @Override
+ public IEvent getSortByGroupsEvent() {
+ return sortByGroupsEvent;
+ }
+
+ @Override
+ public IEvent getSortByRunsEvent() {
+ return sortByRunsEvent;
+ }
+
+ @Override
+ public IEvent getEndTurnEvent() {
+ return endTurnEvent;
+ }
+
+ private void createLeftPanel() {
+ leftPanel = new JPanel();
+ leftPanel.setLayout(null);
+ leftPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
+ SIDE_PANEL_INSET, SIDE_PANEL_INSET));
+
+ currentPlayerNameLabel = new JLabel();
+ currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
+ currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
+ currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
+ currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
+ leftPanel.add(currentPlayerNameLabel);
+
+ sortByGroupsButton = new JButton("<html><center>Nach Gruppen sortieren");
+ sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(0));
+ sortByGroupsButton.setMargin(new Insets(0, 0, 0, 0));
+ sortByGroupsButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ sortByGroupsEvent.emit();
+ }
+ });
+ leftPanel.add(sortByGroupsButton);
+
+ sortByRunsButton = new JButton("<html><center>Nach Reihen sortieren");
+ sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(0));
+ sortByRunsButton.setMargin(new Insets(0, 0, 0, 0));
+ sortByRunsButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ sortByRunsEvent.emit();
+ }
+ });
+ leftPanel.add(sortByRunsButton);
+
+ leftPanel.addComponentListener(new LeftPanelResizeListener());
+ }
+
+ private void createRightPanel() {
+ rightPanel = new JPanel();
+ rightPanel.setLayout(null);
+ rightPanel.setBorder(new EmptyBorder(SIDE_PANEL_INSET, SIDE_PANEL_INSET,
+ SIDE_PANEL_INSET, SIDE_PANEL_INSET));
+
+ timeBar = new JProgressBar(0, 60);
+ timeBar.setStringPainted(true);
+ rightPanel.add(timeBar);
+
+ endTurnButton = new JButton("Zug beenden");
+ endTurnButton.setFont(endTurnButton.getFont().deriveFont(0));
+ endTurnButton.setMargin(new Insets(0, 0, 0, 0));
+ endTurnButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ endTurnEvent.emit();
+ }
+ });
+
+ rightPanel.add(endTurnButton);
+
+ rightPanel.addComponentListener(new RightPanelResizeListener());
+ }
+
+ 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;
+ int boardWidth = hand.getWidth();
+ int panelWidth = (width - boardWidth) / 2;
+
+ leftPanel.setBounds(x, y, panelWidth, height);
+ hand.setBounds(x + panelWidth, y, boardWidth, height);
+ rightPanel.setBounds(x + panelWidth + boardWidth, y, panelWidth, height);
+
+ leftPanel.validate();
+ rightPanel.validate();
+ }
+
+ /**
+ * Creates a new PlayerPanel instance
+ */
+ PlayerPanel() {
+ setLayout(null);
+
+ createLeftPanel();
+ add(leftPanel);
+
+ hand = new HandPanel();
+ add(hand);
+
+ createRightPanel();
+ add(rightPanel);
+
+ ComponentListener rescaleListener = new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ };
+
+ addComponentListener(rescaleListener);
+ hand.addComponentListener(rescaleListener);
+ }
+
+ private class LeftPanelResizeListener extends ComponentAdapter {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ Insets insets = leftPanel.getInsets();
+ int x = insets.left, y = insets.top, width = leftPanel.getWidth()
+ - insets.left - insets.right, height = leftPanel.getHeight()
+ - insets.top - insets.bottom;
+
+ if (width > SIDE_PANEL_MAX_WIDTH) {
+ x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
+ }
+
+ 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);
+ sortByGroupsButton.setBounds(x, y + firstLineHeight
+ + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
+ sortByRunsButton.setBounds(x + buttonWidth + SIDE_PANEL_SEPARATOR, y
+ + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight);
+
+ sortByGroupsButton.setFont(sortByGroupsButton.getFont().deriveFont(
+ fontSize));
+ sortByRunsButton.setFont(sortByRunsButton.getFont().deriveFont(fontSize));
+ }
+ }
+
+ private class RightPanelResizeListener extends ComponentAdapter {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ 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;
+
+ if (width > SIDE_PANEL_MAX_WIDTH) {
+ x += (width - SIDE_PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + SIDE_PANEL_MAX_WIDTH / 2;
+ }
+
+ 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,
+ buttonWidth, buttonHeight);
+ endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
+ }
+ }
}