summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 21:51:20 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-07 21:51:20 +0200
commit8b763a817b21aff45d704940ad2e17799dc7bb43 (patch)
treedc797106eff544419b3be18df01e7335f3a1ffb0 /src/jrummikub/view
parent244abb7e7320355d0c4aad4a7ba267f11d358563 (diff)
downloadJRummikub-8b763a817b21aff45d704940ad2e17799dc7bb43.tar
JRummikub-8b763a817b21aff45d704940ad2e17799dc7bb43.zip
Saving is working
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@382 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/IView.java19
-rw-r--r--src/jrummikub/view/impl/View.java50
2 files changed, 50 insertions, 19 deletions
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 1c95ad4..8280a1b 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -1,10 +1,12 @@
package jrummikub.view;
import java.awt.Color;
+import java.io.File;
import java.util.Collection;
import jrummikub.model.Stone;
import jrummikub.util.IEvent;
+import jrummikub.util.IEvent1;
/**
* The top-level view interface
@@ -154,26 +156,25 @@ public interface IView {
public IEvent getMenuNewGameEvent();
/**
- * The menu load event is emitted when the user selects the load menu
- * entry
+ * The menu quit event is emitted when the user selects the quit menu entry
*
* @return the event
*/
- public IEvent getMenuLoadEvent();
+ public IEvent getMenuQuitEvent();
/**
- * The menu save event is emitted when the user selects the save menu
- * entry
+ * The load event is emitted when the user wants to load a previously saved
+ * game state
*
* @return the event
*/
- public IEvent getMenuSaveEvent();
+ IEvent1<File> getLoadEvent();
/**
- * The menu quit event is emitted when the user selects the quit menu
- * entry
+ * The save event is emitted when the user wants to save the current game
+ * state
*
* @return the event
*/
- public IEvent getMenuQuitEvent();
+ IEvent1<File> getSaveEvent();
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 0bc7120..a3bded6 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -5,11 +5,13 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
+import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JMenu;
@@ -17,13 +19,16 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;
+import javax.swing.filechooser.FileNameExtensionFilter;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.Event;
+import jrummikub.util.Event1;
import jrummikub.util.IEvent;
+import jrummikub.util.IEvent1;
import jrummikub.util.Pair;
import jrummikub.view.IHandPanel;
import jrummikub.view.IPlayerPanel;
@@ -52,11 +57,14 @@ public class View extends JFrame implements IView {
private SettingsPanel settingsPanel;
private ScorePanel scorePanel;
+ private JFileChooser chooser;
+
private Event menuNewGameEvent = new Event();
- private Event menuLoadEvent = new Event();
- private Event menuSaveEvent = new Event();
private Event menuQuitEvent = new Event();
+ private Event1<File> loadEvent = new Event1<File>();
+ private Event1<File> saveEvent = new Event1<File>();
+
private static int even(double d) {
return 2 * (int) (d / 2);
}
@@ -92,18 +100,25 @@ public class View extends JFrame implements IView {
}
@Override
- public IEvent getMenuLoadEvent() {
- return menuLoadEvent;
+ public IEvent getMenuQuitEvent() {
+ return menuQuitEvent;
}
@Override
- public IEvent getMenuSaveEvent() {
- return menuSaveEvent;
+ public IEvent1<File> getLoadEvent() {
+ return loadEvent;
}
@Override
- public IEvent getMenuQuitEvent() {
- return menuQuitEvent;
+ public IEvent1<File> getSaveEvent() {
+ return saveEvent;
+ }
+
+ private void createFileChooser() {
+ chooser = new JFileChooser();
+ FileNameExtensionFilter filter = new FileNameExtensionFilter(
+ "JRummikub-Spiele", "rum");
+ chooser.setFileFilter(filter);
}
private void createMenuBar() {
@@ -127,7 +142,7 @@ public class View extends JFrame implements IView {
loadItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- menuLoadEvent.emit();
+ load();
}
});
gameMenu.add(loadItem);
@@ -135,7 +150,7 @@ public class View extends JFrame implements IView {
saveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- menuSaveEvent.emit();
+ save();
}
});
gameMenu.add(saveItem);
@@ -154,6 +169,20 @@ public class View extends JFrame implements IView {
setJMenuBar(menuBar);
}
+ private void load() {
+ int returnVal = chooser.showOpenDialog(View.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ loadEvent.emit(chooser.getSelectedFile());
+ }
+ }
+
+ private void save() {
+ int returnVal = chooser.showSaveDialog(View.this);
+ if (returnVal == JFileChooser.APPROVE_OPTION) {
+ saveEvent.emit(chooser.getSelectedFile());
+ }
+ }
+
/**
* Create a new instance of the view
*/
@@ -164,6 +193,7 @@ public class View extends JFrame implements IView {
setSize(1000, 700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
+ createFileChooser();
createMenuBar();
layeredPane = new JLayeredPane();