aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/GUI.java
diff options
context:
space:
mode:
authorEduardo Pedroni <ep625@york.ac.uk>2014-04-04 17:14:44 +0100
committerEduardo Pedroni <ep625@york.ac.uk>2014-04-04 17:14:44 +0100
commitc7969623b44f375e30fa3f15dcd7581609276a0f (patch)
treed1743df21e685fed93b7a12dd91a524e44fa42bd /src/jcgp/gui/GUI.java
parent0dbf126fc524bc029d9f5803d849b7c8f43fe389 (diff)
Parameter validation refactored and fully functional.
Diffstat (limited to 'src/jcgp/gui/GUI.java')
-rw-r--r--src/jcgp/gui/GUI.java126
1 files changed, 77 insertions, 49 deletions
diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java
index 0902b21..f7aa25d 100644
--- a/src/jcgp/gui/GUI.java
+++ b/src/jcgp/gui/GUI.java
@@ -53,12 +53,38 @@ public class GUI extends Application {
private GUIConsole console = new GUIConsole();
private SettingsPane settings;
- private Service<Void> cgpService;
-
private boolean evolving = false;
private Object printLock = new Object();
+ private Service<Void> cgpService = new Service<Void> () {
+ @Override
+ protected Task<Void> createTask() {
+ Task<Void> t = new Task<Void>() {
+ @Override
+ protected Void call() throws Exception {
+ while (!isCancelled() && !cgp.isFinished()) {
+ synchronized (printLock) {
+ Platform.runLater(consoleFlush);
+ cgp.nextGeneration();
+ printLock.wait();
+ }
+ }
+ if (cgp.isFinished()) {
+ Platform.runLater(new Runnable() {
+ @Override
+ public void run() {
+ runningMode(false);
+ }
+ });
+ }
+ return null;
+ }
+ };
+ return t;
+ }
+ };
+
private Runnable consoleFlush = new Runnable() {
@Override
public void run() {
@@ -80,27 +106,6 @@ public class GUI extends Application {
public void start(Stage primaryStage) throws Exception {
resources.setConsole(console);
- cgpService = new Service<Void> () {
- @Override
- protected Task<Void> createTask() {
-
- Task<Void> t = new Task<Void>() {
- @Override
- protected Void call() throws Exception {
- while (!isCancelled()) {
- Platform.runLater(consoleFlush);
- synchronized (printLock) {
- cgp.nextGeneration();
- printLock.wait();
- }
- }
- return null;
- }
- };
- return t;
- }
- };
-
/*
* Instantiate the various GUI elements here.
*
@@ -167,45 +172,68 @@ public class GUI extends Application {
chromosomeTabs.setDisable(value);
}
- public void disable(boolean value) {
- chromosomeTabs.setDisable(value);
- settings.disableSettings(value);
- }
-
- public void playPause() {
- if (!evolving) {
- disable(true);
- unlockOutputs();
- evolving = true;
- cgpService.restart();
- } else {
- disable(false);
- updateNodeGrids();
- evolving = false;
- cgpService.cancel();
- relockOutputs();
+ public void runPause() {
+ if (!cgp.isFinished() && settings.areParametersValid()) {
+ if (!evolving) {
+ runningMode(true);
+ cgpService.restart();
+ } else {
+ cgpService.cancel();
+ runningMode(false);
+ }
}
}
public void step() {
- if (!evolving) {
- Thread t = new Thread(new Task<Void>() {
+ if (!evolving && !cgp.isFinished() && settings.areParametersValid()) {
+ if (settings.isResetRequired()) {
+ reset();
+ }
+ unlockOutputs();
+ Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
- unlockOutputs();
cgp.nextGeneration();
- console.flush();
- updateNodeGrids();
- relockOutputs();
+ Platform.runLater(consoleFlush);
return null;
}
- });
+ };
+ Thread t = new Thread(task);
t.start();
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ // nothing
+ } finally {
+ updateNodeGrids();
+ relockOutputs();
+ }
}
}
public void reset() {
- cgp.reset();
- makeChromosomeTabPane();
+ if (!evolving && settings.areParametersValid()) {
+ settings.applyParameters();
+ cgp.reset();
+ makeChromosomeTabPane();
+ settings.revalidateParameters();
+ }
+ }
+
+ private void runningMode(boolean value) {
+ chromosomeTabs.setDisable(value);
+ settings.disableSettings(value);
+ if (value) {
+ unlockOutputs();
+ settings.getRunButton().setText("Pause");
+ if (settings.isResetRequired()) {
+ reset();
+ }
+ } else {
+ updateNodeGrids();
+ relockOutputs();
+ settings.getRunButton().setText("Run");
+ }
+ evolving = value;
}
}