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

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

View file

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

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;
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");

View file

@ -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;
@ -131,6 +133,11 @@ public class View extends JFrame implements IView {
return quitWarningPanel;
}
@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) {
@ -504,6 +510,11 @@ public class View extends JFrame implements IView {
quitWarningPanel.setVisible(show);
}
@Override
public void showConnectPanel(boolean show) {
connectPanel.setVisible(show);
}
@Override
public void setCurrentPlayerName(String playerName) {
playerPanel.setCurrentPlayerName(playerName);
@ -600,7 +611,6 @@ public class View extends JFrame implements IView {
@Override
public void setBottomPanel(BottomPanelType type) {
bottomPanelType = type;
doSetBottomPanel(type);
}