aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/GUI.java')
-rw-r--r--src/jcgp/GUI.java53
1 files changed, 23 insertions, 30 deletions
diff --git a/src/jcgp/GUI.java b/src/jcgp/GUI.java
index 98545db..d81e760 100644
--- a/src/jcgp/GUI.java
+++ b/src/jcgp/GUI.java
@@ -1,6 +1,9 @@
package jcgp;
+import java.util.concurrent.ExecutionException;
+
import javafx.application.Application;
+import javafx.application.Platform;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import javafx.scene.Scene;
@@ -11,7 +14,7 @@ import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import jcgp.JCGP.Resources;
import jcgp.gui.ChromosomePane;
-import jcgp.gui.GUIConsole;
+import jcgp.gui.console.GUIConsole;
import jcgp.gui.settings.SettingsPane;
public class GUI extends Application {
@@ -52,7 +55,7 @@ public class GUI extends Application {
private GUIConsole console = new GUIConsole();
private SettingsPane settings;
- private Service<Object> cgpService;
+ private Service<Integer> cgpService;
private static boolean evolving = false;
@@ -65,22 +68,19 @@ public class GUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
-
-
- cgpService = new Service<Object> () {
-
+
+ cgpService = new Service<Integer> () {
+
@Override
- protected Task<Object> createTask() {
- Task<Object> t = new Task<Object>() {
+ protected Task<Integer> createTask() {
+
+ Task<Integer> t = new Task<Integer>() {
@Override
- protected Object call() throws Exception {
- while (true) {
- if (isCancelled()) {
- return null;
- } else {
- cgp.nextGeneration();
- }
+ protected Integer call() throws Exception {
+ while (!isCancelled()) {
+ cgp.nextGeneration();
}
+ return null;
}
};
@@ -135,11 +135,11 @@ public class GUI extends Application {
public void playPause() {
if (!evolving) {
- setEvolving(true);
+ evolving = true;
cgpService.restart();
} else {
cgpService.cancel();
- setEvolving(false);
+ evolving = false;
}
}
@@ -149,28 +149,21 @@ public class GUI extends Application {
@Override
protected Object call() throws Exception {
cgp.nextGeneration();
- setEvolving(false);
+ evolving = false;
return null;
}
});
- setEvolving(true);
+ evolving = true;
t.start();
}
}
- private void setEvolving(boolean value) {
- evolving = value;
- settings.toggleSettings(value);
- if (value) {
- settings.bindParameters();
- } else {
- updateNodeGrids();
- settings.unbindParameters();
- }
- }
-
public boolean isEvolving() {
return evolving;
}
+
+ public Service<Integer> getCGPService() {
+ return cgpService;
+ }
}