diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/control/ApplicationControl.java | 9 | ||||
-rw-r--r-- | src/jrummikub/view/IView.java | 32 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 104 |
3 files changed, 127 insertions, 18 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index cf9a8ca..0f73310 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -17,10 +17,17 @@ public class ApplicationControl { * Creates a new application control * * @param view - * the view to use + * the view to use */ public ApplicationControl(IView view) { this.view = view; + + view.getMenuQuitEvent().add(new IListener() { + @Override + public void handle() { + System.exit(0); + } + }); } /** diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index ab86b4b..1c95ad4 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -144,4 +144,36 @@ public interface IView { /** */ WIN_PANEL } + + /** + * The menu new game event is emitted when the user selects the new game menu + * entry + * + * @return the event + */ + public IEvent getMenuNewGameEvent(); + + /** + * The menu load event is emitted when the user selects the load menu + * entry + * + * @return the event + */ + public IEvent getMenuLoadEvent(); + + /** + * The menu save event is emitted when the user selects the save menu + * entry + * + * @return the event + */ + public IEvent getMenuSaveEvent(); + + /** + * The menu quit event is emitted when the user selects the quit menu + * entry + * + * @return the event + */ + public IEvent getMenuQuitEvent(); } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 45f825a..0bc7120 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -1,7 +1,8 @@ package jrummikub.view.impl; import java.awt.Color; -import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.Arrays; @@ -11,6 +12,9 @@ import java.util.List; import javax.swing.JFrame; import javax.swing.JLayeredPane; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.border.MatteBorder; @@ -18,6 +22,7 @@ import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.model.StoneColor; import jrummikub.model.StoneSet; +import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.util.Pair; import jrummikub.view.IHandPanel; @@ -32,8 +37,13 @@ import jrummikub.view.IView; */ @SuppressWarnings("serial") public class View extends JFrame implements IView { + private final static float PLAYER_PANEL_RATIO = 0.14f; + private final static int PLAYER_PANEL_BORDER_WIDTH = 1; + private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH; + private JLayeredPane layeredPane; private JPanel mainLayer; + private JMenuBar menuBar; private TablePanel table; private PlayerPanel playerPanel; @@ -42,9 +52,10 @@ public class View extends JFrame implements IView { private SettingsPanel settingsPanel; private ScorePanel scorePanel; - private final static float PLAYER_PANEL_RATIO = 0.14f; - private final static int PLAYER_PANEL_BORDER_WIDTH = 1; - private final static int PLAYER_PANEL_MAX_HEIGHT = 180 + PLAYER_PANEL_BORDER_WIDTH; + private Event menuNewGameEvent = new Event(); + private Event menuLoadEvent = new Event(); + private Event menuSaveEvent = new Event(); + private Event menuQuitEvent = new Event(); private static int even(double d) { return 2 * (int) (d / 2); @@ -75,6 +86,74 @@ public class View extends JFrame implements IView { return playerPanel; } + @Override + public IEvent getMenuNewGameEvent() { + return menuNewGameEvent; + } + + @Override + public IEvent getMenuLoadEvent() { + return menuLoadEvent; + } + + @Override + public IEvent getMenuSaveEvent() { + return menuSaveEvent; + } + + @Override + public IEvent getMenuQuitEvent() { + return menuQuitEvent; + } + + private void createMenuBar() { + menuBar = new JMenuBar(); + + 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.addSeparator(); + + JMenuItem loadItem = new JMenuItem("Laden..."); + loadItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + menuLoadEvent.emit(); + } + }); + gameMenu.add(loadItem); + JMenuItem saveItem = new JMenuItem("Speichern..."); + saveItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + menuSaveEvent.emit(); + } + }); + gameMenu.add(saveItem); + + gameMenu.addSeparator(); + + JMenuItem quitItem = new JMenuItem("Beenden"); + quitItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + menuQuitEvent.emit(); + } + }); + gameMenu.add(quitItem); + + setJMenuBar(menuBar); + } + /** * Create a new instance of the view */ @@ -85,6 +164,8 @@ public class View extends JFrame implements IView { setSize(1000, 700); setDefaultCloseOperation(EXIT_ON_CLOSE); + createMenuBar(); + layeredPane = new JLayeredPane(); layeredPane.setLayout(null); add(layeredPane); @@ -130,9 +211,8 @@ public class View extends JFrame implements IView { } private void rescale() { - Insets insets = getInsets(); - int width = getWidth() - insets.left - insets.right, height = getHeight() - - insets.top - insets.bottom; + int width = getContentPane().getWidth(), height = getContentPane() + .getHeight(); layeredPane.setBounds(0, 0, width, height); mainLayer.setBounds(0, 0, width, height); @@ -160,16 +240,6 @@ public class View extends JFrame implements IView { playerPanel.getHandPanel().setSelectedStones(stones); } - /* - * @Override public void enableStartTurnPanel(boolean enable) { - * playerPanel.setVisible(!enable); startTurnPanel.setVisible(enable); - * winPanel.setVisible(false); } - * - * @Override public void enableWinPanel(boolean enable) { - * playerPanel.setVisible(!enable); startTurnPanel.setVisible(false); - * winPanel.setVisible(enable); } - */ - @Override public void showSettingsPanel(boolean show) { settingsPanel.setVisible(show); |