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.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import jcgp.JCGP.Resources; import jcgp.gui.Console; import jcgp.gui.SettingsPane; import jcgp.gui.population.ChromosomePane; import jcgp.gui.population.GUIGene; public class GUI extends Application { public static final String NEUTRAL_COLOUR = "#FFFFFF"; public static final String HARD_HIGHLIGHT_COLOUR = "#5496FF"; public static final String MEDIUM_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 JCGP 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 JCGP(); 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)); tab = new Tab("Chr " + i); tab.setContent(chromosomes[i]); mainPane.getTabs().add(tab); } settings = new SettingsPane(cgp); mainPane.setPrefHeight(500); window = new BorderPane(); window.setCenter(mainPane); window.setRight(settings); primaryStage.addEventFilter(MouseDragEvent.MOUSE_DRAG_RELEASED, new EventHandler() { @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(); ((GUIGene) event.getGestureSource()).updateLines(); } }); primaryStage.setMinHeight(600); primaryStage.setMinWidth(800); primaryStage.setScene(new Scene(window)); primaryStage.show(); } }