summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-06 23:27:33 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-06 23:27:33 +0200
commitc59332950be525408da7b2e66687603a68cb560b (patch)
tree1c4eee4b7b250ac1cbaaf3870ebc132e14cc114e
parent682357b5841f7853212e354199d1a46589663364 (diff)
downloadJRummikub-c59332950be525408da7b2e66687603a68cb560b.tar
JRummikub-c59332950be525408da7b2e66687603a68cb560b.zip
Add menu bar and make quit item work
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@379 72836036-5685-4462-b002-a69064685172
-rw-r--r--mock/jrummikub/view/MockView.java28
-rw-r--r--src/jrummikub/control/ApplicationControl.java9
-rw-r--r--src/jrummikub/view/IView.java32
-rw-r--r--src/jrummikub/view/impl/View.java104
4 files changed, 154 insertions, 19 deletions
diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java
index 09f3254..044e52f 100644
--- a/mock/jrummikub/view/MockView.java
+++ b/mock/jrummikub/view/MockView.java
@@ -36,9 +36,16 @@ public class MockView implements IView {
public MockEvent quitEvent = new MockEvent();
/** */
public MockEvent newRoundEvent = new MockEvent();
-
/** */
public MockEvent newGameEvent = new MockEvent();
+ /** */
+ public MockEvent menuNewGameEvent = new MockEvent();
+ /** */
+ public MockEvent menuLoadEvent = new MockEvent();
+ /** */
+ public MockEvent menuSaveEvent = new MockEvent();
+ /** */
+ public MockEvent menuQuitEvent = new MockEvent();
@Override
public MockTablePanel getTablePanel() {
@@ -124,4 +131,23 @@ public class MockView implements IView {
bottomPanelType = type;
}
+ @Override
+ public IEvent getMenuNewGameEvent() {
+ return menuNewGameEvent;
+ }
+
+ @Override
+ public IEvent getMenuLoadEvent() {
+ return menuLoadEvent;
+ }
+
+ @Override
+ public IEvent getMenuSaveEvent() {
+ return menuSaveEvent;
+ }
+
+ @Override
+ public IEvent getMenuQuitEvent() {
+ return menuQuitEvent;
+ }
}
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);