diff options
Diffstat (limited to 'src/jcgp/gui/settings')
-rw-r--r-- | src/jcgp/gui/settings/SettingsPane.java | 184 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIBooleanParameter.java | 11 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIDoubleParameter.java | 17 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIIntegerParameter.java | 17 | ||||
-rw-r--r-- | src/jcgp/gui/settings/parameters/GUIParameter.java | 18 |
5 files changed, 92 insertions, 155 deletions
diff --git a/src/jcgp/gui/settings/SettingsPane.java b/src/jcgp/gui/settings/SettingsPane.java index cb066b7..8c707d3 100644 --- a/src/jcgp/gui/settings/SettingsPane.java +++ b/src/jcgp/gui/settings/SettingsPane.java @@ -5,12 +5,10 @@ import java.util.ArrayList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; -import javafx.scene.Cursor; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; import javafx.scene.control.ComboBox; import javafx.scene.control.ScrollPane; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Priority; @@ -23,26 +21,21 @@ import jcgp.backend.function.FunctionSet; import jcgp.backend.modules.ea.EvolutionaryAlgorithm; import jcgp.backend.modules.fitness.FitnessFunction; import jcgp.backend.modules.mutator.Mutator; -import jcgp.backend.parameters.IntegerParameter; -import jcgp.backend.parameters.Parameter; +import jcgp.backend.resources.parameters.Parameter; import jcgp.gui.GUI; -import jcgp.gui.settings.parameters.*; +import jcgp.gui.settings.parameters.GUIParameter; public class SettingsPane extends AnchorPane { private VBox mainContainer; - private VBox bpPane, eaPane, mutatorPane, ffPane, nfPane; + private VBox baseParameterPane, eaPane, mutatorPane, ffPane, nfPane; - private Button runPause; + private Button runPause = new Button("Run"), step = new Button("Step"), reset = new Button("Reset"); private ArrayList<GUIParameter> parameters = new ArrayList<GUIParameter>(); - private boolean dragging = false; - public SettingsPane(JCGP cgp, GUI gui) { super(); - - setResizeListeners(); mainContainer = new VBox(8); mainContainer.setPadding(new Insets(5, GUI.RESIZE_MARGIN, 0, 2)); @@ -50,15 +43,13 @@ public class SettingsPane extends AnchorPane { setMinWidth(GUI.SETTINGS_WIDTH); setPrefWidth(GUI.SETTINGS_WIDTH); - initialiseBaseParameters(cgp, gui); + initialiseBaseParameters(cgp); initialiseEAParameters(cgp); initialiseMutatorParameters(cgp); - initialiseFitnessFunctionParameters(cgp); - - initialiseNodeFunctionParameters(cgp); + initialiseProblemTypeParameters(cgp, gui); createControls(cgp, gui); @@ -75,35 +66,39 @@ public class SettingsPane extends AnchorPane { getChildren().add(scroll); } - private void initialiseBaseParameters(JCGP cgp, GUI gui) { - bpPane = new VBox(2); + private void initialiseBaseParameters(JCGP cgp) { + baseParameterPane = new VBox(2); Text header = new Text("Base Parameters"); header.setFont(Font.font("Arial", 14)); header.setUnderline(true); - bpPane.getChildren().add(header); - - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("rows"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("columns"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("inputs"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("outputs"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("levelsBack"), this)); - - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("popSize"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("generations"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("runs"), this)); - - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentGen"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("currentRun"), this)); - - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("maxFitness"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("seed"), this)); - parameters.add(GUIParameter.create((IntegerParameter) cgp.getResources().getParameter("report"), this)); - - bpPane.getChildren().addAll(parameters); - - mainContainer.getChildren().add(bpPane); + baseParameterPane.getChildren().add(header); + + parameters.add(GUIParameter.create(cgp.getResources().getParameter("rows"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("columns"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("inputs"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("outputs"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("levelsBack"), this)); + + GUIParameter gp = GUIParameter.create(cgp.getResources().getParameter("popSize"), this); + gp.setPadding(new Insets(0, 0, 10, 0)); + parameters.add(gp); + + parameters.add(GUIParameter.create(cgp.getResources().getParameter("currentGen"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("generations"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("currentRun"), this)); + + gp = GUIParameter.create(cgp.getResources().getParameter("runs"), this); + gp.setPadding(new Insets(0, 0, 10, 0)); + parameters.add(gp); + + parameters.add(GUIParameter.create(cgp.getResources().getParameter("seed"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("report"), this)); + parameters.add(GUIParameter.create(cgp.getResources().getParameter("maxFitness"), this)); + + baseParameterPane.getChildren().addAll(parameters); + mainContainer.getChildren().add(baseParameterPane); } private void initialiseEAParameters(final JCGP cgp) { @@ -172,10 +167,10 @@ public class SettingsPane extends AnchorPane { mainContainer.getChildren().add(mutatorPane); } - private void initialiseFitnessFunctionParameters(final JCGP cgp) { + private void initialiseProblemTypeParameters(final JCGP cgp, final GUI gui) { ffPane= new VBox(2); - Text header = new Text("Fitness Function"); + Text header = new Text("Problem type"); header.setFont(Font.font("Arial", 14)); header.setUnderline(true); @@ -200,36 +195,13 @@ public class SettingsPane extends AnchorPane { } }); - ffPane.getChildren().addAll(header, ffCBox, ffParameters); - mainContainer.getChildren().add(ffPane); - - } - - private void initialiseNodeFunctionParameters(JCGP cgp) { - nfPane = new VBox(2); - - Text header = new Text("Node Functions"); - header.setFont(Font.font("Arial", 14)); - header.setUnderline(true); - - final ComboBox<FunctionSet> nfCBox = new ComboBox<FunctionSet>(); - nfCBox.getItems().addAll(cgp.getResources().getFunctionSets()); - nfCBox.getSelectionModel().select(cgp.getResources().getFunctionSet()); - nfCBox.prefWidthProperty().bind(mainContainer.widthProperty()); - final VBox nfParameters = new VBox(); nfParameters.setSpacing(2); - refreshFunctions(cgp.getResources().getFunctionSet(), nfParameters); + refreshFunctions(cgp.getResources().getFunctionSet(), nfParameters, gui); - nfCBox.setOnAction(new EventHandler<ActionEvent>() { - @Override - public void handle(ActionEvent event) { - refreshFunctions(nfCBox.getSelectionModel().getSelectedItem(), nfParameters); - } - }); + ffPane.getChildren().addAll(header, ffCBox, ffParameters, nfParameters); + mainContainer.getChildren().add(ffPane); - nfPane.getChildren().addAll(header, nfCBox, nfParameters); - mainContainer.getChildren().add(nfPane); } private void createControls(final JCGP cgp, final GUI gui) { @@ -237,7 +209,6 @@ public class SettingsPane extends AnchorPane { controls.setFillWidth(true); final HBox flowButtons = new HBox(2); - runPause = new Button("Run"); runPause.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { @@ -245,7 +216,7 @@ public class SettingsPane extends AnchorPane { } }); - Button step = new Button("Step"); + step = new Button("Step"); step.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { @@ -253,7 +224,7 @@ public class SettingsPane extends AnchorPane { } }); - Button reset = new Button("Reset"); + reset = new Button("Reset"); reset.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { @@ -265,10 +236,8 @@ public class SettingsPane extends AnchorPane { HBox.setHgrow(runPause, Priority.ALWAYS); runPause.setMaxWidth(Double.MAX_VALUE); - HBox.setHgrow(step, Priority.ALWAYS); step.setMaxWidth(Double.MAX_VALUE); - HBox.setHgrow(reset, Priority.ALWAYS); reset.setMaxWidth(Double.MAX_VALUE); @@ -293,7 +262,7 @@ public class SettingsPane extends AnchorPane { revalidateParameters(); } - private void refreshFunctions(final FunctionSet fs, VBox vb) { + private void refreshFunctions(final FunctionSet fs, VBox vb, final GUI gui) { vb.getChildren().clear(); CheckBox cb; for (int i = 0; i < fs.getTotalFunctionCount(); i++) { @@ -309,69 +278,30 @@ public class SettingsPane extends AnchorPane { } else { fs.disableFunction(index); } + GUI.updateFunctionSelector(); } }); vb.getChildren().add(cb); + + GUI.updateFunctionSelector(); } } - private void setResizeListeners() { - setOnMousePressed(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(isInDraggableZone(event)) { - dragging = true; - } - } - }); - setOnMouseDragged(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(dragging) { - double newWidth = getWidth() - event.getX(); - if (newWidth >= getMinWidth()) { - setPrefWidth(newWidth); - } else { - setPrefWidth(getMinWidth()); - } - } - } - }); - setOnMouseMoved(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - if(isInDraggableZone(event) || dragging) { - setCursor(Cursor.H_RESIZE); - } - else { - setCursor(Cursor.DEFAULT); - } - } - }); - setOnMouseReleased(new EventHandler<MouseEvent>() { - @Override - public void handle(MouseEvent event) { - dragging = false; - setCursor(Cursor.DEFAULT); - } - }); - } - - private boolean isInDraggableZone(MouseEvent event) { - return event.getX() < (GUI.RESIZE_MARGIN); - } + - public void disableSettings(boolean value) { - bpPane.setDisable(value); + public void runningMode(boolean value) { + baseParameterPane.setDisable(value); eaPane.setDisable(value); mutatorPane.setDisable(value); ffPane.setDisable(value); nfPane.setDisable(value); + step.setDisable(value); + reset.setDisable(value); + + runPause.setText(value ? "Pause" : "Run"); } /** - * Writes the GUI parameter value back to the resources parameter, - * if any changes were made. * * @return true if the experiment needs to be reset, false otherwise. */ @@ -394,8 +324,12 @@ public class SettingsPane extends AnchorPane { } public void revalidateParameters() { + runPause.setDisable(false); for (GUIParameter parameter : parameters) { parameter.validate(); + if (parameter.requiresReset()) { + runPause.setDisable(true); + } } } @@ -404,10 +338,4 @@ public class SettingsPane extends AnchorPane { parameter.applyValue(); } } - - public Button getRunButton() { - return runPause; - } - - } diff --git a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java index fc66e7d..4339562 100644 --- a/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIBooleanParameter.java @@ -3,9 +3,8 @@ package jcgp.gui.settings.parameters; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.control.CheckBox; -import jcgp.backend.parameters.BooleanParameter; -import jcgp.backend.parameters.ParameterStatus; -import jcgp.gui.GUI; +import jcgp.backend.resources.parameters.BooleanParameter; +import jcgp.backend.resources.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; public class GUIBooleanParameter extends GUIParameter { @@ -65,15 +64,15 @@ public class GUIBooleanParameter extends GUIParameter { */ private void setValidityStyle() { if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_CHECKBOX_STYLE + INVALID_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setStyle(BASE_CHECKBOX_STYLE + WARNING_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_CHECKBOX_STYLE + VALID_PARAMETER_STYLE); valueControl.setTooltip(null); } } diff --git a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java index 190f4b7..eecff2d 100644 --- a/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIDoubleParameter.java @@ -8,9 +8,8 @@ import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.layout.Priority; import javafx.scene.text.Text; -import jcgp.backend.parameters.DoubleParameter; -import jcgp.backend.parameters.ParameterStatus; -import jcgp.gui.GUI; +import jcgp.backend.resources.parameters.DoubleParameter; +import jcgp.backend.resources.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; public class GUIDoubleParameter extends GUIParameter { @@ -26,13 +25,14 @@ public class GUIDoubleParameter extends GUIParameter { name = new Text(parameter.getName()); valueControl = new TextField(String.valueOf(parameter.get())); - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setStyle(VALID_PARAMETER_STYLE); ((TextField) valueControl).setAlignment(Pos.CENTER_RIGHT); setHgrow(valueControl, Priority.ALWAYS); + setHgrow(name, Priority.ALWAYS); - name.setWrappingWidth(GUI.WRAP_WIDTH); + name.wrappingWidthProperty().bind(widthProperty().divide(2)); ((TextField) valueControl).setEditable(!parameter.isMonitor()); @@ -41,6 +41,7 @@ public class GUIDoubleParameter extends GUIParameter { makeLightBinding(); } else { valueControl.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) valueControl).getText().contains(".")))) { @@ -101,15 +102,15 @@ public class GUIDoubleParameter extends GUIParameter { private void setValidityStyle() { if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + INVALID_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + WARNING_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + VALID_PARAMETER_STYLE); valueControl.setTooltip(null); } } diff --git a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java index a2040d7..9c84c6a 100644 --- a/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIIntegerParameter.java @@ -8,9 +8,8 @@ import javafx.scene.control.TextField; import javafx.scene.input.KeyEvent; import javafx.scene.layout.Priority; import javafx.scene.text.Text; -import jcgp.backend.parameters.IntegerParameter; -import jcgp.backend.parameters.ParameterStatus; -import jcgp.gui.GUI; +import jcgp.backend.resources.parameters.IntegerParameter; +import jcgp.backend.resources.parameters.ParameterStatus; import jcgp.gui.settings.SettingsPane; public class GUIIntegerParameter extends GUIParameter { @@ -26,13 +25,14 @@ public class GUIIntegerParameter extends GUIParameter { name = new Text(parameter.getName()); valueControl = new TextField(String.valueOf(parameter.get())); - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setStyle(VALID_PARAMETER_STYLE); ((TextField) valueControl).setAlignment(Pos.CENTER_RIGHT); setHgrow(valueControl, Priority.ALWAYS); + setHgrow(name, Priority.ALWAYS); - name.setWrappingWidth(GUI.WRAP_WIDTH); + name.wrappingWidthProperty().bind(widthProperty().divide(2)); ((TextField) valueControl).setEditable(!parameter.isMonitor()); @@ -41,6 +41,7 @@ public class GUIIntegerParameter extends GUIParameter { makeLightBinding(); } else { valueControl.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')) { @@ -101,15 +102,15 @@ public class GUIIntegerParameter extends GUIParameter { private void setValidityStyle() { if (parameter.getStatus() == ParameterStatus.INVALID) { - valueControl.setStyle(GUI.INVALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + INVALID_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else if (parameter.getStatus() == ParameterStatus.WARNING || parameter.getStatus() == ParameterStatus.WARNING_RESET) { - valueControl.setStyle(GUI.WARNING_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + WARNING_PARAMETER_STYLE); valueControl.setTooltip(tooltip); tooltip.setText(parameter.getStatus().getDetails()); } else { - valueControl.setStyle(GUI.VALID_PARAMETER_STYLE); + valueControl.setStyle(BASE_TEXT_STYLE + VALID_PARAMETER_STYLE); valueControl.setTooltip(null); } } diff --git a/src/jcgp/gui/settings/parameters/GUIParameter.java b/src/jcgp/gui/settings/parameters/GUIParameter.java index da2fe86..6bfdf30 100644 --- a/src/jcgp/gui/settings/parameters/GUIParameter.java +++ b/src/jcgp/gui/settings/parameters/GUIParameter.java @@ -10,14 +10,22 @@ import javafx.scene.control.Control; import javafx.scene.control.Tooltip; import javafx.scene.layout.HBox; import javafx.scene.text.Text; -import jcgp.backend.parameters.BooleanParameter; -import jcgp.backend.parameters.DoubleParameter; -import jcgp.backend.parameters.IntegerParameter; -import jcgp.backend.parameters.Parameter; -import jcgp.backend.parameters.ParameterStatus; +import jcgp.backend.resources.parameters.BooleanParameter; +import jcgp.backend.resources.parameters.DoubleParameter; +import jcgp.backend.resources.parameters.IntegerParameter; +import jcgp.backend.resources.parameters.Parameter; +import jcgp.backend.resources.parameters.ParameterStatus; +import jcgp.gui.GUI; import jcgp.gui.settings.SettingsPane; public abstract class GUIParameter extends HBox { + + public static final String BASE_TEXT_STYLE = "-fx-border-color: #C9C9C9; -fx-border-radius: 2; -fx-padding: 0; "; + public static final String BASE_CHECKBOX_STYLE = "-fx-padding: 0; "; + + public static final String INVALID_PARAMETER_STYLE = "-fx-background-color: " + GUI.BAD_SELECTION_COLOUR; + 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; protected Parameter parameter; protected Text name; |