summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java4
-rw-r--r--src/jrummikub/control/network/NetworkGameControl.java53
-rw-r--r--src/jrummikub/view/IView.java65
-rw-r--r--src/jrummikub/view/impl/View.java64
-rw-r--r--src/jrummikub/view/impl/WinPanel.java99
5 files changed, 161 insertions, 124 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index 91b0940..b247a1c 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -1,7 +1,6 @@
package jrummikub.control.network;
import java.util.Iterator;
-import java.util.List;
import java.util.UUID;
import jrummikub.model.GameSettings;
@@ -107,8 +106,7 @@ public class GameOfferControl extends AbstractGameBeginControl {
}
private void handleLeave(String nickname) {
- List<PlayerSettings> players = gameData.getGameSettings().getPlayerList();
- for (PlayerSettings s : players) {
+ for (PlayerSettings s : gameData.getGameSettings().getPlayerList()) {
if (s.getName().equals(nickname) && s.getType() == Type.NETWORK) {
s.setType(Type.VACANT);
s.setName("Offen");
diff --git a/src/jrummikub/control/network/NetworkGameControl.java b/src/jrummikub/control/network/NetworkGameControl.java
index d053e92..768f0c3 100644
--- a/src/jrummikub/control/network/NetworkGameControl.java
+++ b/src/jrummikub/control/network/NetworkGameControl.java
@@ -5,7 +5,10 @@ import jrummikub.control.RoundControl;
import jrummikub.control.SaveControl;
import jrummikub.model.GameSettings;
import jrummikub.model.IRoundState;
+import jrummikub.model.PlayerSettings;
+import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.IListener;
+import jrummikub.util.IListener1;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
@@ -20,34 +23,51 @@ public class NetworkGameControl extends GameControl {
* Creates new network game control
*
* @param gameSettings
- * current game settings
+ * current game settings
* @param saveControl
- * if there should ever be saving in network mode
+ * if there should ever be saving in network mode
* @param view
- * the view
+ * the view
* @param connectionControl
- * the current connection
+ * the current connection
* @param host
- * of the current game
+ * of the current game
*/
- public NetworkGameControl(GameSettings gameSettings,
- SaveControl saveControl, IView view,
- IConnectionControl connectionControl, boolean host) {
+ public NetworkGameControl(GameSettings gameSettings, SaveControl saveControl,
+ final IView view, IConnectionControl connectionControl, boolean host) {
super(gameSettings, saveControl, view);
this.connectionControl = connectionControl;
this.host = host;
- }
- @Override
- protected void startRound() {
- connections.add(connectionControl.getRoundStartEvent().add(
- new IListener() {
+ connections.add(connectionControl.getParticipantLeftEvent().add(
+ new IListener1<String>() {
@Override
- public void handle() {
- NetworkGameControl.super.startRound();
+ public void handle(String nickname) {
+ if (NetworkGameControl.this.gameSettings == null) {
+ return;
+ }
+
+ for (PlayerSettings s : NetworkGameControl.this.gameSettings
+ .getPlayerList()) {
+ if (s.getName().equals(nickname) && s.getType() == Type.NETWORK) {
+ abortGame();
+ view.setBottomPanel(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL);
+ return;
+ }
+ }
}
}));
+ }
+
+ @Override
+ protected void startRound() {
+ connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ NetworkGameControl.super.startRound();
+ }
+ }));
if (host) {
connectionControl.startRound();
@@ -61,8 +81,7 @@ public class NetworkGameControl extends GameControl {
@Override
protected RoundControl createRoundControl(IRoundState roundState) {
- return new NetworkRoundControl(roundState, view, connectionControl,
- host);
+ return new NetworkRoundControl(roundState, view, connectionControl, host);
}
@Override
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index c3670cb..c8f7ce0 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -57,7 +57,7 @@ public interface IView {
* Sets the current player's name
*
* @param playerName
- * the player name
+ * the player name
*/
public void setCurrentPlayerName(String playerName);
@@ -69,7 +69,7 @@ public interface IView {
* Sets the stones that are to be painted selected
*
* @param stones
- * the stones to be painted selected
+ * the stones to be painted selected
*/
public void setSelectedStones(Collection<Stone> stones);
@@ -106,7 +106,7 @@ public interface IView {
* Shows or hides the game settings panel
*
* @param show
- * specifies if the panel shall be shown or hidden
+ * specifies if the panel shall be shown or hidden
*/
public void showSettingsPanel(boolean show);
@@ -114,7 +114,7 @@ public interface IView {
* Shows or hides the score panel
*
* @param show
- * specifies if the panel shall be shown or hidden
+ * specifies if the panel shall be shown or hidden
*/
public void showScorePanel(boolean show);
@@ -123,16 +123,16 @@ public interface IView {
* along with the name
*
* @param color
- * the current player's color
+ * the current player's color
*/
public void setCurrentPlayerColor(Color color);
/**
- * Is used for the PlayerPanel to display if a player has laid out along
- * with the name
+ * Is used for the PlayerPanel to display if a player has laid out along with
+ * the name
*
* @param hasLaidOut
- * specifies if the current player has laid out or not
+ * specifies if the current player has laid out or not
*/
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut);
@@ -147,13 +147,13 @@ public interface IView {
* Sets the bottom panels type
*
* @param type
- * the type of the bottom panel
+ * the type of the bottom panel
*/
public void setBottomPanel(BottomPanelType type);
/**
- * The menu new game event is emitted when the user selects the new game
- * menu entry
+ * The menu new game event is emitted when the user selects the new game menu
+ * entry
*
* @return the event
*/
@@ -221,7 +221,7 @@ public interface IView {
* Show/hide login panel
*
* @param show
- * true = login panel is shown
+ * true = login panel is shown
*/
public void showLoginPanel(boolean show);
@@ -234,7 +234,7 @@ public interface IView {
* Enable/disable pause mode
*
* @param enable
- * true = enable
+ * true = enable
*/
public void enablePauseMode(boolean enable);
@@ -242,7 +242,7 @@ public interface IView {
* Show/hide game list panel
*
* @param show
- * true = show
+ * true = show
*/
public void showGameListPanel(boolean show);
@@ -250,7 +250,7 @@ public interface IView {
* Show/hide side panel
*
* @param show
- * true to show
+ * true to show
*/
void showSidePanel(boolean show);
@@ -258,7 +258,7 @@ public interface IView {
* Is set if a player tried to lay out less than initial meld threshold
*
* @param points
- * initial meld threshold
+ * initial meld threshold
*/
public void setInitialMeldError(int points);
@@ -266,7 +266,7 @@ public interface IView {
* Show stone collection
*
* @param enable
- * showing collection
+ * showing collection
*/
public void setStoneCollectionHidden(boolean enable);
@@ -279,7 +279,7 @@ public interface IView {
* Set invalid sets to enable showing
*
* @param sets
- * invalid sets on table
+ * invalid sets on table
*/
public void setInvalidStoneSets(Collection<StoneSet> sets);
@@ -292,7 +292,7 @@ public interface IView {
* Show an error message when the server couldn't be started
*
* @param alreadyRunning
- * true when the server is already running on this machine
+ * true when the server is already running on this machine
*/
public void showServerStartupError(boolean alreadyRunning);
@@ -300,7 +300,7 @@ public interface IView {
* Enables/disables saving in menu bar
*
* @param enable
- * saving possible
+ * saving possible
*/
public void enableSave(boolean enable);
@@ -308,7 +308,7 @@ public interface IView {
* Sets the quit warning panel visible
*
* @param show
- * is visible
+ * is visible
*/
public void showQuitWarningPanel(boolean show);
@@ -343,7 +343,7 @@ public interface IView {
* Set the connect panel visible
*
* @param show
- * is visible
+ * is visible
*/
public void showConnectPanel(boolean show);
@@ -359,7 +359,7 @@ public interface IView {
* situation
*
* @param mayPause
- * pausing possible
+ * pausing possible
*/
public void setMayPause(boolean mayPause);
@@ -367,23 +367,6 @@ public interface IView {
* Different types of bottom panels
*/
public enum BottomPanelType {
- /** */
- START_GAME_PANEL,
- /** */
- START_TURN_PANEL,
- /** */
- START_REDEAL_TURN_PANEL,
- /** */
- START_LAST_TURN_PANEL,
- /** */
- INVALID_TURN_PANEL,
- /** */
- HUMAN_HAND_PANEL,
- /** */
- NONHUMAN_HAND_PANEL,
- /** */
- WIN_PANEL,
- /** */
- NETWORK_WIN_PANEL
+ START_GAME_PANEL, START_TURN_PANEL, START_REDEAL_TURN_PANEL, START_LAST_TURN_PANEL, INVALID_TURN_PANEL, HUMAN_HAND_PANEL, NONHUMAN_HAND_PANEL, WIN_PANEL, NETWORK_WIN_PANEL, NETWORK_CONNECTION_LOST_PANEL
}
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 0900f92..962ecf0 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -187,8 +187,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());
@@ -206,8 +205,8 @@ public class View extends JFrame implements IView {
.showMessageDialog(
this,
alreadyRunning ? "Ein XMPP-Server l\u00e4ft bereits auf diesem Computer"
- : "Der Server konnte nicht gestartet werden",
- "Fehler", JOptionPane.ERROR_MESSAGE);
+ : "Der Server konnte nicht gestartet werden", "Fehler",
+ JOptionPane.ERROR_MESSAGE);
}
@@ -396,8 +395,7 @@ public class View extends JFrame implements IView {
table = new TablePanel();
mainLayer.add(table);
- table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
- Color.BLACK));
+ table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.BLACK));
playerPanel = new PlayerPanel();
mainLayer.add(playerPanel);
@@ -417,9 +415,9 @@ public class View extends JFrame implements IView {
sidePanel = new SidePanel();
sidePanel.setVisible(false);
mainLayer.add(sidePanel);
- sidePanel.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1,
- Color.BLACK), new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
- Color.GRAY)));
+ sidePanel
+ .setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK),
+ new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.GRAY)));
}
@Override
@@ -623,24 +621,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));
@@ -655,9 +653,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
@@ -673,7 +671,8 @@ public class View extends JFrame implements IView {
startTurnPanel.setType(type);
startTurnPanel.setVisible(showStartTurnPanel);
- boolean showWinPanel = (type == BottomPanelType.WIN_PANEL || type == BottomPanelType.NETWORK_WIN_PANEL);
+ boolean showWinPanel = (type == BottomPanelType.WIN_PANEL
+ || type == BottomPanelType.NETWORK_WIN_PANEL || type == BottomPanelType.NETWORK_CONNECTION_LOST_PANEL);
winPanel.setType(type);
winPanel.setVisible(showWinPanel);
@@ -681,8 +680,7 @@ public class View extends JFrame implements IView {
&& 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());
}
diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java
index 4d9aacc..888cf75 100644
--- a/src/jrummikub/view/impl/WinPanel.java
+++ b/src/jrummikub/view/impl/WinPanel.java
@@ -28,6 +28,8 @@ class WinPanel extends JPanel {
private final static float MAX_BUTTON_FONT_SIZE = 12;
private JLabel waitingLabel;
+ private JLabel connectionLostLabel;
+
private JButton newRoundButton;
private JButton newGameButton;
private JButton endProgramButton;
@@ -50,6 +52,12 @@ class WinPanel extends JPanel {
waitingLabel.setVerticalAlignment(JLabel.CENTER);
add(waitingLabel);
+ connectionLostLabel = new JLabel(
+ "Die Verbindung zu einem Spieler ist abgebrochen.");
+ connectionLostLabel.setHorizontalAlignment(JLabel.CENTER);
+ connectionLostLabel.setVerticalAlignment(JLabel.CENTER);
+ add(connectionLostLabel);
+
newRoundButton = new JButton("Neue Runde");
newRoundButton.addActionListener(new ActionListener() {
@Override
@@ -117,44 +125,26 @@ class WinPanel extends JPanel {
width = width / 2 + PANEL_MAX_WIDTH / 2;
}
- int buttonWidth;
- int buttonHeight;
- int buttonY;
if (type == BottomPanelType.WIN_PANEL) {
- buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3;
- buttonHeight = height;
- buttonY = y;
- } else {
- buttonWidth = (width - PANEL_SEPARATOR) / 2;
- buttonHeight = height * 2 / 3 - PANEL_SEPARATOR;
- buttonY = y + height - buttonHeight;
+ rescaleWinPanel(x, y, width, height);
+ } else if (type == BottomPanelType.NETWORK_WIN_PANEL) {
+ rescaleNetworkWinPanel(x, y, width, height);
+ } else if (type == BottomPanelType.NETWORK_CONNECTION_LOST_PANEL) {
+ rescaleNetworkConnectionLostPanel(x, y, width, height);
}
- int labelHeight = height - buttonHeight - PANEL_SEPARATOR;
+ }
+
+ private void rescaleWinPanel(int x, int y, int width, int height) {
+ int buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3;
+ int buttonHeight = height;
+ int buttonY = y;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE;
- if (type == BottomPanelType.WIN_PANEL) {
- rescaleWinPanel(x, buttonWidth, buttonHeight, buttonY, fontSize);
- } else if (type == BottomPanelType.NETWORK_WIN_PANEL) {
- waitingLabel.setBounds(x, y, width, labelHeight);
- waitingLabel.setVisible(true);
-
- newRoundButton.setVisible(false);
-
- newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight);
- newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
-
- endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY,
- buttonWidth, buttonHeight);
- endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
- }
- }
-
- private void rescaleWinPanel(int x, int buttonWidth, int buttonHeight,
- int buttonY, float fontSize) {
waitingLabel.setVisible(false);
+ connectionLostLabel.setVisible(false);
newRoundButton.setBounds(x, buttonY, buttonWidth, buttonHeight);
newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize));
newRoundButton.setVisible(true);
@@ -168,6 +158,55 @@ class WinPanel extends JPanel {
endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
}
+ private void rescaleNetworkWinPanel(int x, int y, int width, int height) {
+ int buttonWidth = (width - PANEL_SEPARATOR) / 2;
+ int buttonHeight = height * 2 / 3 - PANEL_SEPARATOR;
+ int buttonY = y + height - buttonHeight;
+ int labelHeight = height - buttonHeight - PANEL_SEPARATOR;
+
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ waitingLabel.setBounds(x, y, width, labelHeight);
+ waitingLabel.setVisible(true);
+ connectionLostLabel.setVisible(false);
+
+ newRoundButton.setVisible(false);
+
+ newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight);
+ newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
+
+ endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY,
+ buttonWidth, buttonHeight);
+ endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
+ }
+
+ private void rescaleNetworkConnectionLostPanel(int x, int y, int width,
+ int height) {
+ int buttonWidth = (width - PANEL_SEPARATOR) / 2;
+ int buttonHeight = height * 2 / 3 - PANEL_SEPARATOR;
+ int buttonY = y + height - buttonHeight;
+ int labelHeight = height - buttonHeight - PANEL_SEPARATOR;
+
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ waitingLabel.setVisible(false);
+ connectionLostLabel.setBounds(x, y, width, labelHeight);
+ connectionLostLabel.setVisible(true);
+
+ newRoundButton.setVisible(false);
+
+ newGameButton.setBounds(x, buttonY, buttonWidth, buttonHeight);
+ newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
+
+ endProgramButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, buttonY,
+ buttonWidth, buttonHeight);
+ endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
+ }
+
void setType(BottomPanelType type) {
this.type = type;
rescale();