summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-04-27 20:25:37 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-04-27 20:25:37 +0200
commita526d2efbf69ecf5fd951391644539d14c9b3798 (patch)
treeabe315bb41d39e6ead792fd8cb1a47ac577cc0b4 /src
parent793b4c6dac0137aef286f5096c09bc473105c447 (diff)
downloadJRummikub-a526d2efbf69ecf5fd951391644539d14c9b3798.tar
JRummikub-a526d2efbf69ecf5fd951391644539d14c9b3798.zip
Created basic view
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@3 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/view/Board.java12
-rw-r--r--src/jrummikub/view/IBoard.java4
-rw-r--r--src/jrummikub/view/IPlayerPanel.java8
-rw-r--r--src/jrummikub/view/ITable.java7
-rw-r--r--src/jrummikub/view/IView.java15
-rw-r--r--src/jrummikub/view/PlayerPanel.java144
-rw-r--r--src/jrummikub/view/Table.java47
-rw-r--r--src/jrummikub/view/View.java62
8 files changed, 299 insertions, 0 deletions
diff --git a/src/jrummikub/view/Board.java b/src/jrummikub/view/Board.java
new file mode 100644
index 0000000..70c0988
--- /dev/null
+++ b/src/jrummikub/view/Board.java
@@ -0,0 +1,12 @@
+package jrummikub.view;
+
+import java.awt.Color;
+
+import javax.swing.JPanel;
+
+@SuppressWarnings("serial")
+public class Board extends JPanel implements IBoard {
+ Board() {
+ setBackground(Color.DARK_GRAY);
+ }
+}
diff --git a/src/jrummikub/view/IBoard.java b/src/jrummikub/view/IBoard.java
new file mode 100644
index 0000000..7b9f70b
--- /dev/null
+++ b/src/jrummikub/view/IBoard.java
@@ -0,0 +1,4 @@
+package jrummikub.view;
+
+public interface IBoard {
+} \ No newline at end of file
diff --git a/src/jrummikub/view/IPlayerPanel.java b/src/jrummikub/view/IPlayerPanel.java
new file mode 100644
index 0000000..3330804
--- /dev/null
+++ b/src/jrummikub/view/IPlayerPanel.java
@@ -0,0 +1,8 @@
+package jrummikub.view;
+
+public interface IPlayerPanel {
+ public IBoard getBoard();
+
+ public void setCurrentPlayerName(String playerName);
+ public void setTimeLeft(int time);
+} \ No newline at end of file
diff --git a/src/jrummikub/view/ITable.java b/src/jrummikub/view/ITable.java
new file mode 100644
index 0000000..30582d0
--- /dev/null
+++ b/src/jrummikub/view/ITable.java
@@ -0,0 +1,7 @@
+package jrummikub.view;
+
+public interface ITable {
+ public void setLeftPlayerName(String playerName);
+ public void setTopPlayerName(String playerName);
+ public void setRightPlayerName(String playerName);
+} \ No newline at end of file
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
new file mode 100644
index 0000000..a5f54b8
--- /dev/null
+++ b/src/jrummikub/view/IView.java
@@ -0,0 +1,15 @@
+package jrummikub.view;
+
+public interface IView {
+
+ /**
+ * @return the table
+ */
+ public ITable getTable();
+
+ /**
+ * @return the playerPanel
+ */
+ public IPlayerPanel getPlayerPanel();
+
+} \ No newline at end of file
diff --git a/src/jrummikub/view/PlayerPanel.java b/src/jrummikub/view/PlayerPanel.java
new file mode 100644
index 0000000..f0416dd
--- /dev/null
+++ b/src/jrummikub/view/PlayerPanel.java
@@ -0,0 +1,144 @@
+package jrummikub.view;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.text.DecimalFormat;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.border.LineBorder;
+
+@SuppressWarnings("serial")
+public class PlayerPanel extends JPanel implements IPlayerPanel {
+ private final static DecimalFormat intFormat = new DecimalFormat("00");
+
+ private Board board;
+
+ private JLabel currentPlayerNameLabel;
+ private JButton sortByNumberButton;
+ private JButton sortByColorButton;
+ private JProgressBar timeBar;
+ private JButton endTurnButton;
+
+
+ @Override
+ public IBoard getBoard() {
+ return board;
+ }
+
+ @Override
+ public void setCurrentPlayerName(String playerName) {
+ currentPlayerNameLabel.setText(playerName);
+ }
+
+ @Override
+ public
+ void setTimeLeft(int time) {
+ timeBar.setValue(time);
+ timeBar.setString(Integer.toString(time/60) + ":" + intFormat.format(time%60));
+ }
+
+
+ JPanel createLeftPanel() {
+ JPanel panel = new JPanel();
+ panel.setPreferredSize(new Dimension(0, 0));
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ panel.setLayout(layout);
+ panel.setOpaque(false);
+
+
+ currentPlayerNameLabel = new JLabel();
+ currentPlayerNameLabel.setHorizontalAlignment(JLabel.CENTER);
+ currentPlayerNameLabel.setHorizontalTextPosition(JLabel.CENTER);
+ currentPlayerNameLabel.setVerticalAlignment(JLabel.CENTER);
+ currentPlayerNameLabel.setVerticalTextPosition(JLabel.CENTER);
+ currentPlayerNameLabel.setPreferredSize(new Dimension(200, 30));
+ c.weightx = 0;
+ c.weighty = 1;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(25, 0, 0, 0);
+ layout.setConstraints(currentPlayerNameLabel, c);
+ panel.add(currentPlayerNameLabel);
+
+ sortByNumberButton = new JButton("<html>Sort by<br>number");
+ sortByNumberButton.setPreferredSize(new Dimension(95, 50));
+ c.gridwidth = GridBagConstraints.RELATIVE;
+ c.gridheight = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(15, 0, 20, 5);
+ layout.setConstraints(sortByNumberButton, c);
+ panel.add(sortByNumberButton);
+
+ sortByColorButton = new JButton("<html>Sort by<br>color");
+ sortByColorButton.setPreferredSize(new Dimension(95, 50));
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(15, 5, 20, 0);
+ layout.setConstraints(sortByColorButton, c);
+ panel.add(sortByColorButton);
+
+
+ return panel;
+ }
+
+ JPanel createRightPanel() {
+ JPanel panel = new JPanel();
+ panel.setPreferredSize(new Dimension(0, 0));
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ panel.setLayout(layout);
+ panel.setOpaque(false);
+
+ timeBar = new JProgressBar(0, 60);
+ timeBar.setStringPainted(true);
+ timeBar.setPreferredSize(new Dimension(200, 30));
+ c.weightx = 0;
+ c.weighty = 1;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(25, 0, 0, 0);
+ layout.setConstraints(timeBar, c);
+ panel.add(timeBar);
+
+ endTurnButton = new JButton("End turn");
+ endTurnButton.setPreferredSize(new Dimension(200, 50));
+ c.gridheight = GridBagConstraints.REMAINDER;
+ c.insets = new Insets(15, 0, 20, 0);
+ layout.setConstraints(endTurnButton, c);
+ panel.add(endTurnButton);
+
+ return panel;
+ }
+
+
+ PlayerPanel() {
+ GridBagLayout layout = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ setLayout(layout);
+
+ setBorder(new LineBorder(Color.BLACK, 1));
+ setBackground(Color.LIGHT_GRAY);
+
+ JPanel leftPanel = createLeftPanel();
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx = 1;
+ c.weighty = 1;
+ c.gridheight = GridBagConstraints.REMAINDER;
+ layout.setConstraints(leftPanel, c);
+ add(leftPanel);
+
+ board = new Board();
+ c.weightx = 3;
+ layout.setConstraints(board, c);
+ add(board);
+
+ JPanel rightPanel = createRightPanel();
+ c.weightx = 1;
+ c.gridwidth = GridBagConstraints.REMAINDER;
+ layout.setConstraints(rightPanel, c);
+ add(rightPanel);
+ }
+}
diff --git a/src/jrummikub/view/Table.java b/src/jrummikub/view/Table.java
new file mode 100644
index 0000000..d27c8a1
--- /dev/null
+++ b/src/jrummikub/view/Table.java
@@ -0,0 +1,47 @@
+package jrummikub.view;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+@SuppressWarnings("serial")
+public class Table extends JPanel implements ITable {
+ private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
+ private JPanel innerPanel;
+
+
+ @Override
+ public void setLeftPlayerName(String playerName) {
+ leftPlayerLabel.setText(playerName);
+ }
+
+ @Override
+ public void setTopPlayerName(String playerName) {
+ topPlayerLabel.setText(playerName);
+ }
+
+ @Override
+ public void setRightPlayerName(String playerName) {
+ rightPlayerLabel.setText(playerName);
+ }
+
+ Table() {
+ setLayout(new BorderLayout());
+
+ leftPlayerLabel = new JLabel();
+ add(leftPlayerLabel, BorderLayout.WEST);
+
+ topPlayerLabel = new JLabel();
+ topPlayerLabel.setHorizontalAlignment(JLabel.CENTER);
+ topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER);
+ add(topPlayerLabel, BorderLayout.NORTH);
+
+ rightPlayerLabel = new JLabel();
+ add(rightPlayerLabel, BorderLayout.EAST);
+
+ innerPanel = new JPanel();
+ innerPanel.setOpaque(false);
+ add(innerPanel, BorderLayout.CENTER);
+ }
+}
diff --git a/src/jrummikub/view/View.java b/src/jrummikub/view/View.java
new file mode 100644
index 0000000..52efc54
--- /dev/null
+++ b/src/jrummikub/view/View.java
@@ -0,0 +1,62 @@
+package jrummikub.view;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+
+import javax.swing.JFrame;
+import javax.swing.UIManager;
+
+@SuppressWarnings("serial")
+public class View extends JFrame implements IView {
+ private Table table;
+ private PlayerPanel playerPanel;
+
+ private final static int PLAYER_PANEL_HEIGHT = 150;
+
+
+ public ITable getTable() {
+ return table;
+ }
+
+ public IPlayerPanel getPlayerPanel() {
+ return playerPanel;
+ }
+
+
+ public View() {
+ super("JRummikub");
+
+ setDefaultCloseOperation(EXIT_ON_CLOSE);
+
+ setLayout(new BorderLayout());
+
+ table = new Table();
+ add(table, BorderLayout.CENTER);
+
+ playerPanel = new PlayerPanel();
+ playerPanel.setPreferredSize(new Dimension(0, PLAYER_PANEL_HEIGHT));
+ add(playerPanel, BorderLayout.SOUTH);
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ String nativeLF = UIManager.getSystemLookAndFeelClassName();
+
+ try {
+ UIManager.setLookAndFeel(nativeLF);
+ } catch (Exception e) {
+ }
+
+ View view = new View();
+
+ view.getPlayerPanel().setCurrentPlayerName("Player 1");
+ view.getPlayerPanel().setTimeLeft(42);
+ view.getTable().setLeftPlayerName("Player 2");
+ view.getTable().setTopPlayerName("Player 3");
+ view.getTable().setRightPlayerName("Player 4");
+
+ view.setVisible(true);
+ }
+}