View-Komponente des Logins für Netzwerk-Spiele

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@396 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-10 16:00:03 +02:00
parent e7ee6778b0
commit 9c281a73c0
4 changed files with 179 additions and 37 deletions

View file

@ -0,0 +1,12 @@
package jrummikub.view;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent3;
public interface ILoginPanel {
public IEvent3<String, String, String> getLoginEvent();
public IEvent getCancelEvent();
}

View file

@ -49,7 +49,7 @@ public interface IView {
* Sets the current player's name * Sets the current player's name
* *
* @param playerName * @param playerName
* the player name * the player name
*/ */
public void setCurrentPlayerName(String playerName); public void setCurrentPlayerName(String playerName);
@ -57,7 +57,7 @@ public interface IView {
* Sets the stones that are to be painted selected * Sets the stones that are to be painted selected
* *
* @param stones * @param stones
* the stones to be painted selected * the stones to be painted selected
*/ */
public void setSelectedStones(Collection<Stone> stones); public void setSelectedStones(Collection<Stone> stones);
@ -86,7 +86,7 @@ public interface IView {
* Shows or hides the game settings panel * Shows or hides the game settings panel
* *
* @param show * @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); public void showSettingsPanel(boolean show);
@ -94,7 +94,7 @@ public interface IView {
* Shows or hides the score panel * Shows or hides the score panel
* *
* @param show * @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); public void showScorePanel(boolean show);
@ -103,16 +103,16 @@ public interface IView {
* along with the name * along with the name
* *
* @param color * @param color
* the current player's color * the current player's color
*/ */
public void setCurrentPlayerColor(Color color); public void setCurrentPlayerColor(Color color);
/** /**
* Is used for the PlayerPanel to display if a player has laid out along with * Is used for the PlayerPanel to display if a player has laid out along
* the name * with 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
*/ */
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut); public void setCurrentPlayerHasLaidOut(boolean hasLaidOut);
@ -127,13 +127,13 @@ public interface IView {
* Sets the bottom panels type * Sets the bottom panels type
* *
* @param type * @param type
* the type of the bottom panel * the type of the bottom panel
*/ */
public void setBottomPanel(BottomPanelType type); public void setBottomPanel(BottomPanelType type);
/** /**
* The menu new game event is emitted when the user selects the new game menu * The menu new game event is emitted when the user selects the new game
* entry * menu entry
* *
* @return the event * @return the event
*/ */
@ -168,7 +168,13 @@ public interface IView {
public void clearView(); public void clearView();
void enablePauseMode(boolean enable); public IEvent getNetworkGameEvent();
public ILoginPanel getLoginPanel();
public void showLoginPanel(boolean show);
public void enablePauseMode(boolean enable);
/** /**
* Different types of bottom panels * Different types of bottom panels
@ -185,4 +191,5 @@ public interface IView {
/** */ /** */
WIN_PANEL WIN_PANEL
} }
} }

View file

@ -0,0 +1,97 @@
package jrummikub.view.impl;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import jrummikub.util.Event;
import jrummikub.util.Event3;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent3;
import jrummikub.view.ILoginPanel;
@SuppressWarnings("serial")
class LoginPanel extends JPanel implements ILoginPanel {
private Event3<String, String, String> loginEvent = new Event3<String, String, String>();
private Event cancelEvent = new Event();
private JTextField userNameField;
private JTextField passwordField;
private JTextField channelNameField;
LoginPanel() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = GridBagConstraints.REMAINDER;
c.weightx = 1;
c.weighty = 1;
userNameField = addInputRow("Benutzername:");
passwordField = addInputRow("Passwort:");
channelNameField = addInputRow("Channel:");
add(Box.createVerticalGlue(), c);
c.gridwidth = 1;
c.weighty = 0;
JButton loginButton = new JButton("Login");
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
loginEvent.emit(userNameField.getText(),
passwordField.getText(), channelNameField.getText());
}
});
add(loginButton, c);
c.gridwidth = GridBagConstraints.REMAINDER;
JButton cancelButton = new JButton("Abbrechen");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
cancelEvent.emit();
}
});
add(cancelButton, c);
setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
new EmptyBorder(10, 10, 10, 10)));
}
@Override
public IEvent3<String, String, String> getLoginEvent() {
return loginEvent;
}
@Override
public IEvent getCancelEvent() {
return cancelEvent;
}
private JTextField addInputRow(String label) {
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.gridwidth = 1;
c.weightx = 1;
c.weighty = 0;
add(new JLabel(label), c);
JTextField textField = new JTextField();
c.gridwidth = GridBagConstraints.REMAINDER;
add(textField, c);
return textField;
}
}

View file

@ -32,6 +32,7 @@ import jrummikub.util.IEvent1;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.IHandPanel; import jrummikub.view.IHandPanel;
import jrummikub.view.ILoginPanel;
import jrummikub.view.IPlayerPanel; import jrummikub.view.IPlayerPanel;
import jrummikub.view.IScorePanel; import jrummikub.view.IScorePanel;
import jrummikub.view.ISettingsPanel; import jrummikub.view.ISettingsPanel;
@ -57,6 +58,7 @@ public class View extends JFrame implements IView {
private PausePanel pausePanel; private PausePanel pausePanel;
private WinPanel winPanel; private WinPanel winPanel;
private SettingsPanel settingsPanel; private SettingsPanel settingsPanel;
private LoginPanel loginPanel;
private ScorePanel scorePanel; private ScorePanel scorePanel;
private BottomPanelType bottomPanelType; private BottomPanelType bottomPanelType;
@ -78,6 +80,11 @@ public class View extends JFrame implements IView {
return settingsPanel; return settingsPanel;
} }
@Override
public ILoginPanel getLoginPanel() {
return loginPanel;
}
@Override @Override
public IScorePanel getScorePanel() { public IScorePanel getScorePanel() {
return scorePanel; return scorePanel;
@ -128,11 +135,17 @@ public class View extends JFrame implements IView {
return pausePanel.getEndPauseEvent(); return pausePanel.getEndPauseEvent();
} }
@Override
public IEvent getNetworkGameEvent() {
return settingsPanel.getNetworkGameEvent();
}
@Override @Override
public void clearView() { public void clearView() {
showScorePanel(false); showScorePanel(false);
showSettingsPanel(false); showSettingsPanel(false);
getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList()); getHandPanel().setStones(
Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets( getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList()); Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList()); setSelectedStones(Collections.<Stone> emptyList());
@ -239,6 +252,12 @@ public class View extends JFrame implements IView {
layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER); layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(settingsPanel); layeredPane.add(settingsPanel);
loginPanel = new LoginPanel();
loginPanel.setVisible(false);
layeredPane.setLayer(loginPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(loginPanel);
scorePanel = new ScorePanel(); scorePanel = new ScorePanel();
scorePanel.setVisible(false); scorePanel.setVisible(false);
layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER);
@ -263,8 +282,8 @@ public class View extends JFrame implements IView {
mainLayer.add(table); mainLayer.add(table);
playerPanel = new PlayerPanel(); playerPanel = new PlayerPanel();
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
Color.BLACK)); 0, Color.BLACK));
mainLayer.add(playerPanel); mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel(); startTurnPanel = new StartTurnPanel();
@ -311,6 +330,7 @@ public class View extends JFrame implements IView {
winPanel.setBounds(0, tableHeight, width, playerPanelHeight); winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2); settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2); scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2);
loginPanel.setBounds(width / 3, height / 3, width / 3, height / 3);
} }
@Override @Override
@ -324,6 +344,11 @@ public class View extends JFrame implements IView {
settingsPanel.setVisible(show); settingsPanel.setVisible(show);
} }
@Override
public void showLoginPanel(boolean show) {
loginPanel.setVisible(show);
}
@Override @Override
public void showScorePanel(boolean show) { public void showScorePanel(boolean show) {
scorePanel.setVisible(show); scorePanel.setVisible(show);
@ -368,24 +393,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() { private List<Pair<Stone, Position>> createDecorationStones() {
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J', Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(2.5f, 0)); -'J', StoneColor.BLACK), new Position(2.5f, 0));
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R', Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
StoneColor.ORANGE), new Position(3.5f, 0)); -'R', StoneColor.ORANGE), new Position(3.5f, 0));
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u', Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
StoneColor.BLUE), new Position(4.5f, 0)); -'u', StoneColor.BLUE), new Position(4.5f, 0));
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m', Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(5.5f, 0)); -'m', StoneColor.RED), new Position(5.5f, 0));
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m', Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
StoneColor.GREEN), new Position(6.5f, 0)); -'m', StoneColor.GREEN), new Position(6.5f, 0));
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i', Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
StoneColor.VIOLET), new Position(7.5f, 0)); -'i', StoneColor.VIOLET), new Position(7.5f, 0));
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k', Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
StoneColor.AQUA), new Position(8.5f, 0)); -'k', StoneColor.AQUA), new Position(8.5f, 0));
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u', Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
StoneColor.GRAY), new Position(9.5f, 0)); -'u', StoneColor.GRAY), new Position(9.5f, 0));
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b', Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(10.5f, 0)); -'b', StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone( Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1)); StoneColor.RED), new Position(2, 1));
@ -400,9 +425,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone( Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1)); StoneColor.BLACK), new Position(11, 1));
return Arrays return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek, stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6); stone5, stone6);
} }
@Override @Override
@ -419,7 +444,8 @@ public class View extends JFrame implements IView {
&& type != BottomPanelType.WIN_PANEL && type != null); && type != BottomPanelType.WIN_PANEL && type != null);
if (type == BottomPanelType.START_GAME_PANEL) { if (type == BottomPanelType.START_GAME_PANEL) {
table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList()); table.setStoneSets(Collections
.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones()); playerPanel.getHandPanel().setStones(createDecorationStones());
} }