summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/control/network/MockConnectionControl.java7
-rw-r--r--mock/jrummikub/view/MockView.java12
-rw-r--r--src/jrummikub/control/ApplicationControl.java76
-rw-r--r--src/jrummikub/control/LoginControl.java18
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java61
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java4
-rw-r--r--src/jrummikub/control/network/NetworkControl.java49
-rw-r--r--src/jrummikub/view/IConnectPanel.java11
-rw-r--r--src/jrummikub/view/IView.java40
-rw-r--r--src/jrummikub/view/LoginError.java18
-rw-r--r--src/jrummikub/view/impl/ConnectPanel.java109
-rw-r--r--src/jrummikub/view/impl/QuitWarningPanel.java8
-rw-r--r--src/jrummikub/view/impl/View.java36
13 files changed, 329 insertions, 120 deletions
diff --git a/mock/jrummikub/control/network/MockConnectionControl.java b/mock/jrummikub/control/network/MockConnectionControl.java
index 924febb..d0bb1fa 100644
--- a/mock/jrummikub/control/network/MockConnectionControl.java
+++ b/mock/jrummikub/control/network/MockConnectionControl.java
@@ -12,6 +12,7 @@ import jrummikub.util.IEvent2;
import jrummikub.util.MockEvent;
import jrummikub.util.MockEvent1;
import jrummikub.util.MockEvent2;
+import jrummikub.view.LoginError;
/** */
public class MockConnectionControl implements IConnectionControl {
@@ -20,7 +21,7 @@ public class MockConnectionControl implements IConnectionControl {
/** */
public MockEvent connectedEvent = new MockEvent();
/** */
- public MockEvent connectionFailedEvent = new MockEvent();
+ public MockEvent1<LoginError> connectionFailedEvent = new MockEvent1<LoginError>();
/** */
public MockEvent1<GameData> gameOfferEvent = new MockEvent1<GameData>();
/** */
@@ -66,7 +67,7 @@ public class MockConnectionControl implements IConnectionControl {
@Override
public void connect() {
if (failOnConnect) {
- connectionFailedEvent.emit();
+ connectionFailedEvent.emit(LoginError.UNKNOWN_ERROR);
} else {
connected = true;
connectedEvent.emit();
@@ -84,7 +85,7 @@ public class MockConnectionControl implements IConnectionControl {
}
@Override
- public IEvent getConnectionFailedEvent() {
+ public IEvent1<LoginError> getConnectionFailedEvent() {
return connectionFailedEvent;
}
diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java
index f283ebd..5440fc8 100644
--- a/mock/jrummikub/view/MockView.java
+++ b/mock/jrummikub/view/MockView.java
@@ -225,6 +225,12 @@ public class MockView implements IView {
}
@Override
+ public IConnectPanel getConnectPanel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
public void setInitialMeldError(int points) {
// TODO Auto-generated method stub
@@ -295,4 +301,10 @@ public class MockView implements IView {
public void load() {
// TODO Auto-generated method stub
}
+
+ @Override
+ public void showConnectPanel(boolean show) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index 7a629af..bc16cb4 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -32,7 +32,7 @@ public class ApplicationControl {
* Creates a new application control
*
* @param view
- * the view to use
+ * the view to use
*/
public ApplicationControl(final IView view) {
this.view = view;
@@ -43,15 +43,16 @@ public class ApplicationControl {
public void handle() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
- tempConnection = view.getQuitWarningPanel().getQuitEvent().add(new IListener() {
- @Override
- public void handle() {
- abortControls();
- startApplication();
- view.showQuitWarningPanel(false);
- tempConnection.remove();
- }
- });
+ tempConnection = view.getQuitWarningPanel().getQuitEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ abortControls();
+ startApplication();
+ view.showQuitWarningPanel(false);
+ tempConnection.remove();
+ }
+ });
}
});
view.getMenuQuitEvent().add(new IListener() {
@@ -89,7 +90,7 @@ public class ApplicationControl {
}
}
});
-
+
view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
@Override
public void handle() {
@@ -97,16 +98,22 @@ public class ApplicationControl {
}
});
- addLoginControlListeners();
+ view.getNetworkGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ abortControls();
+
+ createLoginControl();
+ }
+ });
saveControl.getLoadEvent().add(
new IListener3<GameSettings, GameState, IRoundState>() {
@Override
- public void handle(GameSettings settings,
- GameState gameState, IRoundState roundState) {
+ public void handle(GameSettings settings, GameState gameState,
+ IRoundState roundState) {
abortControls();
- gameControl = new GameControl(settings, saveControl,
- view);
+ gameControl = new GameControl(settings, saveControl, view);
addGameControlListeners(gameControl);
gameControl.continueGame(gameState, roundState);
}
@@ -119,28 +126,21 @@ public class ApplicationControl {
});
}
- private void addLoginControlListeners() {
- view.getNetworkGameEvent().add(new IListener() {
+ private void createLoginControl() {
+ loginControl = new LoginControl(view);
+ loginControl.getLoginEvent().add(new IListener1<LoginData>() {
+ @Override
+ public void handle(LoginData loginData) {
+ createNetworkControl(loginData);
+ }
+ });
+ loginControl.getCancelEvent().add(new IListener() {
@Override
public void handle() {
- abortControls();
-
- loginControl = new LoginControl(view);
- loginControl.getLoginEvent().add(new IListener1<LoginData>() {
- @Override
- public void handle(LoginData loginData) {
- createNetworkControl(loginData);
- }
- });
- loginControl.getCancelEvent().add(new IListener() {
- @Override
- public void handle() {
- startApplication();
- }
- });
- loginControl.startLogin();
+ startApplication();
}
});
+ loginControl.startLogin();
}
private void abortControls() {
@@ -215,6 +215,14 @@ public class ApplicationControl {
}
});
+ networkControl.getBackToLoginEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ networkControl = null;
+ createLoginControl();
+ }
+ });
+
networkControl.startNetwork();
}
}
diff --git a/src/jrummikub/control/LoginControl.java b/src/jrummikub/control/LoginControl.java
index 9355220..ccf6e2e 100644
--- a/src/jrummikub/control/LoginControl.java
+++ b/src/jrummikub/control/LoginControl.java
@@ -27,7 +27,7 @@ public class LoginControl {
* Constructor for login Control
*
* @param view
- * for events which need handling
+ * for events which need handling
*/
public LoginControl(final IView view) {
this.view = view;
@@ -36,18 +36,18 @@ public class LoginControl {
@Override
public void handle(LoginData loginData) {
abort();
+ // TODO connectPanel anzeigen
loginEvent.emit(loginData);
}
}));
- connections.add(view.getLoginPanel().getCancelEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- abort();
- cancelEvent.emit();
- }
- }));
+ connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ abort();
+ cancelEvent.emit();
+ }
+ }));
}
/**
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index acccbdc..54c9512 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -16,6 +16,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
import jrummikub.util.LoginData;
+import jrummikub.view.LoginError;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener;
@@ -46,7 +47,7 @@ public class ConnectionControl implements IConnectionControl {
private volatile MultiUserChat muc;
private Event connectedEvent = new Event();
- private Event connectionFailedEvent = new Event();
+ private Event1<LoginError> connectionFailedEvent = new Event1<LoginError>();
private Event1<GameData> gameOfferEvent = new Event1<GameData>();
private Event1<UUID> gameWithdrawalEvent = new Event1<UUID>();
@@ -72,7 +73,7 @@ public class ConnectionControl implements IConnectionControl {
* Creates new connection control
*
* @param loginData
- * player's login data
+ * player's login data
*/
public ConnectionControl(LoginData loginData) {
this.loginData = loginData;
@@ -91,7 +92,7 @@ public class ConnectionControl implements IConnectionControl {
@Override
public void disconnect() {
connectedEvent = new Event();
- connectionFailedEvent = new Event();
+ connectionFailedEvent = new Event1<LoginError>();
run(new Runnable() {
@Override
public void run() {
@@ -111,7 +112,7 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
- public IEvent getConnectionFailedEvent() {
+ public IEvent1<LoginError> getConnectionFailedEvent() {
return connectionFailedEvent;
}
@@ -252,8 +253,7 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "change_color");
extension.setValue("uuid", uuid.toString());
- extension.setValue("color",
- Base64.encodeObject(color, Base64.GZIP));
+ extension.setValue("color", Base64.encodeObject(color, Base64.GZIP));
}
});
}
@@ -316,8 +316,8 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "game_offer");
extension.setValue("uuid", data.getGameID().toString());
- extension.setValue("gameSettings", Base64.encodeObject(
- data.getGameSettings(), Base64.GZIP));
+ extension.setValue("gameSettings",
+ Base64.encodeObject(data.getGameSettings(), Base64.GZIP));
}
});
}
@@ -340,6 +340,15 @@ public class ConnectionControl implements IConnectionControl {
});
}
+ private static <T> void emitLater(final Event1<T> event, final T arg) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ event.emit(arg);
+ }
+ });
+ }
+
private Message createMessage(PacketExtension extension) {
Message message = muc.createMessage();
message.addExtension(extension);
@@ -355,8 +364,8 @@ public class ConnectionControl implements IConnectionControl {
.getExtension(ELEMENT_NAME, NAMESPACE);
if (((Message) packet).getType() == Message.Type.error) {
- System.err.println("Received error message from '"
- + packet.getFrom() + "'");
+ System.err.println("Received error message from '" + packet.getFrom()
+ + "'");
return;
}
@@ -372,14 +381,13 @@ public class ConnectionControl implements IConnectionControl {
String sender, String messageType) {
if (messageType.equals("game_offer")) {
UUID uuid = UUID.fromString(extension.getValue("uuid"));
- GameSettings settings = (GameSettings) Base64
- .decodeToObject(extension.getValue("gameSettings"));
+ GameSettings settings = (GameSettings) Base64.decodeToObject(extension
+ .getValue("gameSettings"));
GameData gameData = new GameData(uuid, settings, sender);
gameOfferEvent.emit(gameData);
} else if (messageType.equals("game_withdrawal")) {
- gameWithdrawalEvent
- .emit(UUID.fromString(extension.getValue("uuid")));
+ gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid")));
} else if (messageType.equals("game_request")) {
if (offeredGame != null) {
sendGameOffer();
@@ -447,10 +455,26 @@ public class ConnectionControl implements IConnectionControl {
connection.disconnect();
connection = null;
- // TODO Auto-generated catch block
+ XMPPError xmppError = e.getXMPPError();
+
+ if (xmppError != null) {
+ int code = xmppError.getCode();
+ if (code == 504) {
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_HOST);
+ return;
+ } else if (code == 404) {
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_CHANNEL);
+ return;
+ } else if (code == 503) {
+ emitLater(connectionFailedEvent, LoginError.RESOURCE_CONFLICT);
+ return;
+ } else if (code == 401 || code == 402 || code == 407) {
+ emitLater(connectionFailedEvent, LoginError.AUTHENTICATION_FAILED);
+ return;
+ }
+ }
e.printStackTrace();
-
- emitLater(connectionFailedEvent);
+ emitLater(connectionFailedEvent, LoginError.UNKNOWN_ERROR);
}
}
}
@@ -471,8 +495,7 @@ public class ConnectionControl implements IConnectionControl {
break; // Join was successful, break the loop
} catch (XMPPException e) {
XMPPError error = e.getXMPPError();
- if (error.getType() == Type.CANCEL
- && error.getCode() == 409) {
+ if (error.getType() == Type.CANCEL && error.getCode() == 409) {
// There was a conflict, try again with another
// nickname
nickname += "_";
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
index b329b4c..ff23c82 100644
--- a/src/jrummikub/control/network/IConnectionControl.java
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -9,6 +9,7 @@ import jrummikub.util.GameData;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
+import jrummikub.view.LoginError;
interface IConnectionControl {
@@ -20,7 +21,7 @@ interface IConnectionControl {
public IEvent getConnectedEvent();
- public IEvent getConnectionFailedEvent();
+ public IEvent1<LoginError> getConnectionFailedEvent();
public IEvent1<GameData> getGameOfferEvent();
@@ -65,5 +66,4 @@ interface IConnectionControl {
public void endTurn(ITable table);
public void startTurn(IRoundState state);
-
} \ No newline at end of file
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 71000aa..60640db 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -15,6 +15,7 @@ import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.LoginData;
import jrummikub.view.IView;
+import jrummikub.view.LoginError;
/**
* Class dealing with network connection, offering and choice of network games
@@ -24,6 +25,7 @@ public class NetworkControl {
private IView view;
private List<Connection> connections = new ArrayList<Connection>();
private Event stopNetworkEvent = new Event();
+ private Event backToLoginEvent = new Event();
private NetworkSettingsControl settingsControl;
private GameOfferControl gameOfferControl;
@@ -36,11 +38,11 @@ public class NetworkControl {
* Creates a new network control
*
* @param loginData
- * user's login data
+ * user's login data
* @param connectionControl
- * current connection for events and messages
+ * current connection for events and messages
* @param view
- * for events and handlers
+ * for events and handlers
*/
public NetworkControl(final LoginData loginData,
IConnectionControl connectionControl, final IView view) {
@@ -85,7 +87,7 @@ public class NetworkControl {
* Adds the listeners for connection control events
*
* @param view
- * view for events
+ * view for events
*/
public void addConnectionControlListeners(final IView view) {
connections.add(connectionControl.getGameOfferEvent().add(
@@ -133,22 +135,29 @@ public class NetworkControl {
private void addConnectionSetupListeners(final LoginData loginData,
final IView view) {
- connections.add(connectionControl.getConnectedEvent().add(
- new IListener() {
+ connections.add(connectionControl.getConnectedEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ view.getGameListPanel().setChannelName(loginData.getChannelName());
+ view.showGameListPanel(true);
+ }
+ }));
+
+ connections.add(connectionControl.getConnectionFailedEvent().add(
+ new IListener1<LoginError>() {
@Override
- public void handle() {
- view.getGameListPanel().setChannelName(
- loginData.getChannelName());
- view.showGameListPanel(true);
+ public void handle(LoginError error) {
+ view.getConnectPanel().setMode(error);
+ view.showConnectPanel(true);
}
}));
- connections.add(connectionControl.getConnectionFailedEvent().add(
- new IListener() {
+ connections.add(view.getConnectPanel().getCancelEvent()
+ .add(new IListener() {
@Override
public void handle() {
- // TODO Auto-generated method stub
-
+ abort();
+ backToLoginEvent.emit();
}
}));
}
@@ -181,9 +190,11 @@ public class NetworkControl {
}
/**
- * Starts a new network connection with the sepcified data
+ * Starts a new network connection with the specified data
*/
public void startNetwork() {
+ view.showConnectPanel(true);
+ view.getConnectPanel().setMode(null);
connectionControl.connect();
}
@@ -195,6 +206,7 @@ public class NetworkControl {
c.remove();
}
view.showGameListPanel(false);
+ view.showConnectPanel(false);
if (settingsControl != null) {
settingsControl.abort();
@@ -218,6 +230,10 @@ public class NetworkControl {
return stopNetworkEvent;
}
+ public IEvent getBackToLoginEvent() {
+ return backToLoginEvent;
+ }
+
private void createSettingsControl() {
if (settingsControl != null) {
return;
@@ -247,8 +263,7 @@ public class NetworkControl {
if (gameOfferControl != null) {
return;
}
- gameOfferControl = new GameOfferControl(connectionControl, settings,
- view);
+ gameOfferControl = new GameOfferControl(connectionControl, settings, view);
gameOfferControl.getBackEvent().add(new IListener() {
@Override
public void handle() {
diff --git a/src/jrummikub/view/IConnectPanel.java b/src/jrummikub/view/IConnectPanel.java
new file mode 100644
index 0000000..57d0aad
--- /dev/null
+++ b/src/jrummikub/view/IConnectPanel.java
@@ -0,0 +1,11 @@
+package jrummikub.view;
+
+import jrummikub.util.IEvent;
+
+public interface IConnectPanel {
+
+ public void setMode(LoginError error);
+
+ public IEvent getCancelEvent();
+
+}
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 09ab088..9962062 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -59,7 +59,7 @@ public interface IView {
* Sets the current player's name
*
* @param playerName
- * the player name
+ * the player name
*/
public void setCurrentPlayerName(String playerName);
@@ -67,7 +67,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);
@@ -104,7 +104,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);
@@ -112,7 +112,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);
@@ -121,16 +121,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);
@@ -145,13 +145,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
*/
@@ -226,7 +226,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);
@@ -322,4 +322,8 @@ public interface IView {
public IEvent1<File> getLoadFileEvent();
public void load();
+
+ public void showConnectPanel(boolean show);
+
+ public IConnectPanel getConnectPanel();
}
diff --git a/src/jrummikub/view/LoginError.java b/src/jrummikub/view/LoginError.java
new file mode 100644
index 0000000..a67a395
--- /dev/null
+++ b/src/jrummikub/view/LoginError.java
@@ -0,0 +1,18 @@
+package jrummikub.view;
+
+public enum LoginError {
+ /** */
+ UNKNOWN_ERROR,
+ /** */
+ TIMEOUT,
+ /** */
+ CONNECTION_REFUSED,
+ /** */
+ AUTHENTICATION_FAILED,
+ /** */
+ RESOURCE_CONFLICT,
+ /** */
+ UNKNOWN_HOST,
+ /** */
+ UNKNOWN_CHANNEL
+}
diff --git a/src/jrummikub/view/impl/ConnectPanel.java b/src/jrummikub/view/impl/ConnectPanel.java
new file mode 100644
index 0000000..befa687
--- /dev/null
+++ b/src/jrummikub/view/impl/ConnectPanel.java
@@ -0,0 +1,109 @@
+package jrummikub.view.impl;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.SwingConstants;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+import jrummikub.view.IConnectPanel;
+import jrummikub.view.LoginError;
+
+public class ConnectPanel extends JPanel implements IConnectPanel {
+ private JLabel messageLabel;
+ private JProgressBar foobar;
+ private JButton cancelButton;
+
+ private Event cancelEvent = new Event();
+
+ public ConnectPanel() {
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 1;
+ c.weighty = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.CENTER;
+
+ messageLabel = new JLabel();
+ messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+ add(messageLabel, c);
+
+ c.gridy = 1;
+ c.insets = new Insets(5, 5, 5, 5);
+
+ foobar = new JProgressBar();
+ foobar.setIndeterminate(true);
+ add(foobar, c);
+
+ c.gridy = 2;
+
+ cancelButton = new JButton();
+ cancelButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ cancelEvent.emit();
+ }
+ });
+ add(cancelButton, c);
+
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
+ 10, 10, 10, 10)));
+ }
+
+ @Override
+ public void setMode(LoginError error) {
+ if (error == null) {
+ foobar.setVisible(true);
+ messageLabel.setText("Verbindung wird hergestellt");
+ cancelButton.setText("Abbrechen");
+ } else {
+ foobar.setVisible(false);
+ String text = "";
+ switch (error) {
+ case UNKNOWN_ERROR:
+ text = "Ein unbekannter Fehler ist aufgetreten";
+ break;
+ case AUTHENTICATION_FAILED:
+ text = "Die Authentifizierung ist fehlgeschlagen";
+ break;
+ case CONNECTION_REFUSED:
+ text = "Die Verbindung wurde abgelehnt";
+ break;
+ case RESOURCE_CONFLICT:
+ text = "Es gibt bereits einen solchen Spieler";
+ break;
+ case TIMEOUT:
+ text = "Der Server reagiert nicht";
+ break;
+ case UNKNOWN_CHANNEL:
+ text = "Der Channel konnte nicht gefunden werden";
+ break;
+ case UNKNOWN_HOST:
+ text = "Der Server konnte nicht gefunden werden";
+ break;
+ }
+ messageLabel.setText(text);
+ }
+ }
+
+ @Override
+ public IEvent getCancelEvent() {
+ return cancelEvent;
+ }
+
+}
diff --git a/src/jrummikub/view/impl/QuitWarningPanel.java b/src/jrummikub/view/impl/QuitWarningPanel.java
index b7992b0..edc8947 100644
--- a/src/jrummikub/view/impl/QuitWarningPanel.java
+++ b/src/jrummikub/view/impl/QuitWarningPanel.java
@@ -19,7 +19,6 @@ import jrummikub.util.IEvent;
import jrummikub.view.IQuitWarningPanel;
public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
- private JPanel buttonPanel;
private JButton cancelButton;
private JButton quitButton;
private QuitMode quitMode;
@@ -51,8 +50,8 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
c.gridx = 1;
add(quitButton, c);
- 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)));
}
private JButton createButton(String title, final Event event) {
@@ -71,8 +70,7 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
this.quitMode = mode;
switch (quitMode) {
case QUIT_PROCESS:
- messageLabel
- .setText("Beim Beenden geht das aktuelle Spiel verloren");
+ messageLabel.setText("Beim Beenden geht das aktuelle Spiel verloren");
break;
case QUIT_GAME:
messageLabel.setText("Der aktuelle Spielstand geht verloren");
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index b367b65..94cb04f 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
@@ -36,6 +37,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
import jrummikub.util.Pair;
+import jrummikub.view.IConnectPanel;
import jrummikub.view.IGameListPanel;
import jrummikub.view.IHandPanel;
import jrummikub.view.ILoginPanel;
@@ -73,7 +75,7 @@ public class View extends JFrame implements IView {
private GameListPanel gameListPanel;
private SidePanel sidePanel;
private QuitWarningPanel quitWarningPanel;
-
+ private ConnectPanel connectPanel;
private BottomPanelType bottomPanelType;
private JFileChooser chooser;
@@ -132,6 +134,11 @@ public class View extends JFrame implements IView {
}
@Override
+ public IConnectPanel getConnectPanel() {
+ return connectPanel;
+ }
+
+ @Override
public IGameListPanel getGameListPanel() {
return gameListPanel;
}
@@ -150,9 +157,9 @@ public class View extends JFrame implements IView {
public IEvent1<File> getLoadFileEvent() {
return loadFileEvent;
}
-
+
@Override
- public IEvent getLoadEvent(){
+ public IEvent getLoadEvent() {
return loadEvent;
}
@@ -287,7 +294,7 @@ public class View extends JFrame implements IView {
setSize(1000, 700);
setMinimumSize(new Dimension(750, 550));
-
+
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
@@ -312,19 +319,21 @@ public class View extends JFrame implements IView {
loginPanel = new LoginPanel();
loginPanel.setVisible(false);
-
layeredPane.setLayer(loginPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(loginPanel);
gameListPanel = new GameListPanel();
gameListPanel.setVisible(false);
-
layeredPane.setLayer(gameListPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(gameListPanel);
+ connectPanel = new ConnectPanel();
+ connectPanel.setVisible(false);
+ layeredPane.setLayer(connectPanel, JLayeredPane.POPUP_LAYER);
+ layeredPane.add(connectPanel);
+
quitWarningPanel = new QuitWarningPanel();
quitWarningPanel.setVisible(false);
-
layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(quitWarningPanel);
@@ -386,10 +395,6 @@ public class View extends JFrame implements IView {
winPanel.setVisible(false);
mainLayer.add(winPanel);
- quitWarningPanel = new QuitWarningPanel();
- quitWarningPanel.setVisible(false);
- mainLayer.add(quitWarningPanel);
-
sidePanel = new SidePanel();
sidePanel.setVisible(false);
mainLayer.add(sidePanel);
@@ -440,7 +445,8 @@ public class View extends JFrame implements IView {
rescaleSubpanel(loginPanel, 1 / 3.0, 1 / 3.0, 200, 200);
rescaleSubpanel(gameListPanel, 1 / 2.0, 1 / 2.0, 475, 300);
rescaleSubpanel(quitWarningPanel, 1 / 2.0, 1 / 6.0, 400, 150);
-}
+ rescaleSubpanel(connectPanel, 1 / 2.0, 1 / 6.0, 400, 150);
+ }
private void rescaleSubpanel(JPanel sub, double widthFactor,
double heightFactor, int minWidth, int minHeight) {
@@ -505,6 +511,11 @@ public class View extends JFrame implements IView {
}
@Override
+ public void showConnectPanel(boolean show) {
+ connectPanel.setVisible(show);
+ }
+
+ @Override
public void setCurrentPlayerName(String playerName) {
playerPanel.setCurrentPlayerName(playerName);
startTurnPanel.setCurrentPlayerName(playerName);
@@ -600,7 +611,6 @@ public class View extends JFrame implements IView {
@Override
public void setBottomPanel(BottomPanelType type) {
bottomPanelType = type;
-
doSetBottomPanel(type);
}