summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-19 16:11:20 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-19 16:11:20 +0200
commit92fe29000b3a8da2adc498154521e7969b6f9c5f (patch)
tree03017bc91e5903ac011ae1a833bca82136871159
parent0506b7f154a816d591f580466a294e1b6820774b (diff)
downloadJRummikub-92fe29000b3a8da2adc498154521e7969b6f9c5f.tar
JRummikub-92fe29000b3a8da2adc498154521e7969b6f9c5f.zip
Load error, save default file, save disable
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@483 72836036-5685-4462-b002-a69064685172
-rw-r--r--mock/jrummikub/view/MockView.java12
-rw-r--r--src/jrummikub/control/ApplicationControl.java8
-rw-r--r--src/jrummikub/control/SaveControl.java11
-rw-r--r--src/jrummikub/view/IView.java3
-rw-r--r--src/jrummikub/view/impl/View.java33
5 files changed, 55 insertions, 12 deletions
diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java
index 167bc0b..dbc36da 100644
--- a/mock/jrummikub/view/MockView.java
+++ b/mock/jrummikub/view/MockView.java
@@ -244,4 +244,16 @@ public class MockView implements IView {
}
+ @Override
+ public void showError() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void enableSave(boolean enable) {
+ // TODO Auto-generated method stub
+
+ }
+
}
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index bcf497f..d07a0f6 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -65,6 +65,12 @@ public class ApplicationControl {
}
});
+ saveControl.getLoadErrorEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ view.showError();
+ }
+ });
}
private void addLoginControlListeners() {
@@ -123,10 +129,12 @@ public class ApplicationControl {
saveControl.setGameState(null);
settingsControl = new SettingsControl(view, new GameSettings());
+ view.enableSave(false);
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
@Override
public void handle(GameSettings settings) {
+ view.enableSave(true);
settingsControl = null;
saveControl.setGameSettings(settings);
diff --git a/src/jrummikub/control/SaveControl.java b/src/jrummikub/control/SaveControl.java
index bebe6c5..3e12a9d 100644
--- a/src/jrummikub/control/SaveControl.java
+++ b/src/jrummikub/control/SaveControl.java
@@ -9,6 +9,7 @@ import java.io.ObjectOutputStream;
import jrummikub.model.GameSettings;
import jrummikub.model.GameState;
import jrummikub.model.IRoundState;
+import jrummikub.util.Event;
import jrummikub.util.Event3;
import jrummikub.util.IEvent3;
import jrummikub.util.IListener1;
@@ -22,6 +23,7 @@ public class SaveControl {
private GameState gameState;
private IRoundState roundState;
private Event3<GameSettings, GameState, IRoundState> loadEvent = new Event3<GameSettings, GameState, IRoundState>();
+ private Event loadErrorEvent = new Event();
/**
* Creates a new SaveControl
@@ -96,17 +98,20 @@ public class SaveControl {
stream.close();
if (gameState == null || gameSettings == null) {
- // TODO Fehlermeldung
- System.err.println("laden ging nicht");
+ loadErrorEvent.emit();
return;
}
loadEvent.emit(gameSettings, gameState, roundState);
} catch (Exception e) {
- e.printStackTrace();
+ loadErrorEvent.emit();
}
}
+
+ public Event getLoadErrorEvent(){
+ return loadErrorEvent;
+ }
private void save(File file) {
if (gameState == null || gameSettings == null) {
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index b127377..86ab5be 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -276,4 +276,7 @@ public interface IView {
/** */
WIN_PANEL
}
+ void showError();
+
+ void enableSave(boolean enable);
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 60202e4..e436419 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -17,6 +17,7 @@ import javax.swing.JLayeredPane;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.MatteBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
@@ -52,6 +53,7 @@ public class View extends JFrame implements IView {
private JLayeredPane layeredPane;
private JPanel mainLayer;
private JMenuBar menuBar;
+ private JMenuItem saveItem;
private TablePanel table;
private PlayerPanel playerPanel;
@@ -162,11 +164,20 @@ public class View extends JFrame implements IView {
setSelectedStones(Collections.<Stone> emptyList());
}
+ @Override
+ public void showError() {
+ JOptionPane.showMessageDialog(this, "Kein g\u00fcltiger Spielstand",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+ }
+
private void createFileChooser() {
chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JRummikub-Spiele", "rum");
chooser.setFileFilter(filter);
+
+ String defaultFile = "spiel.rum";
+ chooser.setSelectedFile(new File(defaultFile));
}
private void createMenuBar() {
@@ -188,7 +199,8 @@ public class View extends JFrame implements IView {
}
});
gameMenu.add(loadItem);
- JMenuItem saveItem = new JMenuItem("Speichern...");
+
+ saveItem = new JMenuItem("Speichern...");
saveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -215,6 +227,11 @@ public class View extends JFrame implements IView {
return item;
}
+ @Override
+ public void enableSave(boolean enable) {
+ saveItem.setEnabled(enable);
+ }
+
private void load() {
int returnVal = chooser.showOpenDialog(View.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
@@ -322,7 +339,7 @@ public class View extends JFrame implements IView {
winPanel = new WinPanel();
winPanel.setVisible(false);
mainLayer.add(winPanel);
-
+
sidePanel = new SidePanel();
mainLayer.add(sidePanel);
}
@@ -339,8 +356,6 @@ public class View extends JFrame implements IView {
int width = getContentPane().getWidth(), height = getContentPane()
.getHeight();
-
-
layeredPane.setBounds(0, 0, width, height);
mainLayer.setBounds(0, 0, width, height);
@@ -354,9 +369,9 @@ public class View extends JFrame implements IView {
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
playerPanel.rescale();
-
+
int sideWidth = playerPanel.getLeftPanelWidth() + 1;
-
+
table.setBounds(sideWidth, 0, width - sideWidth, tableHeight);
table.validate();
sidePanel.setBounds(0, 0, sideWidth, tableHeight);
@@ -414,7 +429,7 @@ public class View extends JFrame implements IView {
startTurnPanel.setCurrentPlayerName(playerName);
pausePanel.setCurrentPlayerName(playerName);
}
-
+
@Override
public void setInitialMeldError(int points) {
startTurnPanel.setInitialMeldError(points);
@@ -444,7 +459,7 @@ public class View extends JFrame implements IView {
public IEvent getAcknowledgeInvalidEvent() {
return startTurnPanel.getAcknowledgeInvalidEvent();
}
-
+
@Override
public IEvent getNewRoundEvent() {
return winPanel.getNewRoundEvent();
@@ -524,7 +539,7 @@ public class View extends JFrame implements IView {
playerPanel.showButtons(type != BottomPanelType.START_GAME_PANEL);
playerPanel.enableButtons(type != BottomPanelType.COMPUTER_HAND_PANEL);
}
-
+
@Override
public void setStoneCollectionHidden(boolean enable) {
table.getStoneCollectionPanel().setHidden(enable);