diff options
author | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-21 00:09:55 +0100 |
---|---|---|
committer | Eduardo Pedroni <ep625@york.ac.uk> | 2014-04-21 00:09:55 +0100 |
commit | efe490fec1c7a94f004b496c7c97c82083fe44ec (patch) | |
tree | ffe7a8bb411a9208c3220247247081eb90ac4fc0 /src/jcgp/gui | |
parent | 88314e71f908efcfc38da3b800319c171a6ccceb (diff) |
Tooltips are looking strange, checking on a different machine
Diffstat (limited to 'src/jcgp/gui')
-rw-r--r-- | src/jcgp/gui/population/GUIInput.java | 22 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUINode.java | 2 | ||||
-rw-r--r-- | src/jcgp/gui/population/GUIOutput.java | 2 | ||||
-rw-r--r-- | src/jcgp/gui/settings/SettingsPane.java | 76 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIDoubleParameter.java | 41 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIIntegerParameter.java | 32 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIParameter.java | 12 | ||||
-rw-r--r-- | src/jcgp/gui/settings/testcase/TestCaseTable.java | 18 |
8 files changed, 110 insertions, 95 deletions
diff --git a/src/jcgp/gui/population/GUIInput.java b/src/jcgp/gui/population/GUIInput.java index 6a783db..065c125 100644 --- a/src/jcgp/gui/population/GUIInput.java +++ b/src/jcgp/gui/population/GUIInput.java @@ -7,7 +7,6 @@ import javafx.scene.paint.Paint; import javafx.scene.shape.Circle; import jcgp.backend.population.Connection; import jcgp.backend.population.Input; -import jcgp.backend.population.Output; import jcgp.gui.GUI; public class GUIInput extends GUIGene { @@ -40,20 +39,12 @@ public class GUIInput extends GUIGene { // the drag has entered this node, react appropriately // this happens even if we are the source of the drag ((GUIGene) event.getGestureSource()).setConnectionLine((GUIGene) event.getSource()); - - if (event.getGestureSource() instanceof GUINode) { - Connection source = ((GUINode) event.getGestureSource()).getChangingConnection(); - if (input == source) { - setState(GUIGeneState.NO_CHANGE_TARGET); - return; - } - } else if (event.getGestureSource() instanceof GUIOutput) { - Output source = ((GUIOutput) event.getGestureSource()).getGene(); - if (((GUIGene) event.getSource()).getGene() == source.getSource()) { - ((GUIGene) event.getSource()).setState(GUIGeneState.NO_CHANGE_TARGET); - } + Connection source = ((GUIGene) event.getGestureSource()).getChangingConnection(); + if (input == source) { + setState(GUIGeneState.NO_CHANGE_TARGET); + } else { + setState(GUIGeneState.TARGET); } - setState(GUIGeneState.TARGET); } }); @@ -170,7 +161,6 @@ public class GUIInput extends GUIGene { break; default: break; - } } @@ -241,7 +231,7 @@ public class GUIInput extends GUIGene { @Override public void updateText() { if (parent.isEvaluating()) { - text.setText("I: " + input.getIndex() + "\nValue: " + value.toString()); + text.setText("I: " + input.getIndex() + "\n" + value.toString()); } else { text.setText("I: " + input.getIndex()); } diff --git a/src/jcgp/gui/population/GUINode.java b/src/jcgp/gui/population/GUINode.java index 2b953c0..f50edd3 100644 --- a/src/jcgp/gui/population/GUINode.java +++ b/src/jcgp/gui/population/GUINode.java @@ -454,7 +454,7 @@ public class GUINode extends GUIGene { public void updateText() { if (parent.isEvaluating()) { - text.setText(node.getFunction().getName() + "\nValue: " + value.toString()); + text.setText(node.getFunction().getName() + "\n" + value.toString()); } else { text.setText(node.getFunction().getName()); } diff --git a/src/jcgp/gui/population/GUIOutput.java b/src/jcgp/gui/population/GUIOutput.java index 89c12b3..79159b9 100644 --- a/src/jcgp/gui/population/GUIOutput.java +++ b/src/jcgp/gui/population/GUIOutput.java @@ -321,7 +321,7 @@ public class GUIOutput extends GUIGene { @Override public void updateText() { if (parent.isEvaluating()) { - text.setText("O: " + output.getIndex() + "\nValue: " + value.toString()); + text.setText("O: " + output.getIndex() + "\n" + value.toString()); } else { text.setText("O: " + output.getIndex()); } diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index 4e8c342..4050a89 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; -import javafx.scene.Group; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; @@ -125,8 +124,7 @@ public class SettingsPane extends AnchorPane { eaCBox.getSelectionModel().select(jcgp.getEvolutionaryStrategy()); eaCBox.prefWidthProperty().bind(mainContainer.widthProperty()); - final VBox eaParameters = new VBox(); - eaParameters.setSpacing(2); + final VBox eaParameters = new VBox(2); if (jcgp.getEvolutionaryStrategy().getLocalParameters() != null) { refreshParameters(jcgp.getEvolutionaryStrategy().getLocalParameters(), eaParameters); @@ -158,8 +156,7 @@ public class SettingsPane extends AnchorPane { mutatorCBox.getSelectionModel().select(jcgp.getMutator()); mutatorCBox.prefWidthProperty().bind(mainContainer.widthProperty()); - final VBox mutatorParameters = new VBox(); - mutatorParameters.setSpacing(2); + final VBox mutatorParameters = new VBox(2); if (jcgp.getEvolutionaryStrategy().getLocalParameters() != null) { refreshParameters(jcgp.getMutator().getLocalParameters(), mutatorParameters); } @@ -190,23 +187,27 @@ public class SettingsPane extends AnchorPane { problemCBox.getSelectionModel().select(jcgp.getProblem()); problemCBox.prefWidthProperty().bind(mainContainer.widthProperty()); - final VBox problemParameters = new VBox(); - problemParameters.setSpacing(2); + final VBox problemParameters = new VBox(2); problemParameters.setPadding(new Insets(0, 0, 4, 0)); if (jcgp.getProblem().getLocalParameters() != null) { refreshParameters(jcgp.getProblem().getLocalParameters(), problemParameters); } - final Group showTestCaseContainer = new Group(); + final HBox testCaseControlContainer = new HBox(2); + final Button showTestCaseButton = makeTestCaseButton(); + final Button loadTestCaseButton = makeLoadTestCaseButton(); + HBox.setHgrow(showTestCaseButton, Priority.ALWAYS); + showTestCaseButton.setMaxWidth(Double.MAX_VALUE); + HBox.setHgrow(loadTestCaseButton, Priority.ALWAYS); + loadTestCaseButton.setMaxWidth(Double.MAX_VALUE); + if (jcgp.getProblem() instanceof TestCaseProblem<?>) { - showTestCaseContainer.getChildren().add(showTestCaseButton); - - testCaseTable = new TestCaseTable((TestCaseProblem<Object>) jcgp.getProblem(), gui); + testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadTestCaseButton); + remakeTestCaseTable(); } - nodeFunctions = new VBox(); - nodeFunctions.setSpacing(2); + nodeFunctions = new VBox(2); nodeFunctions.setPadding(new Insets(0, 0, 4, 0)); refreshFunctions(); @@ -220,20 +221,40 @@ public class SettingsPane extends AnchorPane { testCaseTable.close(); gui.setEvaluating(false); refreshFunctions(); - showTestCaseContainer.getChildren().clear(); + testCaseControlContainer.getChildren().clear(); if (jcgp.getProblem() instanceof TestCaseProblem) { - showTestCaseContainer.getChildren().add(showTestCaseButton); - testCaseTable = new TestCaseTable((TestCaseProblem<Object>) jcgp.getProblem(), gui); + testCaseControlContainer.getChildren().addAll(showTestCaseButton, loadTestCaseButton); + remakeTestCaseTable(); } gui.reset(); } }); - problemPane.getChildren().addAll(header, problemCBox, problemParameters, nodeFunctions, showTestCaseContainer); + problemPane.getChildren().addAll(header, problemCBox, problemParameters, nodeFunctions, testCaseControlContainer); mainContainer.getChildren().add(problemPane); } + private Button makeLoadTestCaseButton() { + Button b = new Button("Load test cases"); + b.setOnAction(new EventHandler<ActionEvent>() { + @Override + public void handle(ActionEvent event) { + FileChooser fc = new FileChooser(); + fc.setTitle("Open test case file..."); + fc.getExtensionFilters().add(new ExtensionFilter("CGP " + gui.getExperiment().getProblem() + " files", "*" + ((TestCaseProblem<?>) gui.getExperiment().getProblem()).getFileExtension())); + fc.getExtensionFilters().add(new ExtensionFilter("All files", "*.*")); + File chrFile = fc.showOpenDialog(gui.getStage()); + if (chrFile != null) { + gui.getExperiment().loadTestCases(chrFile); + remakeTestCaseTable(); + gui.reDraw(); + } + } + }); + return b; + } + private Button makeTestCaseButton() { Button b = new Button("Show test cases"); b.setOnAction(new EventHandler<ActionEvent>() { @@ -295,9 +316,9 @@ public class SettingsPane extends AnchorPane { File parFile = fc.showOpenDialog(gui.getStage()); if (parFile != null) { gui.getExperiment().loadParameters(parFile); + gui.reDraw(); + refreshFunctions(); } - gui.reDraw(); - refreshFunctions(); } }); @@ -311,14 +332,14 @@ public class SettingsPane extends AnchorPane { File chrFile = fc.showOpenDialog(gui.getStage()); if (chrFile != null) { gui.getExperiment().loadChromosome(chrFile); + gui.reDraw(); } - gui.reDraw(); } }); saveChromosome.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { - //gui.step(); + } }); @@ -458,10 +479,21 @@ public class SettingsPane extends AnchorPane { loadChromosome.setDisable(running); saveChromosome.setDisable(running); - testCaseTable.getTable().setDisable(running); } + private void remakeTestCaseTable() { + boolean wasShowing = false; + if (testCaseTable != null) { + wasShowing = testCaseTable.isShowing(); + testCaseTable.close(); + } + testCaseTable = new TestCaseTable((TestCaseProblem<Object>) gui.getExperiment().getProblem(), gui); + if (wasShowing) { + testCaseTable.show(); + } + } + public TestCaseTable getTestCaseTable() { return testCaseTable; } diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java index 29648ca..9a6ec4a 100644 --- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java @@ -1,12 +1,12 @@ package jcgp.gui.settings.parameters; +import java.text.DecimalFormat; + import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.control.Control; import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; import jcgp.backend.resources.parameters.Parameter; import jcgp.backend.resources.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; @@ -23,6 +23,7 @@ import jcgp.gui.settings.SettingsPane; public class GUIDoubleParameter extends GUIParameter<Number> { private TextField textField; + private DecimalFormat decimalFormat; /** * This default-visibility constructor is intended for use @@ -31,6 +32,8 @@ public class GUIDoubleParameter extends GUIParameter<Number> { */ GUIDoubleParameter(Parameter<Number> parameter, SettingsPane sp) { super(parameter, sp); + decimalFormat = new DecimalFormat(); + decimalFormat.setMaximumFractionDigits(10); } @Override @@ -38,23 +41,12 @@ public class GUIDoubleParameter extends GUIParameter<Number> { textField = new TextField(String.valueOf(parameter.get())); textField.setStyle(VALID_PARAMETER_STYLE); textField.setAlignment(Pos.CENTER_RIGHT); - + textField.prefWidthProperty().bind(widthProperty().divide(2)); return textField; } @Override protected void setControlListeners() { - /* filter keypresses and ignore anything that is not a number - * and any decimal point beyond the first ones */ - textField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() { - @Override - public void handle( KeyEvent t ) { - char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1]; - if (!((ch >= '0' && ch <= '9') || (ch == '.' && !textField.getText().contains(".")))) { - t.consume(); - } - } - }); /* pass the TextField value back to the parameter whenever it gets * modified, provided it is not empty and the experiment isn't running */ textField.textProperty().addListener(new ChangeListener<String>() { @@ -62,11 +54,17 @@ public class GUIDoubleParameter extends GUIParameter<Number> { public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { - if (!newValue.isEmpty() && !settingsPane.isExperimentRunning()) { - parameter.set(Double.parseDouble(newValue)); - settingsPane.revalidateParameters(); + if (!settingsPane.isExperimentRunning()) { + if (newValue.matches("([0-9]*[.]*[0-9]*)")) { + if (!newValue.isEmpty()) { + double value = Double.parseDouble(newValue); + parameter.set(value); + settingsPane.revalidateParameters(); + } + } else { + refreshValue(); + } } - } }); /* if the TextField loses focus and is empty, set it to the current @@ -76,8 +74,8 @@ public class GUIDoubleParameter extends GUIParameter<Number> { public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { - if (!newValue && textField.getText().isEmpty()) { - textField.setText(String.valueOf(parameter.get())); + if (!newValue) { + refreshValue(); } } }); @@ -102,6 +100,7 @@ public class GUIDoubleParameter extends GUIParameter<Number> { @Override public void refreshValue() { - textField.setText(String.valueOf((parameter).get())); + System.out.println("setting text to: " + parameter.get().doubleValue()); + textField.setText(decimalFormat.format(parameter.get().doubleValue())); } } diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java index da2c11f..ee266f3 100644 --- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java @@ -2,11 +2,9 @@ package jcgp.gui.settings.parameters; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.control.Control; import javafx.scene.control.TextField; -import javafx.scene.input.KeyEvent; import jcgp.backend.resources.parameters.Parameter; import jcgp.backend.resources.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; @@ -38,22 +36,13 @@ public class GUIIntegerParameter extends GUIParameter<Number> { textField = new TextField(String.valueOf(parameter.get())); textField.setStyle(VALID_PARAMETER_STYLE); textField.setAlignment(Pos.CENTER_RIGHT); + textField.prefWidthProperty().bind(widthProperty().divide(2)); return textField; } @Override protected void setControlListeners() { - /* filter keypresses and ignore anything that is not a number */ - textField.addEventFilter(KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() { - @Override - public void handle( KeyEvent t ) { - char ch = t.getCharacter().toCharArray()[t.getCharacter().toCharArray().length - 1]; - if (!(ch >= '0' && ch <= '9')) { - t.consume(); - } - } - }); /* pass the TextField value back to the parameter whenever it gets * modified, provided it is not empty and the experiment isn't running */ textField.textProperty().addListener(new ChangeListener<String>() { @@ -61,9 +50,16 @@ public class GUIIntegerParameter extends GUIParameter<Number> { public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { - if (!newValue.isEmpty() && !settingsPane.isExperimentRunning()) { - parameter.set(Double.parseDouble(newValue)); - settingsPane.revalidateParameters(); + if (!settingsPane.isExperimentRunning()) { + if (newValue.matches("[0-9]*")) { + if (!newValue.isEmpty()) { + int value = Integer.parseInt(newValue); + parameter.set(value); + settingsPane.revalidateParameters(); + } + } else { + refreshValue(); + } } } }); @@ -74,8 +70,8 @@ public class GUIIntegerParameter extends GUIParameter<Number> { public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { - if (!newValue && textField.getText().isEmpty()) { - textField.setText(String.valueOf(parameter.get())); + if (!newValue) { + refreshValue(); } } }); @@ -101,6 +97,6 @@ public class GUIIntegerParameter extends GUIParameter<Number> { @Override public void refreshValue() { - textField.setText(String.valueOf((parameter).get())); + textField.setText(String.valueOf(parameter.get())); } } diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index 159e709..7dd7231 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -7,10 +7,9 @@ import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Pos; import javafx.scene.control.Control; +import javafx.scene.control.Label; import javafx.scene.control.Tooltip; import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; -import javafx.scene.text.Text; import jcgp.backend.resources.parameters.BooleanParameter; import jcgp.backend.resources.parameters.DoubleParameter; import jcgp.backend.resources.parameters.IntegerParameter; @@ -46,7 +45,7 @@ public abstract class GUIParameter<T> extends HBox { public static final String WARNING_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_SELECTION_COLOUR; public static final String VALID_PARAMETER_STYLE = "-fx-background-color: " + GUI.NEUTRAL_COLOUR; - private Text name; + private Label name; private Control valueControl; protected SettingsPane settingsPane; @@ -80,9 +79,9 @@ public abstract class GUIParameter<T> extends HBox { setAlignment(Pos.CENTER_LEFT); setSpacing(5); - name = new Text(parameter.getName()); + name = new Label(parameter.getName()); // set text width to half of the total width of the GUIParameter - name.wrappingWidthProperty().bind(widthProperty().divide(2)); + name.prefWidthProperty().bind(widthProperty().divide(2)); // the tooltip is the hover-over label containing status information, when appropriate tooltip = new Tooltip(); @@ -90,7 +89,6 @@ public abstract class GUIParameter<T> extends HBox { tooltip.setSkin(null); valueControl = makeControl(); - setHgrow(valueControl, Priority.ALWAYS); // if the parameter is a monitor, it should be permanently disabled valueControl.setDisable(parameter.isMonitor()); @@ -177,7 +175,7 @@ public abstract class GUIParameter<T> extends HBox { */ public void validate() { parameter.validate(parameter.get()); - refreshValue(); + //refreshValue(); setValidityStyle(); } diff --git a/src/jcgp/gui/settings/testcase/TestCaseTable.java b/src/jcgp/gui/settings/testcase/TestCaseTable.java index b84f9ab..d7b2e2b 100644 --- a/src/jcgp/gui/settings/testcase/TestCaseTable.java +++ b/src/jcgp/gui/settings/testcase/TestCaseTable.java @@ -19,7 +19,6 @@ import jcgp.backend.modules.problem.TestCaseProblem.TestCase; import jcgp.gui.GUI; /** - * Dont forget to override toString()! * * * @author Eduardo Pedroni @@ -29,17 +28,17 @@ public class TestCaseTable extends Stage { private TableView<TestCase<Object>> table; - public TestCaseTable(final TestCaseProblem<Object> problem, final GUI gui) { + public TestCaseTable(final TestCaseProblem<Object> testCaseProblem, final GUI gui) { super(); table = new TableView<TestCase<Object>>(); - ObservableList<TestCase<Object>> testCaseList = problem.getTestCases(); + ObservableList<TestCase<Object>> testCaseList = testCaseProblem.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()); + ArrayList<TableColumn<TestCase<Object>, String>> inputs = new ArrayList<TableColumn<TestCase<Object>, String>>(testCaseProblem.getInputCount()); + ArrayList<TableColumn<TestCase<Object>, String>> outputs = new ArrayList<TableColumn<TestCase<Object>, String>>(testCaseProblem.getOutputCount()); TableColumn<TestCase<Object>, String> tc; - for (int i = 0; i < problem.getInputCount(); i++) { + for (int i = 0; i < testCaseProblem.getInputCount(); i++) { tc = new TableColumn<TestCase<Object>, String>("I: " + i); inputs.add(tc); final int index = i; @@ -50,10 +49,10 @@ public class TestCaseTable extends Stage { } }); tc.setSortable(false); - tc.prefWidthProperty().bind(table.widthProperty().divide(problem.getInputCount() + problem.getOutputCount())); + tc.prefWidthProperty().bind(table.widthProperty().divide(testCaseProblem.getInputCount() + testCaseProblem.getOutputCount())); } - for (int o = 0; o < problem.getOutputCount(); o++) { + for (int o = 0; o < testCaseProblem.getOutputCount(); o++) { tc = new TableColumn<TestCase<Object>, String>("O: " + o); outputs.add(tc); final int index = o; @@ -64,7 +63,7 @@ public class TestCaseTable extends Stage { } }); tc.setSortable(false); - tc.prefWidthProperty().bind(table.widthProperty().divide(problem.getInputCount() + problem.getOutputCount())); + tc.prefWidthProperty().bind(table.widthProperty().divide(testCaseProblem.getInputCount() + testCaseProblem.getOutputCount())); } table.getColumns().addAll(inputs); @@ -84,6 +83,7 @@ public class TestCaseTable extends Stage { @Override public void handle(WindowEvent event) { gui.hideGeneValues(); + table.getSelectionModel().select(null); } }); |