diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-03-09 17:03:48 -0300 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-03-09 17:03:48 -0300 |
commit | d69fa8746728367646494fd8c2c18944f306c6a2 (patch) | |
tree | f063f9efc6c93a5520991f509f3a481543b73a91 /src/jcgp/gui/population/FunctionSelector.java | |
parent | 9062115b7d15cb05552632dc5486a5cd15a45289 (diff) |
Added existing source code
Diffstat (limited to 'src/jcgp/gui/population/FunctionSelector.java')
-rw-r--r-- | src/jcgp/gui/population/FunctionSelector.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/jcgp/gui/population/FunctionSelector.java b/src/jcgp/gui/population/FunctionSelector.java new file mode 100644 index 0000000..14614e5 --- /dev/null +++ b/src/jcgp/gui/population/FunctionSelector.java @@ -0,0 +1,80 @@ +package jcgp.gui.population; + +import javafx.event.EventHandler; +import javafx.scene.control.Label; +import javafx.scene.input.MouseEvent; +import javafx.scene.layout.VBox; +import jcgp.backend.function.FunctionSet; +import jcgp.gui.constants.Constants; + +/** + * A menu class, exposes all of the allowed functions + * when called by a node, so that the node function can be changed. + * + * + * @author Eduardo Pedroni + * + */ +public class FunctionSelector extends VBox { + + private GUINode target; + + public FunctionSelector(FunctionSet functionSet) { + setFillWidth(true); + setVisible(false); + setStyle("-fx-border-color: #A0A0A0; -fx-border-width: 1 1 0 1"); + + remakeFunctions(functionSet); + + addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() { + @Override + public void handle(MouseEvent event) { + dismiss(); + } + }); + } + + public void remakeFunctions(final FunctionSet fs) { + getChildren().clear(); + + for (int i = 0; i < fs.getAllowedFunctionCount(); i++) { + final int index = i; + Label l = new Label(fs.getAllowedFunction(i).toString()); + l.setMaxWidth(Double.MAX_VALUE); + l.setStyle("-fx-background-color: #FFFFFF; -fx-border-color: #A0A0A0; -fx-border-width: 0 0 1 0; -fx-padding: 2"); + + l.addEventFilter(MouseEvent.MOUSE_ENTERED, new EventHandler<MouseEvent>() { + @Override + public void handle(MouseEvent event) { + ((Label) event.getSource()).setStyle("-fx-background-color: " + Constants.SOFT_HIGHLIGHT_PAINT + "; -fx-border-color: #B0B0B0; -fx-border-width: 0 0 1 0; -fx-padding: 2"); + } + }); + l.addEventFilter(MouseEvent.MOUSE_EXITED, new EventHandler<MouseEvent>() { + @Override + public void handle(MouseEvent event) { + ((Label) event.getSource()).setStyle("-fx-background-color: #FFFFFF; -fx-border-color: #A0A0A0; -fx-border-width: 0 0 1 0; -fx-padding: 2"); + } + }); + l.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { + @Override + public void handle(MouseEvent event) { + //target.setFunction(fs.getAllowedFunction(index)); + dismiss(); + } + }); + + getChildren().add(l); + } + } + + public void relocateAndShow(MouseEvent event, GUINode node) { + relocate(event.getSceneX() - 5, event.getSceneY() - 5); + target = node; + setVisible(true); + } + + private void dismiss() { + setVisible(false); + } + +} |