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.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/jcgp/GUI.java b/src/jcgp/GUI.java
new file mode 100644
index 0000000..1e1d4e4
--- /dev/null
+++ b/src/jcgp/GUI.java
@@ -0,0 +1,111 @@
+package jcgp;
+
+import javafx.application.Application;
+import javafx.event.EventHandler;
+import javafx.scene.Node;
+import javafx.scene.Scene;
+import javafx.scene.control.Tab;
+import javafx.scene.control.TabPane;
+import javafx.scene.control.TabPane.TabClosingPolicy;
+import javafx.scene.input.MouseDragEvent;
+import javafx.scene.layout.BorderPane;
+import javafx.stage.Stage;
+import jcgp.CGP.Resources;
+import jcgp.gui.Console;
+import jcgp.gui.SettingsPane;
+import jcgp.gui.population.ChromosomePane;
+import jcgp.gui.population.GUIGene;
+import jcgp.gui.population.GUINode;
+import jcgp.gui.population.GUIOutput;
+
+public class GUI extends Application {
+
+ public static final String NEUTRAL_COLOUR = "#FFFFFF";
+ public static final String HARD_HIGHLIGHT_COLOUR = "#89AAD6";
+ public static final String SOFT_HIGHLIGHT_COLOUR = "#C7DFFF";
+ public static final String GOOD_SELECTION_COLOUR = "#BDFFC2";
+ public static final String NEUTRAL_SELECTION_COLOUR = "#FBFFB8";
+ public static final String BAD_SELECTION_COLOUR = "#FF9C9C";
+
+ private static CGP cgp;
+ public static Resources resources;
+
+
+ private BorderPane window;
+
+ private ChromosomePane[] chromosomes;
+ private TabPane mainPane;
+
+ private static Console console;
+ private SettingsPane settings;
+
+ public static void main(String[] args) {
+
+ cgp = new CGP();
+ resources = cgp.getResources();
+
+ launch();
+
+ }
+
+ @Override
+ public void start(Stage primaryStage) throws Exception {
+
+ /*
+ * Instantiate the various GUI elements here.
+ *
+ *
+ */
+
+ mainPane = new TabPane();
+ mainPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
+ chromosomes = new ChromosomePane[(int) cgp.getResources().get("popSize")];
+ Tab tab;
+ for (int i = 0; i < chromosomes.length; i++) {
+ chromosomes[i] = new ChromosomePane(cgp.getPopulation().getChromosome(i), cgp.getResources());
+ tab = new Tab("Chr " + i);
+ tab.setContent(chromosomes[i]);
+ mainPane.getTabs().add(tab);
+ }
+
+ mainPane.setPrefHeight(500);
+
+ window = new BorderPane();
+ window.setCenter(mainPane);
+
+ Scene scene = new Scene(window);
+
+ primaryStage.addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler<MouseDragEvent>() {
+ @Override
+ public void handle(MouseDragEvent event) {
+ // preemptively determine whether this event will reach a GUIGene
+ // sodding Controls...
+ if (event.getTarget() instanceof Node) {
+ Node source = ((Node) event.getTarget());
+ while (source != null) {
+ if (source instanceof GUIGene) {
+ return;
+ }
+ source = source.getParent();
+ }
+ }
+ event.consume();
+ ((GUIGene) event.getGestureSource()).resetState();
+ if (event.getGestureSource() instanceof GUINode) {
+ ((GUINode) event.getGestureSource()).updateLines();
+ } else if (event.getGestureSource() instanceof GUIOutput) {
+ ((GUIOutput) event.getGestureSource()).updateLine();
+ }
+ }
+ });
+
+ primaryStage.setMinHeight(600);
+ primaryStage.setMinWidth(800);
+
+ primaryStage.setScene(scene);
+ primaryStage.show();
+
+
+ }
+
+}