summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/View.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/View.java')
-rw-r--r--src/jrummikub/view/impl/View.java40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 31235c6..4cbad44 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -1,8 +1,10 @@
package jrummikub.view.impl;
-import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
+import java.awt.Insets;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
import java.util.Collection;
import javax.swing.JFrame;
@@ -17,9 +19,15 @@ public class View extends JFrame implements IView {
private Table table;
private PlayerPanel playerPanel;
- private final static int PLAYER_PANEL_HEIGHT = 140;
+ private final static float PLAYER_PANEL_RATIO = 0.125f;
+ private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
+ private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH;
+ private static int even(double d) {
+ return 2*(int)(d/2);
+ }
+
public ITable getTable() {
return table;
}
@@ -31,19 +39,35 @@ public class View extends JFrame implements IView {
public View() {
super("JRummikub");
+ setLayout(null);
setSize(1000, 700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
- setLayout(new BorderLayout());
-
table = new Table();
- add(table, BorderLayout.CENTER);
+ add(table);
playerPanel = new PlayerPanel();
- playerPanel.setBorder(new CustomBorder(Color.BLACK, 1, 0, 0, 0));
- playerPanel.setPreferredSize(new Dimension(0, PLAYER_PANEL_HEIGHT+1));
- add(playerPanel, BorderLayout.SOUTH);
+ playerPanel.setBorder(new CustomBorder(Color.BLACK, PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0));
+ add(playerPanel);
+
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ Insets insets = getInsets();
+ int x = insets.left, y = insets.top, width = getWidth()-insets.left-insets.right, height = getHeight()-insets.top-insets.bottom;
+
+ int playerPanelHeight = even(Math.pow((double)width*width*height, 1/3.0)*PLAYER_PANEL_RATIO) + PLAYER_PANEL_BORDER_WIDTH;
+ if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
+ playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
+
+ int tableHeight = height - playerPanelHeight;
+
+ table.setBounds(x, y, width, tableHeight);
+ table.validate();
+ playerPanel.setBounds(x, y+tableHeight, width, playerPanelHeight);
+ }
+ });
setVisible(true);
}