summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/IGameListPanel.java11
-rw-r--r--src/jrummikub/view/impl/GameListPanel.java108
-rw-r--r--src/jrummikub/view/impl/View.java56
3 files changed, 141 insertions, 34 deletions
diff --git a/src/jrummikub/view/IGameListPanel.java b/src/jrummikub/view/IGameListPanel.java
index adb754b..da41839 100644
--- a/src/jrummikub/view/IGameListPanel.java
+++ b/src/jrummikub/view/IGameListPanel.java
@@ -2,11 +2,8 @@ package jrummikub.view;
import java.util.UUID;
-import jrummikub.util.Event;
-import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
-import jrummikub.view.IGameListPanel.GameData;
public interface IGameListPanel {
public static class GameData {
@@ -51,4 +48,10 @@ public interface IGameListPanel {
public IEvent getCancelEvent();
public IEvent1<GameData> getJoinEvent();
-} \ No newline at end of file
+
+ public void removeGame(GameData game);
+
+ public void addGame(GameData game);
+
+ public void setChannelName(String name);
+}
diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java
index d509a6e..eae424a 100644
--- a/src/jrummikub/view/impl/GameListPanel.java
+++ b/src/jrummikub/view/impl/GameListPanel.java
@@ -1,17 +1,23 @@
package jrummikub.view.impl;
import java.awt.Color;
+import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
+import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.Box;
+import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+import javax.swing.ListCellRenderer;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
@@ -28,10 +34,13 @@ class GameListPanel extends JPanel implements IGameListPanel {
private JButton joinButton;
private JButton openNewGameButton;
private JButton cancelButton;
+
private Event1<GameData> joinEvent = new Event1<GameData>();
private Event openNewGameEvent = new Event();
private Event cancelEvent = new Event();
+ private List<GameData> games = new ArrayList<GameData>();
+
GameListPanel() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -41,15 +50,21 @@ class GameListPanel extends JPanel implements IGameListPanel {
c.weighty = 0;
title = new JLabel();
+ title.setFont(title.getFont().deriveFont(16.0f));
add(title, c);
+ add(Box.createVerticalStrut(3), c);
+
gameList = new JList();
+ gameList.setCellRenderer(new GameDataCellRenderer());
c.weighty = 1;
add(new JScrollPane(gameList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c);
- joinButton = new JButton("Beitreten");
c.weighty = 0;
+ add(Box.createVerticalStrut(3), c);
+
+ joinButton = new JButton("Beitreten");
c.gridwidth = 1;
add(joinButton, c);
joinButton.addActionListener(new ActionListener() {
@@ -89,8 +104,43 @@ class GameListPanel extends JPanel implements IGameListPanel {
}
});
- setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
- new EmptyBorder(10, 10, 10, 10)));
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
+ 10, 10, 10, 10)));
+ }
+
+ void reset() {
+ games.clear();
+ }
+
+ @Override
+ public void setChannelName(String name) {
+ title.setText("Spiele in " + name + ":");
+ }
+
+ @Override
+ public void addGame(GameData game) {
+ if (!games.contains(game)) {
+ games.add(game);
+ }
+
+ updateModel();
+ }
+
+ @Override
+ public void removeGame(GameData game) {
+ if (games.remove(game)) {
+ updateModel();
+ }
+ }
+
+ private void updateModel() {
+ DefaultListModel model = new DefaultListModel();
+
+ for (GameData game : games) {
+ model.addElement(game);
+ }
+
+ gameList.setModel(model);
}
@Override
@@ -108,4 +158,56 @@ class GameListPanel extends JPanel implements IGameListPanel {
return cancelEvent;
}
+ private static class GameDataCellRenderer extends JPanel implements
+ ListCellRenderer {
+ JLabel hostLabel, playerCountLabel;
+
+ GameDataCellRenderer() {
+ setLayout(new GridLayout(1, 2));
+ hostLabel = new JLabel();
+ hostLabel.setOpaque(true);
+ hostLabel.setHorizontalAlignment(JLabel.LEFT);
+ add(hostLabel);
+
+ playerCountLabel = new JLabel();
+ playerCountLabel.setOpaque(true);
+ playerCountLabel.setHorizontalAlignment(JLabel.RIGHT);
+ add(playerCountLabel);
+ }
+
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value,
+ int index, boolean isSelected, boolean cellHasFocus) {
+ String host = "", playerCount = "";
+
+ if (value instanceof GameData) {
+ GameData gameData = (GameData) value;
+
+ host = gameData.getHost();
+ playerCount = gameData.getCurrentPlayerCount() + "/"
+ + gameData.getMaxPlayerCount();
+ } else {
+ host = String.valueOf(value);
+ }
+
+ hostLabel.setText(host);
+ playerCountLabel.setText(playerCount);
+
+ if (isSelected) {
+ hostLabel.setBackground(list.getSelectionBackground());
+ hostLabel.setForeground(list.getSelectionForeground());
+ playerCountLabel.setBackground(list.getSelectionBackground());
+ playerCountLabel.setForeground(list.getSelectionForeground());
+ } else {
+ hostLabel.setBackground(list.getBackground());
+ hostLabel.setForeground(list.getForeground());
+ playerCountLabel.setBackground(list.getBackground());
+ playerCountLabel.setForeground(list.getForeground());
+ }
+
+ setEnabled(list.isEnabled());
+ setFont(list.getFont());
+ return this;
+ }
+ }
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 01623d2..c18d3b3 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -154,8 +154,7 @@ public class View extends JFrame implements IView {
showSettingsPanel(false);
showLoginPanel(false);
showGameListPanel(false);
- getHandPanel().setStones(
- Collections.<Pair<Stone, Position>> emptyList());
+ getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
@@ -306,8 +305,8 @@ public class View extends JFrame implements IView {
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));
mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel();
@@ -380,6 +379,10 @@ public class View extends JFrame implements IView {
@Override
public void showGameListPanel(boolean show) {
+ if (show) {
+ gameListPanel.reset();
+ }
+
gameListPanel.setVisible(show);
}
@@ -427,24 +430,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
- Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
- -'J', StoneColor.BLACK), new Position(2.5f, 0));
- Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
- -'R', StoneColor.ORANGE), new Position(3.5f, 0));
- Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.BLUE), new Position(4.5f, 0));
- Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.RED), new Position(5.5f, 0));
- Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.GREEN), new Position(6.5f, 0));
- Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
- -'i', StoneColor.VIOLET), new Position(7.5f, 0));
- Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
- -'k', StoneColor.AQUA), new Position(8.5f, 0));
- Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.GRAY), new Position(9.5f, 0));
- Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
- -'b', StoneColor.BLACK), new Position(10.5f, 0));
+ Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
+ StoneColor.BLACK), new Position(2.5f, 0));
+ Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
+ StoneColor.ORANGE), new Position(3.5f, 0));
+ Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.BLUE), new Position(4.5f, 0));
+ Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.RED), new Position(5.5f, 0));
+ Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.GREEN), new Position(6.5f, 0));
+ Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
+ StoneColor.VIOLET), new Position(7.5f, 0));
+ Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
+ StoneColor.AQUA), new Position(8.5f, 0));
+ Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.GRAY), new Position(9.5f, 0));
+ Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
+ StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1));
@@ -459,9 +462,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1));
- return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
- stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
- stone5, stone6);
+ return Arrays
+ .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
+ stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
}
@Override
@@ -478,8 +481,7 @@ public class View extends JFrame implements IView {
&& type != BottomPanelType.WIN_PANEL && type != null);
if (type == BottomPanelType.START_GAME_PANEL) {
- table.setStoneSets(Collections
- .<Pair<StoneSet, Position>> emptyList());
+ table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}