From 88314e71f908efcfc38da3b800319c171a6ccceb Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 18 Apr 2014 09:08:41 +0100 Subject: Added parsers, did a bit of testing, switched to java8 --- src/jcgp/gui/settings/SettingsPane.java | 59 +++++++++++++++------- src/jcgp/gui/settings/parameters/GUIParameter.java | 2 +- 2 files changed, 42 insertions(+), 19 deletions(-) (limited to 'src/jcgp/gui/settings') diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index 2ab9650..4e8c342 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -1,5 +1,6 @@ package jcgp.gui.settings; +import java.io.File; import java.util.ArrayList; import javafx.event.ActionEvent; @@ -16,6 +17,8 @@ import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.Text; +import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; import jcgp.JCGP; import jcgp.backend.function.FunctionSet; import jcgp.backend.modules.es.EvolutionaryStrategy; @@ -31,6 +34,7 @@ public class SettingsPane extends AnchorPane { private VBox mainContainer; private VBox baseParameterPane, eaPane, mutatorPane, problemPane; + private VBox nodeFunctions; private Button runPause = new Button("Run"), step = new Button("Step"), reset = new Button("Reset"); private Button loadParameters = new Button("Load parameters"), loadChromosome = new Button("Load chromosome"), saveChromosome = new Button("Save chromosome"); @@ -103,7 +107,7 @@ public class SettingsPane extends AnchorPane { parameters.add(gp); parameters.add(GUIParameter.create(jcgp.getResources().getSeedParameter(), this)); - parameters.add(GUIParameter.create(jcgp.getResources().getReportParameter(), this)); + parameters.add(GUIParameter.create(jcgp.getResources().getReportIntervalParameter(), this)); baseParameterPane.getChildren().addAll(parameters); mainContainer.getChildren().add(baseParameterPane); @@ -201,10 +205,10 @@ public class SettingsPane extends AnchorPane { testCaseTable = new TestCaseTable((TestCaseProblem) jcgp.getProblem(), gui); } - final VBox nodeFunctions = new VBox(); + nodeFunctions = new VBox(); nodeFunctions.setSpacing(2); nodeFunctions.setPadding(new Insets(0, 0, 4, 0)); - refreshFunctions(jcgp.getResources().getFunctionSet(), nodeFunctions, gui); + refreshFunctions(); problemCBox.setOnAction(new EventHandler() { @Override @@ -215,7 +219,7 @@ public class SettingsPane extends AnchorPane { } testCaseTable.close(); gui.setEvaluating(false); - refreshFunctions(jcgp.getProblem().getFunctionSet(), nodeFunctions, gui); + refreshFunctions(); showTestCaseContainer.getChildren().clear(); if (jcgp.getProblem() instanceof TestCaseProblem) { showTestCaseContainer.getChildren().add(showTestCaseButton); @@ -284,14 +288,31 @@ public class SettingsPane extends AnchorPane { loadParameters.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { - //gui.runPause(); + FileChooser fc = new FileChooser(); + fc.setTitle("Open .par file..."); + fc.getExtensionFilters().add(new ExtensionFilter("CGP parameter files", "*.par")); + fc.getExtensionFilters().add(new ExtensionFilter("All files", "*.*")); + File parFile = fc.showOpenDialog(gui.getStage()); + if (parFile != null) { + gui.getExperiment().loadParameters(parFile); + } + gui.reDraw(); + refreshFunctions(); } }); loadChromosome.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { - //gui.step(); + FileChooser fc = new FileChooser(); + fc.setTitle("Open .chr file..."); + fc.getExtensionFilters().add(new ExtensionFilter("CGP chromosome files", "*.chr")); + fc.getExtensionFilters().add(new ExtensionFilter("All files", "*.*")); + File chrFile = fc.showOpenDialog(gui.getStage()); + if (chrFile != null) { + gui.getExperiment().loadChromosome(chrFile); + } + gui.reDraw(); } }); saveChromosome.setOnAction(new EventHandler() { @@ -331,31 +352,28 @@ public class SettingsPane extends AnchorPane { /** * This method handles a problem type change by updating the list of allowed * node functions. - * - * @param functionSet - * @param container - * @param gui */ - private void refreshFunctions(final FunctionSet functionSet, VBox container, final GUI gui) { - container.getChildren().clear(); + private void refreshFunctions() { + nodeFunctions.getChildren().clear(); CheckBox cb; - for (int i = 0; i < functionSet.getTotalFunctionCount(); i++) { - cb = new CheckBox(functionSet.getFunction(i).getName()); + final FunctionSet fs = gui.getExperiment().getResources().getFunctionSet(); + for (int i = 0; i < fs.getTotalFunctionCount(); i++) { + cb = new CheckBox(fs.getFunction(i).getName()); cb.setId(String.valueOf(i)); - cb.setSelected(functionSet.isEnabled(functionSet.getFunction(i))); + cb.setSelected(fs.isEnabled(fs.getFunction(i))); final int index = i; cb.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { if (((CheckBox) event.getSource()).isSelected()) { - functionSet.enableFunction(index); + fs.enableFunction(index); } else { - functionSet.disableFunction(index); + fs.disableFunction(index); } gui.updateFunctionSelector(); } }); - container.getChildren().add(cb); + nodeFunctions.getChildren().add(cb); gui.updateFunctionSelector(); } @@ -436,6 +454,11 @@ public class SettingsPane extends AnchorPane { step.setDisable(running || finished); reset.setDisable(running); + loadParameters.setDisable(running); + loadChromosome.setDisable(running); + saveChromosome.setDisable(running); + + testCaseTable.getTable().setDisable(running); } diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index a8a8c4a..159e709 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -86,7 +86,7 @@ public abstract class GUIParameter extends HBox { // the tooltip is the hover-over label containing status information, when appropriate tooltip = new Tooltip(); - tooltip.setStyle("-fx-background-color: white; -fx-border-color: black; .page-corner {-fx-background-color: transparent;}"); + tooltip.setStyle("-fx-background-color: white; -fx-border-color: black;"); tooltip.setSkin(null); valueControl = makeControl(); -- cgit v1.2.3