diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-06 21:58:53 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-06 21:58:53 +0100 |
commit | e6dd7711c7dad5e000445208eb5845801f4ccffc (patch) | |
tree | 1454bd20a8dd7069b1283184c42f4def6d5f7e6f /src/jcgp/gui/GUI.java | |
parent | c7969623b44f375e30fa3f15dcd7581609276a0f (diff) |
About to make big changes to the way fitness works, committing just in case
Diffstat (limited to 'src/jcgp/gui/GUI.java')
-rw-r--r-- | src/jcgp/gui/GUI.java | 172 |
1 files changed, 67 insertions, 105 deletions
diff --git a/src/jcgp/gui/GUI.java b/src/jcgp/gui/GUI.java index f7aa25d..8f28884 100644 --- a/src/jcgp/gui/GUI.java +++ b/src/jcgp/gui/GUI.java @@ -5,14 +5,16 @@ import javafx.application.Platform; import javafx.concurrent.Service; import javafx.concurrent.Task; import javafx.scene.Scene; -import javafx.scene.control.Tab; -import javafx.scene.control.TabPane; -import javafx.scene.control.TabPane.TabClosingPolicy; import javafx.scene.layout.BorderPane; +import javafx.scene.layout.Pane; import javafx.stage.Stage; import jcgp.JCGP; -import jcgp.JCGP.Resources; +import jcgp.backend.resources.Resources; import jcgp.gui.console.GUIConsole; +import jcgp.gui.dragresize.HorizontalDragResize; +import jcgp.gui.dragresize.VerticalDragResize; +import jcgp.gui.population.FunctionSelector; +import jcgp.gui.population.PopulationPane; import jcgp.gui.settings.SettingsPane; public class GUI extends Application { @@ -28,10 +30,6 @@ public class GUI extends Application { public static final String GOOD_SELECTION_COLOUR = "#38C25B"; public static final String NEUTRAL_SELECTION_COLOUR = "#FFEF73"; public static final String BAD_SELECTION_COLOUR = "#FF5C5C"; - - public static final String INVALID_PARAMETER_STYLE = "-fx-border-color: C9C9C9; -fx-border-radius: 2; -fx-padding: 0; -fx-background-color: " + BAD_SELECTION_COLOUR; - public static final String WARNING_PARAMETER_STYLE = "-fx-border-color: C9C9C9; -fx-border-radius: 2; -fx-padding: 0; -fx-background-color: " + NEUTRAL_SELECTION_COLOUR; - public static final String VALID_PARAMETER_STYLE = "-fx-border-color: C9C9C9; -fx-border-radius: 2; -fx-padding: 0; -fx-background-color: " + NEUTRAL_COLOUR; /* Sizes and distances */ public static final double RESIZE_MARGIN = 5.0; @@ -41,17 +39,16 @@ public class GUI extends Application { public static final double WRAP_WIDTH = 90; - private static JCGP cgp; - public static Resources resources; + public static final JCGP jcgp = new JCGP(); + public static final Resources resources = jcgp.getResources(); - private BorderPane leftPane; - private BorderPane window; + public static final FunctionSelector functionSelector = new FunctionSelector(resources.getFunctionSet()); - private ChromosomePane[] chromosomes; - private TabPane chromosomeTabs; + private PopulationPane populationPane; private GUIConsole console = new GUIConsole(); - private SettingsPane settings; + + private SettingsPane settingsPane; private boolean evolving = false; @@ -63,14 +60,14 @@ public class GUI extends Application { Task<Void> t = new Task<Void>() { @Override protected Void call() throws Exception { - while (!isCancelled() && !cgp.isFinished()) { + while (!isCancelled() && !jcgp.isFinished()) { synchronized (printLock) { Platform.runLater(consoleFlush); - cgp.nextGeneration(); + jcgp.nextGeneration(); printLock.wait(); } } - if (cgp.isFinished()) { + if (jcgp.isFinished()) { Platform.runLater(new Runnable() { @Override public void run() { @@ -96,84 +93,55 @@ public class GUI extends Application { }; public static void main(String[] args) { - cgp = new JCGP(); - resources = cgp.getResources(); +// jcgp = new JCGP(); +// resources = jcgp.getResources(); +// +// functionSelector = launch(); } @Override public void start(Stage primaryStage) throws Exception { - resources.setConsole(console); + jcgp.setConsole(console); /* * Instantiate the various GUI elements here. * * */ + BorderPane leftFrame = new BorderPane(); - leftPane = new BorderPane(); + populationPane = new PopulationPane(jcgp); - chromosomeTabs = new TabPane(); - chromosomeTabs.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE); - makeChromosomeTabPane(); + settingsPane = new SettingsPane(jcgp, this); - settings = new SettingsPane(cgp, this); + HorizontalDragResize.makeDragResizable(settingsPane); + VerticalDragResize.makeDragResizable(console); - leftPane.setCenter(chromosomeTabs); - leftPane.setBottom(console); + leftFrame.setCenter(populationPane); + leftFrame.setBottom(console); - window = new BorderPane(); + BorderPane experimentLayer = new BorderPane(); - window.setCenter(leftPane); - window.setRight(settings); + experimentLayer.setCenter(leftFrame); + experimentLayer.setRight(settingsPane); primaryStage.setTitle("JCGP"); - primaryStage.setScene(new Scene(window)); + Pane sceneParent = new Pane(); + experimentLayer.prefHeightProperty().bind(sceneParent.heightProperty()); + experimentLayer.prefWidthProperty().bind(sceneParent.widthProperty()); + sceneParent.getChildren().addAll(experimentLayer, functionSelector); + + primaryStage.setScene(new Scene(sceneParent)); + primaryStage.setMinWidth(800); + primaryStage.setMinHeight(600); primaryStage.show(); } - /** - * - */ - private void makeChromosomeTabPane() { - chromosomeTabs.getTabs().clear(); - - chromosomes = new ChromosomePane[cgp.getResources().getInt("popSize")]; - Tab tab; - for (int i = 0; i < chromosomes.length; i++) { - chromosomes[i] = new ChromosomePane(cgp.getPopulation().getChromosome(i), resources); - tab = new Tab("Chr " + i); - tab.setContent(chromosomes[i]); - chromosomeTabs.getTabs().add(tab); - } - } - - private void updateNodeGrids() { - for (int i = 0; i < chromosomes.length; i++) { - chromosomes[i].update(); - } - } - - private void unlockOutputs() { - for (int i = 0; i < chromosomes.length; i++) { - chromosomes[i].unlockOutputs(); - } - } - - private void relockOutputs() { - for (int i = 0; i < chromosomes.length; i++) { - chromosomes[i].relockOutputs(); - } - } - - public void disableChromosomePanes(boolean value) { - chromosomeTabs.setDisable(value); - } - public void runPause() { - if (!cgp.isFinished() && settings.areParametersValid()) { + if (!jcgp.isFinished() && settingsPane.areParametersValid()) { if (!evolving) { runningMode(true); cgpService.restart(); @@ -185,55 +153,49 @@ public class GUI extends Application { } public void step() { - if (!evolving && !cgp.isFinished() && settings.areParametersValid()) { - if (settings.isResetRequired()) { + if (!evolving && !jcgp.isFinished() && settingsPane.areParametersValid()) { + if (settingsPane.isResetRequired()) { reset(); } - unlockOutputs(); - Task<Void> task = new Task<Void>() { - @Override - protected Void call() throws Exception { - cgp.nextGeneration(); - Platform.runLater(consoleFlush); - return null; - } - }; - Thread t = new Thread(task); - t.start(); - try { - t.join(); - } catch (InterruptedException e) { - // nothing - } finally { - updateNodeGrids(); - relockOutputs(); - } + populationPane.unlockOutputs(); + + jcgp.nextGeneration(); + console.flush(); + + populationPane.updateGenes(); + populationPane.relockOutputs(); + } } public void reset() { - if (!evolving && settings.areParametersValid()) { - settings.applyParameters(); - cgp.reset(); - makeChromosomeTabPane(); - settings.revalidateParameters(); + if (!evolving && settingsPane.areParametersValid()) { + settingsPane.applyParameters(); + jcgp.reset(); + populationPane.remakeTabs(jcgp.getPopulation(), jcgp.getResources()); + settingsPane.revalidateParameters(); + console.flush(); } } private void runningMode(boolean value) { - chromosomeTabs.setDisable(value); - settings.disableSettings(value); + populationPane.setDisable(value); + settingsPane.runningMode(value); + if (value) { - unlockOutputs(); - settings.getRunButton().setText("Pause"); - if (settings.isResetRequired()) { + populationPane.unlockOutputs(); + if (settingsPane.isResetRequired()) { reset(); } } else { - updateNodeGrids(); - relockOutputs(); - settings.getRunButton().setText("Run"); + populationPane.updateGenes(); + populationPane.relockOutputs(); } evolving = value; } + + public static void updateFunctionSelector() { + functionSelector.remakeFunctions(resources.getFunctionSet()); + } + } |