summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/ApplicationControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/ApplicationControl.java')
-rw-r--r--src/jrummikub/control/ApplicationControl.java66
1 files changed, 49 insertions, 17 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();