Implemented login error messages

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@500 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Bennet Gerlach 2011-06-20 03:06:46 +02:00
parent ace7175f1a
commit 4df5c0e665
13 changed files with 330 additions and 121 deletions

View file

@ -12,6 +12,7 @@ import jrummikub.util.IEvent2;
import jrummikub.util.MockEvent; import jrummikub.util.MockEvent;
import jrummikub.util.MockEvent1; import jrummikub.util.MockEvent1;
import jrummikub.util.MockEvent2; import jrummikub.util.MockEvent2;
import jrummikub.view.LoginError;
/** */ /** */
public class MockConnectionControl implements IConnectionControl { public class MockConnectionControl implements IConnectionControl {
@ -20,7 +21,7 @@ public class MockConnectionControl implements IConnectionControl {
/** */ /** */
public MockEvent connectedEvent = new MockEvent(); public MockEvent connectedEvent = new MockEvent();
/** */ /** */
public MockEvent connectionFailedEvent = new MockEvent(); public MockEvent1<LoginError> connectionFailedEvent = new MockEvent1<LoginError>();
/** */ /** */
public MockEvent1<GameData> gameOfferEvent = new MockEvent1<GameData>(); public MockEvent1<GameData> gameOfferEvent = new MockEvent1<GameData>();
/** */ /** */
@ -66,7 +67,7 @@ public class MockConnectionControl implements IConnectionControl {
@Override @Override
public void connect() { public void connect() {
if (failOnConnect) { if (failOnConnect) {
connectionFailedEvent.emit(); connectionFailedEvent.emit(LoginError.UNKNOWN_ERROR);
} else { } else {
connected = true; connected = true;
connectedEvent.emit(); connectedEvent.emit();
@ -84,7 +85,7 @@ public class MockConnectionControl implements IConnectionControl {
} }
@Override @Override
public IEvent getConnectionFailedEvent() { public IEvent1<LoginError> getConnectionFailedEvent() {
return connectionFailedEvent; return connectionFailedEvent;
} }

View file

@ -224,6 +224,12 @@ public class MockView implements IView {
return gameListPanel; return gameListPanel;
} }
@Override
public IConnectPanel getConnectPanel() {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public void setInitialMeldError(int points) { public void setInitialMeldError(int points) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -295,4 +301,10 @@ public class MockView implements IView {
public void load() { public void load() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void showConnectPanel(boolean show) {
// TODO Auto-generated method stub
}
} }

View file

@ -43,7 +43,8 @@ public class ApplicationControl {
public void handle() { public void handle() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME); view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true); view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent().add(new IListener() { tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override @Override
public void handle() { public void handle() {
abortControls(); abortControls();
@ -97,16 +98,22 @@ public class ApplicationControl {
} }
}); });
addLoginControlListeners(); view.getNetworkGameEvent().add(new IListener() {
@Override
public void handle() {
abortControls();
createLoginControl();
}
});
saveControl.getLoadEvent().add( saveControl.getLoadEvent().add(
new IListener3<GameSettings, GameState, IRoundState>() { new IListener3<GameSettings, GameState, IRoundState>() {
@Override @Override
public void handle(GameSettings settings, public void handle(GameSettings settings, GameState gameState,
GameState gameState, IRoundState roundState) { IRoundState roundState) {
abortControls(); abortControls();
gameControl = new GameControl(settings, saveControl, gameControl = new GameControl(settings, saveControl, view);
view);
addGameControlListeners(gameControl); addGameControlListeners(gameControl);
gameControl.continueGame(gameState, roundState); gameControl.continueGame(gameState, roundState);
} }
@ -119,12 +126,7 @@ public class ApplicationControl {
}); });
} }
private void addLoginControlListeners() { private void createLoginControl() {
view.getNetworkGameEvent().add(new IListener() {
@Override
public void handle() {
abortControls();
loginControl = new LoginControl(view); loginControl = new LoginControl(view);
loginControl.getLoginEvent().add(new IListener1<LoginData>() { loginControl.getLoginEvent().add(new IListener1<LoginData>() {
@Override @Override
@ -140,8 +142,6 @@ public class ApplicationControl {
}); });
loginControl.startLogin(); loginControl.startLogin();
} }
});
}
private void abortControls() { private void abortControls() {
if (settingsControl != null) { if (settingsControl != null) {
@ -215,6 +215,14 @@ public class ApplicationControl {
} }
}); });
networkControl.getBackToLoginEvent().add(new IListener() {
@Override
public void handle() {
networkControl = null;
createLoginControl();
}
});
networkControl.startNetwork(); networkControl.startNetwork();
} }
} }

View file

@ -36,12 +36,12 @@ public class LoginControl {
@Override @Override
public void handle(LoginData loginData) { public void handle(LoginData loginData) {
abort(); abort();
// TODO connectPanel anzeigen
loginEvent.emit(loginData); loginEvent.emit(loginData);
} }
})); }));
connections.add(view.getLoginPanel().getCancelEvent() connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() {
.add(new IListener() {
@Override @Override
public void handle() { public void handle() {
abort(); abort();

View file

@ -16,6 +16,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2; import jrummikub.util.IEvent2;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.LoginError;
import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.PacketListener;
@ -46,7 +47,7 @@ public class ConnectionControl implements IConnectionControl {
private volatile MultiUserChat muc; private volatile MultiUserChat muc;
private Event connectedEvent = new Event(); 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<GameData> gameOfferEvent = new Event1<GameData>();
private Event1<UUID> gameWithdrawalEvent = new Event1<UUID>(); private Event1<UUID> gameWithdrawalEvent = new Event1<UUID>();
@ -91,7 +92,7 @@ public class ConnectionControl implements IConnectionControl {
@Override @Override
public void disconnect() { public void disconnect() {
connectedEvent = new Event(); connectedEvent = new Event();
connectionFailedEvent = new Event(); connectionFailedEvent = new Event1<LoginError>();
run(new Runnable() { run(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -111,7 +112,7 @@ public class ConnectionControl implements IConnectionControl {
} }
@Override @Override
public IEvent getConnectionFailedEvent() { public IEvent1<LoginError> getConnectionFailedEvent() {
return connectionFailedEvent; return connectionFailedEvent;
} }
@ -252,8 +253,7 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) { protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "change_color"); extension.setValue("messageType", "change_color");
extension.setValue("uuid", uuid.toString()); extension.setValue("uuid", uuid.toString());
extension.setValue("color", extension.setValue("color", Base64.encodeObject(color, Base64.GZIP));
Base64.encodeObject(color, Base64.GZIP));
} }
}); });
} }
@ -316,8 +316,8 @@ public class ConnectionControl implements IConnectionControl {
protected void addData(DefaultPacketExtension extension) { protected void addData(DefaultPacketExtension extension) {
extension.setValue("messageType", "game_offer"); extension.setValue("messageType", "game_offer");
extension.setValue("uuid", data.getGameID().toString()); extension.setValue("uuid", data.getGameID().toString());
extension.setValue("gameSettings", Base64.encodeObject( extension.setValue("gameSettings",
data.getGameSettings(), Base64.GZIP)); 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) { private Message createMessage(PacketExtension extension) {
Message message = muc.createMessage(); Message message = muc.createMessage();
message.addExtension(extension); message.addExtension(extension);
@ -355,8 +364,8 @@ public class ConnectionControl implements IConnectionControl {
.getExtension(ELEMENT_NAME, NAMESPACE); .getExtension(ELEMENT_NAME, NAMESPACE);
if (((Message) packet).getType() == Message.Type.error) { if (((Message) packet).getType() == Message.Type.error) {
System.err.println("Received error message from '" System.err.println("Received error message from '" + packet.getFrom()
+ packet.getFrom() + "'"); + "'");
return; return;
} }
@ -372,14 +381,13 @@ public class ConnectionControl implements IConnectionControl {
String sender, String messageType) { String sender, String messageType) {
if (messageType.equals("game_offer")) { if (messageType.equals("game_offer")) {
UUID uuid = UUID.fromString(extension.getValue("uuid")); UUID uuid = UUID.fromString(extension.getValue("uuid"));
GameSettings settings = (GameSettings) Base64 GameSettings settings = (GameSettings) Base64.decodeToObject(extension
.decodeToObject(extension.getValue("gameSettings")); .getValue("gameSettings"));
GameData gameData = new GameData(uuid, settings, sender); GameData gameData = new GameData(uuid, settings, sender);
gameOfferEvent.emit(gameData); gameOfferEvent.emit(gameData);
} else if (messageType.equals("game_withdrawal")) { } else if (messageType.equals("game_withdrawal")) {
gameWithdrawalEvent gameWithdrawalEvent.emit(UUID.fromString(extension.getValue("uuid")));
.emit(UUID.fromString(extension.getValue("uuid")));
} else if (messageType.equals("game_request")) { } else if (messageType.equals("game_request")) {
if (offeredGame != null) { if (offeredGame != null) {
sendGameOffer(); sendGameOffer();
@ -447,10 +455,26 @@ public class ConnectionControl implements IConnectionControl {
connection.disconnect(); connection.disconnect();
connection = null; connection = null;
// TODO Auto-generated catch block XMPPError xmppError = e.getXMPPError();
e.printStackTrace();
emitLater(connectionFailedEvent); 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, LoginError.UNKNOWN_ERROR);
} }
} }
} }
@ -471,8 +495,7 @@ public class ConnectionControl implements IConnectionControl {
break; // Join was successful, break the loop break; // Join was successful, break the loop
} catch (XMPPException e) { } catch (XMPPException e) {
XMPPError error = e.getXMPPError(); XMPPError error = e.getXMPPError();
if (error.getType() == Type.CANCEL if (error.getType() == Type.CANCEL && error.getCode() == 409) {
&& error.getCode() == 409) {
// There was a conflict, try again with another // There was a conflict, try again with another
// nickname // nickname
nickname += "_"; nickname += "_";

View file

@ -9,6 +9,7 @@ import jrummikub.util.GameData;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2; import jrummikub.util.IEvent2;
import jrummikub.view.LoginError;
interface IConnectionControl { interface IConnectionControl {
@ -20,7 +21,7 @@ interface IConnectionControl {
public IEvent getConnectedEvent(); public IEvent getConnectedEvent();
public IEvent getConnectionFailedEvent(); public IEvent1<LoginError> getConnectionFailedEvent();
public IEvent1<GameData> getGameOfferEvent(); public IEvent1<GameData> getGameOfferEvent();
@ -65,5 +66,4 @@ interface IConnectionControl {
public void endTurn(ITable table); public void endTurn(ITable table);
public void startTurn(IRoundState state); public void startTurn(IRoundState state);
} }

View file

@ -15,6 +15,7 @@ import jrummikub.util.IListener;
import jrummikub.util.IListener1; import jrummikub.util.IListener1;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.IView; import jrummikub.view.IView;
import jrummikub.view.LoginError;
/** /**
* Class dealing with network connection, offering and choice of network games * Class dealing with network connection, offering and choice of network games
@ -24,6 +25,7 @@ public class NetworkControl {
private IView view; private IView view;
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
private Event stopNetworkEvent = new Event(); private Event stopNetworkEvent = new Event();
private Event backToLoginEvent = new Event();
private NetworkSettingsControl settingsControl; private NetworkSettingsControl settingsControl;
private GameOfferControl gameOfferControl; private GameOfferControl gameOfferControl;
@ -133,22 +135,29 @@ public class NetworkControl {
private void addConnectionSetupListeners(final LoginData loginData, private void addConnectionSetupListeners(final LoginData loginData,
final IView view) { final IView view) {
connections.add(connectionControl.getConnectedEvent().add( connections.add(connectionControl.getConnectedEvent().add(new IListener() {
new IListener() {
@Override @Override
public void handle() { public void handle() {
view.getGameListPanel().setChannelName( view.getGameListPanel().setChannelName(loginData.getChannelName());
loginData.getChannelName());
view.showGameListPanel(true); view.showGameListPanel(true);
} }
})); }));
connections.add(connectionControl.getConnectionFailedEvent().add( connections.add(connectionControl.getConnectionFailedEvent().add(
new IListener() { new IListener1<LoginError>() {
@Override
public void handle(LoginError error) {
view.getConnectPanel().setMode(error);
view.showConnectPanel(true);
}
}));
connections.add(view.getConnectPanel().getCancelEvent()
.add(new IListener() {
@Override @Override
public void handle() { 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() { public void startNetwork() {
view.showConnectPanel(true);
view.getConnectPanel().setMode(null);
connectionControl.connect(); connectionControl.connect();
} }
@ -195,6 +206,7 @@ public class NetworkControl {
c.remove(); c.remove();
} }
view.showGameListPanel(false); view.showGameListPanel(false);
view.showConnectPanel(false);
if (settingsControl != null) { if (settingsControl != null) {
settingsControl.abort(); settingsControl.abort();
@ -218,6 +230,10 @@ public class NetworkControl {
return stopNetworkEvent; return stopNetworkEvent;
} }
public IEvent getBackToLoginEvent() {
return backToLoginEvent;
}
private void createSettingsControl() { private void createSettingsControl() {
if (settingsControl != null) { if (settingsControl != null) {
return; return;
@ -247,8 +263,7 @@ public class NetworkControl {
if (gameOfferControl != null) { if (gameOfferControl != null) {
return; return;
} }
gameOfferControl = new GameOfferControl(connectionControl, settings, gameOfferControl = new GameOfferControl(connectionControl, settings, view);
view);
gameOfferControl.getBackEvent().add(new IListener() { gameOfferControl.getBackEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {

View file

@ -0,0 +1,11 @@
package jrummikub.view;
import jrummikub.util.IEvent;
public interface IConnectPanel {
public void setMode(LoginError error);
public IEvent getCancelEvent();
}

View file

@ -126,8 +126,8 @@ public interface IView {
public void setCurrentPlayerColor(Color color); public void setCurrentPlayerColor(Color color);
/** /**
* Is used for the PlayerPanel to display if a player has laid out along * Is used for the PlayerPanel to display if a player has laid out along with
* with the name * the name
* *
* @param hasLaidOut * @param hasLaidOut
* specifies if the current player has laid out or not * specifies if the current player has laid out or not
@ -150,8 +150,8 @@ public interface IView {
public void setBottomPanel(BottomPanelType type); public void setBottomPanel(BottomPanelType type);
/** /**
* The menu new game event is emitted when the user selects the new game * The menu new game event is emitted when the user selects the new game menu
* menu entry * entry
* *
* @return the event * @return the event
*/ */
@ -322,4 +322,8 @@ public interface IView {
public IEvent1<File> getLoadFileEvent(); public IEvent1<File> getLoadFileEvent();
public void load(); public void load();
public void showConnectPanel(boolean show);
public IConnectPanel getConnectPanel();
} }

View file

@ -0,0 +1,18 @@
package jrummikub.view;
public enum LoginError {
/** */
UNKNOWN_ERROR,
/** */
TIMEOUT,
/** */
CONNECTION_REFUSED,
/** */
AUTHENTICATION_FAILED,
/** */
RESOURCE_CONFLICT,
/** */
UNKNOWN_HOST,
/** */
UNKNOWN_CHANNEL
}

View file

@ -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;
}
}

View file

@ -19,7 +19,6 @@ import jrummikub.util.IEvent;
import jrummikub.view.IQuitWarningPanel; import jrummikub.view.IQuitWarningPanel;
public class QuitWarningPanel extends JPanel implements IQuitWarningPanel { public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
private JPanel buttonPanel;
private JButton cancelButton; private JButton cancelButton;
private JButton quitButton; private JButton quitButton;
private QuitMode quitMode; private QuitMode quitMode;
@ -51,8 +50,8 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
c.gridx = 1; c.gridx = 1;
add(quitButton, c); add(quitButton, c);
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
new EmptyBorder(10, 10, 10, 10))); 10, 10, 10, 10)));
} }
private JButton createButton(String title, final Event event) { private JButton createButton(String title, final Event event) {
@ -71,8 +70,7 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
this.quitMode = mode; this.quitMode = mode;
switch (quitMode) { switch (quitMode) {
case QUIT_PROCESS: case QUIT_PROCESS:
messageLabel messageLabel.setText("Beim Beenden geht das aktuelle Spiel verloren");
.setText("Beim Beenden geht das aktuelle Spiel verloren");
break; break;
case QUIT_GAME: case QUIT_GAME:
messageLabel.setText("Der aktuelle Spielstand geht verloren"); messageLabel.setText("Der aktuelle Spielstand geht verloren");

View file

@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.swing.JComponent;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
@ -36,6 +37,7 @@ import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.IConnectPanel;
import jrummikub.view.IGameListPanel; import jrummikub.view.IGameListPanel;
import jrummikub.view.IHandPanel; import jrummikub.view.IHandPanel;
import jrummikub.view.ILoginPanel; import jrummikub.view.ILoginPanel;
@ -73,7 +75,7 @@ public class View extends JFrame implements IView {
private GameListPanel gameListPanel; private GameListPanel gameListPanel;
private SidePanel sidePanel; private SidePanel sidePanel;
private QuitWarningPanel quitWarningPanel; private QuitWarningPanel quitWarningPanel;
private ConnectPanel connectPanel;
private BottomPanelType bottomPanelType; private BottomPanelType bottomPanelType;
private JFileChooser chooser; private JFileChooser chooser;
@ -131,6 +133,11 @@ public class View extends JFrame implements IView {
return quitWarningPanel; return quitWarningPanel;
} }
@Override
public IConnectPanel getConnectPanel() {
return connectPanel;
}
@Override @Override
public IGameListPanel getGameListPanel() { public IGameListPanel getGameListPanel() {
return gameListPanel; return gameListPanel;
@ -152,7 +159,7 @@ public class View extends JFrame implements IView {
} }
@Override @Override
public IEvent getLoadEvent(){ public IEvent getLoadEvent() {
return loadEvent; return loadEvent;
} }
@ -312,19 +319,21 @@ public class View extends JFrame implements IView {
loginPanel = new LoginPanel(); loginPanel = new LoginPanel();
loginPanel.setVisible(false); loginPanel.setVisible(false);
layeredPane.setLayer(loginPanel, JLayeredPane.POPUP_LAYER); layeredPane.setLayer(loginPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(loginPanel); layeredPane.add(loginPanel);
gameListPanel = new GameListPanel(); gameListPanel = new GameListPanel();
gameListPanel.setVisible(false); gameListPanel.setVisible(false);
layeredPane.setLayer(gameListPanel, JLayeredPane.POPUP_LAYER); layeredPane.setLayer(gameListPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(gameListPanel); layeredPane.add(gameListPanel);
connectPanel = new ConnectPanel();
connectPanel.setVisible(false);
layeredPane.setLayer(connectPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(connectPanel);
quitWarningPanel = new QuitWarningPanel(); quitWarningPanel = new QuitWarningPanel();
quitWarningPanel.setVisible(false); quitWarningPanel.setVisible(false);
layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER); layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(quitWarningPanel); layeredPane.add(quitWarningPanel);
@ -386,10 +395,6 @@ public class View extends JFrame implements IView {
winPanel.setVisible(false); winPanel.setVisible(false);
mainLayer.add(winPanel); mainLayer.add(winPanel);
quitWarningPanel = new QuitWarningPanel();
quitWarningPanel.setVisible(false);
mainLayer.add(quitWarningPanel);
sidePanel = new SidePanel(); sidePanel = new SidePanel();
sidePanel.setVisible(false); sidePanel.setVisible(false);
mainLayer.add(sidePanel); 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(loginPanel, 1 / 3.0, 1 / 3.0, 200, 200);
rescaleSubpanel(gameListPanel, 1 / 2.0, 1 / 2.0, 475, 300); rescaleSubpanel(gameListPanel, 1 / 2.0, 1 / 2.0, 475, 300);
rescaleSubpanel(quitWarningPanel, 1 / 2.0, 1 / 6.0, 400, 150); 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, private void rescaleSubpanel(JPanel sub, double widthFactor,
double heightFactor, int minWidth, int minHeight) { double heightFactor, int minWidth, int minHeight) {
@ -504,6 +510,11 @@ public class View extends JFrame implements IView {
quitWarningPanel.setVisible(show); quitWarningPanel.setVisible(show);
} }
@Override
public void showConnectPanel(boolean show) {
connectPanel.setVisible(show);
}
@Override @Override
public void setCurrentPlayerName(String playerName) { public void setCurrentPlayerName(String playerName) {
playerPanel.setCurrentPlayerName(playerName); playerPanel.setCurrentPlayerName(playerName);
@ -600,7 +611,6 @@ public class View extends JFrame implements IView {
@Override @Override
public void setBottomPanel(BottomPanelType type) { public void setBottomPanel(BottomPanelType type) {
bottomPanelType = type; bottomPanelType = type;
doSetBottomPanel(type); doSetBottomPanel(type);
} }