From dbae5ce2e0765f229e11b692a2aba570286980f4 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 10 Apr 2014 16:57:30 +0100 Subject: Added manual test case evaluation to GUI --- src/jcgp/gui/settings/testcase/TestCaseTable.java | 90 +++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/jcgp/gui/settings/testcase/TestCaseTable.java (limited to 'src/jcgp/gui/settings/testcase') diff --git a/src/jcgp/gui/settings/testcase/TestCaseTable.java b/src/jcgp/gui/settings/testcase/TestCaseTable.java new file mode 100644 index 0000000..7e72cbd --- /dev/null +++ b/src/jcgp/gui/settings/testcase/TestCaseTable.java @@ -0,0 +1,90 @@ +package jcgp.gui.settings.testcase; + +import java.util.ArrayList; + +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.ObservableList; +import javafx.event.EventHandler; +import javafx.scene.Scene; +import javafx.scene.control.TableColumn; +import javafx.scene.control.TableColumn.CellDataFeatures; +import javafx.scene.control.TableView; +import javafx.stage.Stage; +import javafx.stage.WindowEvent; +import javafx.util.Callback; +import jcgp.backend.modules.problem.TestCaseProblem; +import jcgp.backend.modules.problem.TestCaseProblem.TestCase; +import jcgp.gui.GUI; + +/** + * Dont forget to override toString()! + * + * + * @author Eduardo Pedroni + * + */ +public class TestCaseTable extends Stage { + + public TestCaseTable(final TestCaseProblem problem, final GUI gui) { + super(); + + TableView> tv = new TableView>(); + ObservableList> testCaseList = problem.getTestCases(); + + ArrayList, String>> inputs = new ArrayList, String>>(problem.getInputCount()); + ArrayList, String>> outputs = new ArrayList, String>>(problem.getOutputCount()); + + TableColumn, String> tc; + for (int i = 0; i < problem.getInputCount(); i++) { + tc = new TableColumn, String>("I: " + i); + inputs.add(tc); + final int index = i; + tc.setCellValueFactory(new Callback,String>, ObservableValue>() { + @Override + public ObservableValue call(CellDataFeatures, String> param) { + return new SimpleStringProperty(param.getValue().getInput(index).toString()); + } + }); + tc.setSortable(false); + tc.prefWidthProperty().bind(tv.widthProperty().divide(problem.getInputCount() + problem.getOutputCount())); + } + + for (int o = 0; o < problem.getOutputCount(); o++) { + tc = new TableColumn, String>("O: " + o); + outputs.add(tc); + final int index = o; + tc.setCellValueFactory(new Callback,String>, ObservableValue>() { + @Override + public ObservableValue call(CellDataFeatures, String> param) { + return new SimpleStringProperty(param.getValue().getOutput(index).toString()); + } + }); + tc.setSortable(false); + tc.prefWidthProperty().bind(tv.widthProperty().divide(problem.getInputCount() + problem.getOutputCount())); + } + + tv.getColumns().addAll(inputs); + tv.getColumns().addAll(outputs); + + tv.setItems(testCaseList); + + tv.getSelectionModel().selectedItemProperty().addListener(new ChangeListener>() { + @Override + public void changed( + ObservableValue> observable, TestCase oldValue, TestCase newValue) { + gui.evaluateTestCase(newValue); + } + }); + + setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + gui.hideGeneValues(); + } + }); + + setScene(new Scene(tv)); + } +} -- cgit v1.2.3