summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 06:14:41 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 06:14:41 +0200
commit443e99450b172c06438ceb452e9b0dc3c715f914 (patch)
tree091dfe7f406f94087a980251ac439478c5b403d7 /src
parent86eeace6738c4715857df6730dff41e788918b43 (diff)
downloadJRummikub-443e99450b172c06438ceb452e9b0dc3c715f914.tar
JRummikub-443e99450b172c06438ceb452e9b0dc3c715f914.zip
Fixed load warnings panels and everything
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@579 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/ApplicationControl.java66
-rw-r--r--src/jrummikub/control/SaveControl.java29
-rw-r--r--src/jrummikub/control/network/NetworkControl.java35
-rw-r--r--src/jrummikub/view/impl/LoginPanel.java8
4 files changed, 57 insertions, 81 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index 7590081..25de8c9 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -42,7 +42,7 @@ public class ApplicationControl {
saveControl = new SaveControl(view);
addQuitGameHandlers();
-
+ addSaveLoadHandlers();
addNewNetworkGameHandler();
saveControl.getLoadEvent().add(
@@ -65,27 +65,56 @@ public class ApplicationControl {
});
}
- private void addNewNetworkGameHandler() {
- view.getNetworkGameEvent().add(new IListener() {
+ private void addSaveLoadHandlers() {
+ view.getLoadEvent().add(new IListener() {
@Override
public void handle() {
- if (gameControl == null) {
+ if (!isGameRunning()) {
abortControls();
- createLoginControl(true);
- } else {
- view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
+ startApplication();
+ view.load();
+ return;
+ }
+ view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
+
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
- view.showQuitWarningPanel(false);
abortControls();
- createLoginControl(true);
+ startApplication();
+ view.showQuitWarningPanel(false);
+ view.load();
tempConnection.remove();
- tempConnection = null;
}
});
+ }
+ });
+
+ }
+
+ private void addNewNetworkGameHandler() {
+ view.getNetworkGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ if (!isGameRunning()) {
+ abortControls();
+ createLoginControl(true);
+ } else {
+ view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
+ view.showQuitWarningPanel(true);
+ tempConnection = view.getQuitWarningPanel().getQuitEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ view.showQuitWarningPanel(false);
+ abortControls();
+ createLoginControl(true);
+ tempConnection.remove();
+ tempConnection = null;
+ }
+ });
}
}
});
@@ -101,10 +130,7 @@ public class ApplicationControl {
view.getQuitEvent().add(new IListener() {
@Override
public void handle() {
- if (networkControl != null) {
- return;
- }
- if (gameControl == null) {
+ if (!isGameRunning()) {
System.exit(0);
} else {
showQuitWarning();
@@ -152,6 +178,15 @@ public class ApplicationControl {
}
/**
+ * Checks if a game is currently running
+ * @return true when a game is running
+ */
+ public boolean isGameRunning() {
+ return gameControl != null || networkControl != null
+ && networkControl.isGameRunning();
+ }
+
+ /**
* Create a new network login control
*/
private void createLoginControl(boolean reset) {
@@ -282,9 +317,6 @@ public class ApplicationControl {
* @return whether the server could be started
*/
public boolean startDedicatedServer(String password) {
- if (password == "") {
- password = "jrummikub";
- }
if (server == null) {
DedicatedServer newServer = new DedicatedServer(password);
ServerStatus status = newServer.start();
diff --git a/src/jrummikub/control/SaveControl.java b/src/jrummikub/control/SaveControl.java
index 5ecbb45..f348756 100644
--- a/src/jrummikub/control/SaveControl.java
+++ b/src/jrummikub/control/SaveControl.java
@@ -27,7 +27,6 @@ public class SaveControl {
private IRoundState roundState;
private Event3<GameSettings, GameState, IRoundState> loadEvent = new Event3<GameSettings, GameState, IRoundState>();
private Event loadErrorEvent = new Event();
- private Connection tempConnection;
/**
* Creates a new SaveControl
@@ -42,34 +41,6 @@ public class SaveControl {
save(file);
}
});
-
- view.getLoadEvent().add(new IListener() {
- @Override
- public void handle() {
- view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
- view.showQuitWarningPanel(true);
-
- tempConnection = view.getQuitWarningPanel().getQuitEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- view.showQuitWarningPanel(false);
- view.load();
- tempConnection.remove();
- }
- });
- }
- });
- view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
- @Override
- public void handle() {
- view.showQuitWarningPanel(false);
- if (tempConnection != null) {
- tempConnection.remove();
- tempConnection = null;
- }
- }
- });
view.getLoadFileEvent().add(new IListener1<File>() {
@Override
public void handle(final File file) {
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index 6e42f83..2b5f90f 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -27,7 +27,6 @@ public class NetworkControl {
private IConnectionControl connectionControl;
private IView view;
private List<Connection> connections = new ArrayList<Connection>();
- Connection tempConnection;
private Event stopNetworkEvent = new Event();
private Event backToLoginEvent = new Event();
@@ -63,41 +62,10 @@ public class NetworkControl {
addConnectionSetupListeners(loginData, view);
addConnectionControlListeners(view);
-
- connections.add(view.getQuitEvent().add(new IListener() {
- @Override
- public void handle() {
- if (gameControl == null) {
- System.exit(0);
- } else {
- view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
- view.showQuitWarningPanel(true);
- tempConnection = view.getQuitWarningPanel().getQuitEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- System.exit(0);
- }
- });
- }
- }
- }));
addViewEventListeners();
}
private void addViewEventListeners() {
- connections.add(view.getQuitWarningPanel().getCancelEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- view.showQuitWarningPanel(false);
- if (tempConnection != null) {
- tempConnection.remove();
- tempConnection = null;
- }
- }
- }));
-
connections.add(view.getGameListPanel().getJoinEvent()
.add(new IListener1<GameData>() {
@Override
@@ -378,4 +346,7 @@ public class NetworkControl {
gameControl.startGame();
}
+ public boolean isGameRunning() {
+ return gameControl != null;
+ }
}
diff --git a/src/jrummikub/view/impl/LoginPanel.java b/src/jrummikub/view/impl/LoginPanel.java
index 9fef581..0cca29d 100644
--- a/src/jrummikub/view/impl/LoginPanel.java
+++ b/src/jrummikub/view/impl/LoginPanel.java
@@ -34,7 +34,8 @@ class LoginPanel extends JPanel implements ILoginPanel {
private JTextField passwordField;
private JTextField channelNameField;
private JButton startDedicatedServerButton;
-
+ private static final String DEFAULT_PASSWORD = "jrummikub";
+
LoginPanel() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -50,7 +51,8 @@ class LoginPanel extends JPanel implements ILoginPanel {
startDedicatedServerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
- useDedicatedServer.emit(passwordField.getText());
+ useDedicatedServer.emit(passwordField.getText().isEmpty() ? DEFAULT_PASSWORD
+ : passwordField.getText());
}
});
@@ -144,7 +146,7 @@ class LoginPanel extends JPanel implements ILoginPanel {
private void login() {
loginEvent.emit(new LoginData(userNameField.getText(), serverNameField
- .getText(), passwordField.getText().isEmpty() ? "jrummikub"
+ .getText(), passwordField.getText().isEmpty() ? DEFAULT_PASSWORD
: passwordField.getText(), channelNameField.getText()));
}