aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/settings/testcase
diff options
context:
space:
mode:
Diffstat (limited to 'src/jcgp/gui/settings/testcase')
-rw-r--r--src/jcgp/gui/settings/testcase/TestCaseTable.java90
1 files changed, 90 insertions, 0 deletions
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<Object> problem, final GUI gui) {
+ super();
+
+ TableView<TestCase<Object>> tv = new TableView<TestCase<Object>>();
+ ObservableList<TestCase<Object>> testCaseList = problem.getTestCases();
+
+ ArrayList<TableColumn<TestCase<Object>, String>> inputs = new ArrayList<TableColumn<TestCase<Object>, String>>(problem.getInputCount());
+ ArrayList<TableColumn<TestCase<Object>, String>> outputs = new ArrayList<TableColumn<TestCase<Object>, String>>(problem.getOutputCount());
+
+ TableColumn<TestCase<Object>, String> tc;
+ for (int i = 0; i < problem.getInputCount(); i++) {
+ tc = new TableColumn<TestCase<Object>, String>("I: " + i);
+ inputs.add(tc);
+ final int index = i;
+ tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TestCase<Object>,String>, ObservableValue<String>>() {
+ @Override
+ public ObservableValue<String> call(CellDataFeatures<TestCase<Object>, 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<TestCase<Object>, String>("O: " + o);
+ outputs.add(tc);
+ final int index = o;
+ tc.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TestCase<Object>,String>, ObservableValue<String>>() {
+ @Override
+ public ObservableValue<String> call(CellDataFeatures<TestCase<Object>, 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<TestCase<Object>>() {
+ @Override
+ public void changed(
+ ObservableValue<? extends TestCase<Object>> observable, TestCase<Object> oldValue, TestCase<Object> newValue) {
+ gui.evaluateTestCase(newValue);
+ }
+ });
+
+ setOnCloseRequest(new EventHandler<WindowEvent>() {
+ @Override
+ public void handle(WindowEvent event) {
+ gui.hideGeneValues();
+ }
+ });
+
+ setScene(new Scene(tv));
+ }
+}