summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/StartTurnPanel.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/StartTurnPanel.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/StartTurnPanel.java')
-rw-r--r--src/jrummikub/view/impl/StartTurnPanel.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/jrummikub/view/impl/StartTurnPanel.java b/src/jrummikub/view/impl/StartTurnPanel.java
new file mode 100644
index 0000000..d52ce22
--- /dev/null
+++ b/src/jrummikub/view/impl/StartTurnPanel.java
@@ -0,0 +1,89 @@
+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;
+
+@SuppressWarnings("serial")
+class StartTurnPanel extends JPanel {
+ private final static int PANEL_INSET = 15;
+ private final static int PANEL_SEPARATOR = 10;
+ 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 startTurnLabel;
+ private JButton startTurnButton;
+
+ private Event startTurnEvent = new Event();
+
+ StartTurnPanel() {
+ setLayout(null);
+ setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET,
+ PANEL_INSET));
+
+ startTurnLabel = new JLabel();
+ startTurnLabel.setHorizontalAlignment(JLabel.CENTER);
+ startTurnLabel.setHorizontalTextPosition(JLabel.CENTER);
+ startTurnLabel.setVerticalAlignment(JLabel.CENTER);
+ startTurnLabel.setVerticalTextPosition(JLabel.CENTER);
+ add(startTurnLabel);
+
+ startTurnButton = new JButton("Zug beginnen");
+ startTurnButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ startTurnEvent.emit();
+ }
+ });
+ add(startTurnButton);
+
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ });
+ }
+
+ void setCurrentPlayerName(String playerName) {
+ startTurnLabel.setText("'" + playerName + "' ist jetzt an der Reihe.");
+ }
+
+ IEvent getStartTurnEvent() {
+ return startTurnEvent;
+ }
+
+ 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;
+ }
+
+ int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = width;
+ int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ startTurnLabel.setBounds(x, y, width, firstLineHeight);
+ startTurnButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
+ buttonWidth, buttonHeight);
+ startTurnButton.setFont(startTurnButton.getFont().deriveFont(fontSize));
+ }
+}