From cc4797fd8b894cc7e02346dc93f891cccb4c0a09 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sat, 11 Jun 2011 00:02:42 +0200 Subject: Netzwerk hat Panel mit laufenden Spielen und einem funktionierenden Abbrechen-Button git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@406 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/GameListPanel.java | 111 +++++++++++++++++++++++++++++ src/jrummikub/view/impl/LoginPanel.java | 3 + src/jrummikub/view/impl/View.java | 72 ++++++++++++------- 3 files changed, 161 insertions(+), 25 deletions(-) create mode 100644 src/jrummikub/view/impl/GameListPanel.java (limited to 'src/jrummikub/view/impl') diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java new file mode 100644 index 0000000..d509a6e --- /dev/null +++ b/src/jrummikub/view/impl/GameListPanel.java @@ -0,0 +1,111 @@ +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.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.CompoundBorder; +import javax.swing.border.EmptyBorder; +import javax.swing.border.LineBorder; + +import jrummikub.util.Event; +import jrummikub.util.Event1; +import jrummikub.util.IEvent; +import jrummikub.util.IEvent1; +import jrummikub.view.IGameListPanel; + +class GameListPanel extends JPanel implements IGameListPanel { + private JLabel title; + private JList gameList; + private JButton joinButton; + private JButton openNewGameButton; + private JButton cancelButton; + private Event1 joinEvent = new Event1(); + private Event openNewGameEvent = new Event(); + private Event cancelEvent = new Event(); + + GameListPanel() { + setLayout(new GridBagLayout()); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.gridwidth = GridBagConstraints.REMAINDER; + c.weightx = 1; + c.weighty = 0; + + title = new JLabel(); + add(title, c); + + gameList = new JList(); + c.weighty = 1; + add(new JScrollPane(gameList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c); + + joinButton = new JButton("Beitreten"); + c.weighty = 0; + c.gridwidth = 1; + add(joinButton, c); + joinButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + // joinEvent.emit(); + } + }); + + c.weightx = 0; + add(Box.createHorizontalStrut(10), c); + + openNewGameButton = new JButton("Neues Spiel"); + c.weightx = 1; + add(openNewGameButton, c); + openNewGameButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + openNewGameEvent.emit(); + } + }); + + c.weightx = 0; + add(Box.createHorizontalStrut(10), c); + + cancelButton = new JButton("Abbrechen"); + c.weightx = 1; + c.weighty = 0; + c.gridwidth = GridBagConstraints.REMAINDER; + add(cancelButton, c); + cancelButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + cancelEvent.emit(); + } + }); + + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), + new EmptyBorder(10, 10, 10, 10))); + } + + @Override + public IEvent getOpenNewGameEvent() { + return openNewGameEvent; + } + + @Override + public IEvent1 getJoinEvent() { + return joinEvent; + } + + @Override + public IEvent getCancelEvent() { + return cancelEvent; + } + +} diff --git a/src/jrummikub/view/impl/LoginPanel.java b/src/jrummikub/view/impl/LoginPanel.java index 842bf74..5241896 100644 --- a/src/jrummikub/view/impl/LoginPanel.java +++ b/src/jrummikub/view/impl/LoginPanel.java @@ -41,9 +41,12 @@ class LoginPanel extends JPanel implements ILoginPanel { c.weighty = 1; userNameField = addInputRow("Benutzername:", new JTextField()); + userNameField.setText("test1"); serverNameField = addInputRow("Server:", new JTextField()); + serverNameField.setText("universe-factory.net"); passwordField = addInputRow("Passwort:", new JPasswordField()); channelNameField = addInputRow("Channel:", new JTextField()); + channelNameField.setText("jrummikub@muc.universe-factory.net"); add(Box.createVerticalGlue(), c); c.gridwidth = 1; diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 99e8924..01623d2 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -31,6 +31,7 @@ import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.Pair; +import jrummikub.view.IGameListPanel; import jrummikub.view.IHandPanel; import jrummikub.view.ILoginPanel; import jrummikub.view.IPlayerPanel; @@ -60,6 +61,7 @@ public class View extends JFrame implements IView { private SettingsPanel settingsPanel; private LoginPanel loginPanel; private ScorePanel scorePanel; + private GameListPanel gameListPanel; private BottomPanelType bottomPanelType; @@ -106,6 +108,11 @@ public class View extends JFrame implements IView { return playerPanel; } + @Override + public IGameListPanel getGameListPanel() { + return gameListPanel; + } + @Override public IEvent getMenuNewGameEvent() { return menuNewGameEvent; @@ -146,7 +153,9 @@ public class View extends JFrame implements IView { showScorePanel(false); showSettingsPanel(false); showLoginPanel(false); - getHandPanel().setStones(Collections.> emptyList()); + showGameListPanel(false); + getHandPanel().setStones( + Collections.> emptyList()); getTablePanel().setStoneSets( Collections.> emptyList()); setSelectedStones(Collections. emptyList()); @@ -249,6 +258,12 @@ public class View extends JFrame implements IView { layeredPane.setLayer(loginPanel, JLayeredPane.POPUP_LAYER); layeredPane.add(loginPanel); + gameListPanel = new GameListPanel(); + gameListPanel.setVisible(false); + + layeredPane.setLayer(gameListPanel, JLayeredPane.POPUP_LAYER); + layeredPane.add(gameListPanel); + scorePanel = new ScorePanel(); scorePanel.setVisible(false); layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); @@ -291,8 +306,8 @@ public class View extends JFrame implements IView { mainLayer.add(table); playerPanel = new PlayerPanel(); - playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, - Color.BLACK)); + playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, + 0, Color.BLACK)); mainLayer.add(playerPanel); startTurnPanel = new StartTurnPanel(); @@ -340,6 +355,7 @@ public class View extends JFrame implements IView { settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2); scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2); loginPanel.setBounds(width / 3, height / 3, width / 3, height / 3); + gameListPanel.setBounds(width / 4, height / 4, width / 2, height / 2); } @Override @@ -362,6 +378,11 @@ public class View extends JFrame implements IView { loginPanel.setVisible(show); } + @Override + public void showGameListPanel(boolean show) { + gameListPanel.setVisible(show); + } + @Override public void showScorePanel(boolean show) { scorePanel.setVisible(show); @@ -406,24 +427,24 @@ public class View extends JFrame implements IView { @SuppressWarnings("unchecked") private List> createDecorationStones() { - Pair stoneJ = new Pair(new Stone(-'J', - StoneColor.BLACK), new Position(2.5f, 0)); - Pair stoneR = new Pair(new Stone(-'R', - StoneColor.ORANGE), new Position(3.5f, 0)); - Pair stoneu1 = new Pair(new Stone(-'u', - StoneColor.BLUE), new Position(4.5f, 0)); - Pair stonem1 = new Pair(new Stone(-'m', - StoneColor.RED), new Position(5.5f, 0)); - Pair stonem2 = new Pair(new Stone(-'m', - StoneColor.GREEN), new Position(6.5f, 0)); - Pair stonei = new Pair(new Stone(-'i', - StoneColor.VIOLET), new Position(7.5f, 0)); - Pair stonek = new Pair(new Stone(-'k', - StoneColor.AQUA), new Position(8.5f, 0)); - Pair stoneu2 = new Pair(new Stone(-'u', - StoneColor.GRAY), new Position(9.5f, 0)); - Pair stoneb = new Pair(new Stone(-'b', - StoneColor.BLACK), new Position(10.5f, 0)); + Pair stoneJ = new Pair(new Stone( + -'J', StoneColor.BLACK), new Position(2.5f, 0)); + Pair stoneR = new Pair(new Stone( + -'R', StoneColor.ORANGE), new Position(3.5f, 0)); + Pair stoneu1 = new Pair(new Stone( + -'u', StoneColor.BLUE), new Position(4.5f, 0)); + Pair stonem1 = new Pair(new Stone( + -'m', StoneColor.RED), new Position(5.5f, 0)); + Pair stonem2 = new Pair(new Stone( + -'m', StoneColor.GREEN), new Position(6.5f, 0)); + Pair stonei = new Pair(new Stone( + -'i', StoneColor.VIOLET), new Position(7.5f, 0)); + Pair stonek = new Pair(new Stone( + -'k', StoneColor.AQUA), new Position(8.5f, 0)); + Pair stoneu2 = new Pair(new Stone( + -'u', StoneColor.GRAY), new Position(9.5f, 0)); + Pair stoneb = new Pair(new Stone( + -'b', StoneColor.BLACK), new Position(10.5f, 0)); Pair stone1 = new Pair(new Stone( StoneColor.RED), new Position(2, 1)); @@ -438,9 +459,9 @@ public class View extends JFrame implements IView { Pair stone6 = new Pair(new Stone( StoneColor.BLACK), new Position(11, 1)); - return Arrays - .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek, - stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6); + return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, + stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4, + stone5, stone6); } @Override @@ -457,7 +478,8 @@ public class View extends JFrame implements IView { && type != BottomPanelType.WIN_PANEL && type != null); if (type == BottomPanelType.START_GAME_PANEL) { - table.setStoneSets(Collections.> emptyList()); + table.setStoneSets(Collections + .> emptyList()); playerPanel.getHandPanel().setStones(createDecorationStones()); } -- cgit v1.2.3