diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-20 03:06:46 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-20 03:06:46 +0200 |
commit | 4df5c0e665991dd19a2f25ee513c3ff85a672c55 (patch) | |
tree | 1da402f1c8f98d1a67cfb887f66c2b17d008560a /src/jrummikub/view/impl | |
parent | ace7175f1a57f3dc88a861842969e84efacf65ad (diff) | |
download | JRummikub-4df5c0e665991dd19a2f25ee513c3ff85a672c55.tar JRummikub-4df5c0e665991dd19a2f25ee513c3ff85a672c55.zip |
Implemented login error messages
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@500 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r-- | src/jrummikub/view/impl/ConnectPanel.java | 109 | ||||
-rw-r--r-- | src/jrummikub/view/impl/QuitWarningPanel.java | 8 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 36 |
3 files changed, 135 insertions, 18 deletions
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); } |