From 82eb3eb24ef823d89e5328089cea5c41bd465a50 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 10 Jun 2011 17:43:15 +0200 Subject: Add network game menu item git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@400 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/View.java | 109 ++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 51 deletions(-) (limited to 'src/jrummikub/view') diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index ab6b4c2..8ef8e50 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -68,6 +68,7 @@ public class View extends JFrame implements IView { private Event menuNewGameEvent = new Event(); private Event menuQuitEvent = new Event(); + private Event networkGameEvent = new Event(); private Event1 loadEvent = new Event1(); private Event1 saveEvent = new Event1(); @@ -137,7 +138,7 @@ public class View extends JFrame implements IView { @Override public IEvent getNetworkGameEvent() { - return settingsPanel.getNetworkGameEvent(); + return networkGameEvent; } @Override @@ -145,8 +146,7 @@ public class View extends JFrame implements IView { showScorePanel(false); showSettingsPanel(false); showLoginPanel(false); - getHandPanel().setStones( - Collections.> emptyList()); + getHandPanel().setStones(Collections.> emptyList()); getTablePanel().setStoneSets( Collections.> emptyList()); setSelectedStones(Collections. emptyList()); @@ -165,14 +165,8 @@ public class View extends JFrame implements IView { JMenu gameMenu = new JMenu("Spiel"); menuBar.add(gameMenu); - JMenuItem newItem = new JMenuItem("Neu"); - newItem.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - menuNewGameEvent.emit(); - } - }); - gameMenu.add(newItem); + gameMenu.add(createMenuItem("Neu", menuNewGameEvent)); + gameMenu.add(createMenuItem("Netzwerkspiel...", networkGameEvent)); gameMenu.addSeparator(); @@ -195,16 +189,20 @@ public class View extends JFrame implements IView { gameMenu.addSeparator(); - JMenuItem quitItem = new JMenuItem("Beenden"); - quitItem.addActionListener(new ActionListener() { + gameMenu.add(createMenuItem("Beenden", menuQuitEvent)); + + setJMenuBar(menuBar); + } + + private JMenuItem createMenuItem(String text, final Event event) { + JMenuItem item = new JMenuItem(text); + item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - menuQuitEvent.emit(); + event.emit(); } }); - gameMenu.add(quitItem); - - setJMenuBar(menuBar); + return item; } private void load() { @@ -240,15 +238,7 @@ public class View extends JFrame implements IView { createMainLayer(); - settingsPanel = new SettingsPanel(); - settingsPanel.setVisible(false); - - settingsPanel.getLoadGameEvent().add(new IListener() { - @Override - public void handle() { - load(); - } - }); + createSettingsPanel(); layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER); layeredPane.add(settingsPanel); @@ -274,6 +264,24 @@ public class View extends JFrame implements IView { setVisible(true); } + private void createSettingsPanel() { + settingsPanel = new SettingsPanel(); + settingsPanel.setVisible(false); + + settingsPanel.getNetworkGameEvent().add(new IListener() { + @Override + public void handle() { + networkGameEvent.emit(); + } + }); + settingsPanel.getLoadGameEvent().add(new IListener() { + @Override + public void handle() { + load(); + } + }); + } + private void createMainLayer() { mainLayer = new JPanel(); mainLayer.setLayout(null); @@ -283,8 +291,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(); @@ -394,24 +402,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)); @@ -426,9 +434,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 @@ -445,8 +453,7 @@ 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