aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/GUI.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/GUI.java')
-rw-r--r--src/jcgp/gui/GUI.java167
1 files changed, 99 insertions, 68 deletions
diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java
index 5a7a16d..6d87de1 100644
--- a/src/jcgp/gui/GUI.java
+++ b/src/jcgp/gui/GUI.java
@@ -4,24 +4,26 @@ import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
+import javafx.event.EventHandler;
import javafx.scene.Scene;
+import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
import jcgp.JCGP;
-import jcgp.backend.resources.Resources;
+import jcgp.backend.modules.problem.TestCaseProblem.TestCase;
import jcgp.gui.console.GUIConsole;
import jcgp.gui.dragresize.HorizontalDragResize;
import jcgp.gui.dragresize.VerticalDragResize;
import jcgp.gui.population.FunctionSelector;
+import jcgp.gui.population.GUINode;
import jcgp.gui.population.PopulationPane;
import jcgp.gui.settings.SettingsPane;
public class GUI extends Application {
/* Colours */
- /** NEUTRAL_COLOUR is the colour elements should be when no interaction is occurring
- * (no hovering, clicking, dragging or any other form of interaction). */
public static final String NEUTRAL_COLOUR = "#FFFFFF";
public static final String HARD_HIGHLIGHT_COLOUR = "#5496FF";
public static final String MEDIUM_HIGHLIGHT_COLOUR = "#75BAFF";
@@ -33,16 +35,12 @@ public class GUI extends Application {
/* Sizes and distances */
public static final double RESIZE_MARGIN = 5.0;
+ public static final double SETTINGS_MIN_WIDTH = 200;
+ public static final double CONSOLE_MIN_HEIGHT = 100;
- public static final double SETTINGS_WIDTH = 200;
- public static final double CONSOLE_HEIGHT = 100;
-
- public static final double WRAP_WIDTH = 90;
-
- public static final JCGP jcgp = new JCGP();
- public static final Resources resources = jcgp.getResources();
+ private final JCGP jcgp;
- public static final FunctionSelector functionSelector = new FunctionSelector(resources.getFunctionSet());
+ private final FunctionSelector functionSelector;
private PopulationPane populationPane;
@@ -50,53 +48,62 @@ public class GUI extends Application {
private SettingsPane settingsPane;
- private static boolean working = 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() && !jcgp.isFinished()) {
- synchronized (printLock) {
- Platform.runLater(consoleFlush);
- jcgp.nextGeneration();
- printLock.wait();
- }
- }
- if (jcgp.isFinished()) {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- runningMode(false);
- }
- });
- }
- return null;
- }
- };
- return t;
- }
- };
-
- private Runnable consoleFlush = new Runnable() {
- @Override
- public void run() {
- synchronized(printLock) {
- console.flush();
- printLock.notifyAll();
- }
- }
- };
+ private boolean running = false;
+
+ private final Object printLock = new Object();
+
+ private Service<Void> cgpService;
+
+ private Runnable consoleFlush;
public static void main(String[] args) {
-
+ new GUI();
launch();
}
+ public GUI() {
+ jcgp = new JCGP();
+ functionSelector = new FunctionSelector(jcgp.getResources().getFunctionSet());
+
+ consoleFlush = new Runnable() {
+ @Override
+ public void run() {
+ synchronized(printLock) {
+ console.flush();
+ printLock.notifyAll();
+ }
+ }
+ };
+
+ cgpService = new Service<Void> () {
+ @Override
+ protected Task<Void> createTask() {
+ Task<Void> t = new Task<Void>() {
+ @Override
+ protected Void call() throws Exception {
+ while (!isCancelled() && !jcgp.isFinished()) {
+ synchronized (printLock) {
+ Platform.runLater(consoleFlush);
+ jcgp.nextGeneration();
+ printLock.wait();
+ }
+ }
+ if (jcgp.isFinished()) {
+ Platform.runLater(new Runnable() {
+ @Override
+ public void run() {
+ runningMode(false);
+ }
+ });
+ }
+ return null;
+ }
+ };
+ return t;
+ }
+ };
+ }
+
@Override
public void start(Stage primaryStage) throws Exception {
console = new GUIConsole();
@@ -109,9 +116,9 @@ public class GUI extends Application {
*/
BorderPane leftFrame = new BorderPane();
- populationPane = new PopulationPane(jcgp);
+ populationPane = new PopulationPane(this);
- settingsPane = new SettingsPane(jcgp, this);
+ settingsPane = new SettingsPane(this);
HorizontalDragResize.makeDragResizable(settingsPane);
VerticalDragResize.makeDragResizable(console);
@@ -135,11 +142,18 @@ public class GUI extends Application {
primaryStage.setMinWidth(800);
primaryStage.setMinHeight(600);
primaryStage.show();
+
+ primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
+ @Override
+ public void handle(WindowEvent event) {
+ settingsPane.getTestCaseTable().close();
+ }
+ });
}
public void runPause() {
if (!jcgp.isFinished() && settingsPane.areParametersValid()) {
- if (!working) {
+ if (!running) {
runningMode(true);
cgpService.restart();
} else {
@@ -150,7 +164,7 @@ public class GUI extends Application {
}
public void step() {
- if (!working && !jcgp.isFinished() && settingsPane.areParametersValid()) {
+ if (!running && !jcgp.isFinished() && settingsPane.areParametersValid()) {
if (settingsPane.isResetRequired()) {
reset();
}
@@ -166,20 +180,18 @@ public class GUI extends Application {
}
public void reset() {
- if (!working && settingsPane.areParametersValid()) {
+ if (!running && settingsPane.areParametersValid()) {
settingsPane.applyParameters();
jcgp.reset();
- populationPane.remakeTabs(jcgp.getPopulation(), jcgp.getResources());
+ populationPane.remakeTabs();
settingsPane.revalidateParameters();
+ System.out.println("[reset] call: " + jcgp.isFinished());
settingsPane.updateControls(false, jcgp.isFinished());
console.flush();
}
}
- private void runningMode(boolean value) {
- populationPane.setDisable(value);
- settingsPane.updateControls(value, jcgp.isFinished());
-
+ private void runningMode(boolean value) {
if (value) {
populationPane.unlockOutputs();
if (settingsPane.isResetRequired()) {
@@ -190,14 +202,33 @@ public class GUI extends Application {
populationPane.relockOutputs();
settingsPane.revalidateParameters();
}
- working = value;
+ populationPane.setDisable(value);
+ settingsPane.updateControls(value, jcgp.isFinished());
+
+ running = value;
}
- public static void updateFunctionSelector() {
- functionSelector.remakeFunctions(resources.getFunctionSet());
+ public void updateFunctionSelector() {
+ functionSelector.remakeFunctions(jcgp.getResources().getFunctionSet());
+ }
+
+ public boolean isWorking() {
+ return running;
+ }
+
+ public void bringFunctionSelector(MouseEvent event, GUINode node) {
+ functionSelector.relocateAndShow(event, node);
+ }
+
+ public JCGP getExperiment() {
+ return jcgp;
}
- public static boolean isWorking() {
- return working;
+ public void evaluateTestCase(TestCase<Object> testCase) {
+ populationPane.evaluateTestCase(testCase);
+ }
+
+ public void hideGeneValues() {
+ populationPane.hideValues();
}
}