summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/view/impl/ImageUtil.java26
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java109
-rw-r--r--src/jrummikub/view/impl/View.java75
3 files changed, 185 insertions, 25 deletions
diff --git a/src/jrummikub/view/impl/ImageUtil.java b/src/jrummikub/view/impl/ImageUtil.java
new file mode 100644
index 0000000..78f825b
--- /dev/null
+++ b/src/jrummikub/view/impl/ImageUtil.java
@@ -0,0 +1,26 @@
+package jrummikub.view.impl;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+
+import javax.swing.ImageIcon;
+
+class ImageUtil {
+ private ImageUtil() {
+ }
+
+ static ImageIcon createColorIcon(Color c, int size) {
+ BufferedImage image = new BufferedImage(size, size,
+ BufferedImage.TYPE_INT_RGB);
+ Graphics2D g = image.createGraphics();
+
+ g.setColor(Color.BLACK);
+ g.fillRect(0, 0, size, size);
+
+ g.setColor(c);
+ g.fillRect(1, 1, size - 2, size - 2);
+
+ return new ImageIcon(image);
+ }
+}
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
new file mode 100644
index 0000000..9aba78c
--- /dev/null
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -0,0 +1,109 @@
+package jrummikub.view.impl;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.util.LinkedList;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTextField;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+
+@SuppressWarnings("serial")
+class SettingsPanel extends JPanel {
+ private JPanel playerSetupPanel;
+ private JPanel playerSettingsViewport;
+ private JPanel ruleSetupPanel;
+
+ private LinkedList<PlayerSettingsPanel> playerSettingsPanels = new LinkedList<PlayerSettingsPanel>();
+
+ private void addPlayerSettings() {
+ PlayerSettingsPanel panel = new PlayerSettingsPanel();
+ playerSettingsPanels.add(panel);
+ playerSettingsViewport.add(panel,
+ playerSettingsViewport.getComponentCount() - 1);
+ }
+
+ private void createPlayerSetupPanel() {
+ playerSetupPanel = new JPanel();
+ playerSetupPanel.setLayout(new BorderLayout());
+
+ playerSettingsViewport = new JPanel();
+ playerSettingsViewport.setLayout(new BoxLayout(playerSettingsViewport,
+ BoxLayout.Y_AXIS));
+
+ JScrollPane scrollPane = new JScrollPane(playerSettingsViewport,
+ JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ playerSetupPanel.add(scrollPane);
+
+ playerSettingsViewport.add(new JButton("Neuer Spieler"));
+
+ addPlayerSettings();
+ addPlayerSettings();
+ }
+
+ private void createRuleSetupPanel() {
+ ruleSetupPanel = new JPanel();
+ }
+
+ SettingsPanel() {
+ setLayout(new BorderLayout());
+
+ final JTabbedPane tabbedPane = new JTabbedPane();
+
+ createPlayerSetupPanel();
+ tabbedPane.addTab("Spieler", playerSetupPanel);
+
+ createRuleSetupPanel();
+ tabbedPane.addTab("Regeln", ruleSetupPanel);
+
+ add(tabbedPane);
+
+ JButton startButton = new JButton("Spiel starten");
+ add(startButton, BorderLayout.SOUTH);
+
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
+ 10, 10, 10, 10)));
+
+ 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;
+
+ // tabbedPane.setBounds(x, y, width, height);
+ }
+ });
+ }
+
+ private static class PlayerSettingsPanel extends JPanel {
+ PlayerSettingsPanel() {
+ setLayout(new BorderLayout());
+
+ add(new JButton(ImageUtil.createColorIcon(Color.RED, 16)),
+ BorderLayout.WEST);
+ add(new JTextField());
+ add(new JButton("\u2716"), BorderLayout.EAST);
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ return getComponent(1).getPreferredSize();
+ }
+
+ @Override
+ public Dimension getMaximumSize() {
+ return new Dimension(Integer.MAX_VALUE, getPreferredSize().height);
+ }
+ }
+}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 74c6d54..ad47375 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -7,6 +7,8 @@ import java.awt.event.ComponentEvent;
import java.util.Collection;
import javax.swing.JFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.JPanel;
import javax.swing.border.MatteBorder;
import jrummikub.model.Stone;
@@ -21,10 +23,14 @@ import jrummikub.view.IView;
*/
@SuppressWarnings("serial")
public class View extends JFrame implements IView {
+ private JLayeredPane layeredPane;
+ private JPanel mainLayer;
+
private TablePanel table;
private PlayerPanel playerPanel;
private StartTurnPanel startTurnPanel;
private WinPanel winPanel;
+ private SettingsPanel settingsPanel;
private final static float PLAYER_PANEL_RATIO = 0.14f;
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
@@ -59,50 +65,69 @@ public class View extends JFrame implements IView {
setSize(800, 600);
setDefaultCloseOperation(EXIT_ON_CLOSE);
+ layeredPane = new JLayeredPane();
+ layeredPane.setLayout(null);
+ add(layeredPane);
+
+ mainLayer = new JPanel();
+ mainLayer.setLayout(null);
+ layeredPane.add(mainLayer);
+
table = new TablePanel();
- add(table);
+ mainLayer.add(table);
playerPanel = new PlayerPanel();
- playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
- 0, Color.BLACK));
+ playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
+ Color.BLACK));
playerPanel.setVisible(false);
- add(playerPanel);
+ mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel();
- add(startTurnPanel);
+ mainLayer.add(startTurnPanel);
winPanel = new WinPanel();
winPanel.setVisible(false);
- add(winPanel);
+ mainLayer.add(winPanel);
+
+ settingsPanel = new SettingsPanel();
+ settingsPanel.setVisible(false);
+ layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER);
+ layeredPane.add(settingsPanel);
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
- Insets insets = getInsets();
- int 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(0, 0, width, tableHeight);
- table.validate();
- playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
- startTurnPanel.setBounds(0, tableHeight, width,
- playerPanelHeight);
- winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ rescale();
}
});
setVisible(true);
}
+ private void rescale() {
+ Insets insets = getInsets();
+ int width = getWidth() - insets.left - insets.right, height = getHeight()
+ - insets.top - insets.bottom;
+
+ layeredPane.setBounds(0, 0, width, height);
+ mainLayer.setBounds(0, 0, width, height);
+
+ 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(0, 0, width, tableHeight);
+ table.validate();
+ playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
+ }
+
@Override
public void setSelectedStones(Collection<Stone> stones) {
table.setSelectedStones(stones);