From 8189116ea4b5db4675e31dfd04a5687d55e29262 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Tue, 6 May 2014 14:29:37 +0100 Subject: Added javadocs, made minor changes to the comments --- src/jcgp/gui/settings/testcase/TestCaseTable.java | 33 ++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'src/jcgp/gui/settings/testcase/TestCaseTable.java') diff --git a/src/jcgp/gui/settings/testcase/TestCaseTable.java b/src/jcgp/gui/settings/testcase/TestCaseTable.java index d4c1ff9..d4f789c 100644 --- a/src/jcgp/gui/settings/testcase/TestCaseTable.java +++ b/src/jcgp/gui/settings/testcase/TestCaseTable.java @@ -20,7 +20,10 @@ import jcgp.backend.resources.Resources; import jcgp.gui.GUI; /** - * + * This is a test case table. For problems that have test cases, + * this table shows the test case inputs and outputs. Clicking on + * a test case (one is shown per row) applies the values to all + * chromosome inputs shows the calculated values throughout the chromosome. * * @author Eduardo Pedroni * @@ -29,17 +32,27 @@ public class TestCaseTable extends Stage { private TableView> table; + /** + * Make a new instance of {@code TestCaseTable}. + * + * @param testCaseProblem the {@code TestCaseProblem} whose data must be displayed. + * @param gui a reference to the GUI. + */ public TestCaseTable(final TestCaseProblem testCaseProblem, final GUI gui) { super(); Resources resources = gui.getExperiment().getResources(); + // create the actual table view table = new TableView>(); + // get test cases from problem ObservableList> testCaseList = testCaseProblem.getTestCases(); + // prepare input and output columns ArrayList, String>> inputs = new ArrayList, String>>(resources.inputs()); ArrayList, String>> outputs = new ArrayList, String>>(resources.outputs()); + // create input columns TableColumn, String> tc; for (int i = 0; i < resources.inputs(); i++) { tc = new TableColumn, String>("I: " + i); @@ -48,13 +61,16 @@ public class TestCaseTable extends Stage { tc.setCellValueFactory(new Callback,String>, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures, String> param) { + // create a new string property and give it the test case value, no need for dynamic binding - this wont change often return new SimpleStringProperty(param.getValue().getInput(index).toString()); } }); tc.setSortable(false); + // set column width so all columns are distributed across the width of the stage tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs())); } + // create output columns for (int o = 0; o < resources.outputs(); o++) { tc = new TableColumn, String>("O: " + o); outputs.add(tc); @@ -62,37 +78,46 @@ public class TestCaseTable extends Stage { tc.setCellValueFactory(new Callback,String>, ObservableValue>() { @Override public ObservableValue call(CellDataFeatures, String> param) { + // create a new string property and give it the test case value, no need for dynamic binding - this wont change often return new SimpleStringProperty(param.getValue().getOutput(index).toString()); } }); tc.setSortable(false); + // set column width so all columns are distributed across the width of the stage tc.prefWidthProperty().bind(table.widthProperty().divide(resources.inputs() + resources.outputs())); } + // add created columns table.getColumns().addAll(inputs); table.getColumns().addAll(outputs); + // populate table with actual data table.setItems(testCaseList); + // apply test case values when a new test case is selected table.getSelectionModel().selectedItemProperty().addListener(new ChangeListener>() { @Override - public void changed( - ObservableValue> observable, TestCase oldValue, TestCase newValue) { + public void changed(ObservableValue> observable, TestCase oldValue, TestCase newValue) { gui.evaluateTestCase(newValue); } }); + // when the stage is closed, clear the selection + // this doesn't work if the stage is closed by the program for some reason... setOnCloseRequest(new EventHandler() { @Override public void handle(WindowEvent event) { gui.hideGeneValues(); - table.getSelectionModel().select(null); + table.getSelectionModel().clearSelection(); } }); setScene(new Scene(table)); } + /** + * @return a reference to the actual table of test cases. + */ public TableView> getTable() { return table; } -- cgit v1.2.3