From 7e71f6fad38a8f372afd0b035ce24999d9950183 Mon Sep 17 00:00:00 2001 From: Zeynep Date: Wed, 29 May 2024 18:28:16 +0200 Subject: [PATCH] Revert "changed comments" This reverts commit b3b9660c9b0289a89b3c101daba8d18a2791354e. --- .../mortar/gui/controls/ToggleSwitch.java | 73 ++++++++++--------- .../mortar/gui/views/SettingsView.java | 13 +++- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/main/java/de/unijena/cheminf/mortar/gui/controls/ToggleSwitch.java b/src/main/java/de/unijena/cheminf/mortar/gui/controls/ToggleSwitch.java index 58c17a1f..84b53812 100644 --- a/src/main/java/de/unijena/cheminf/mortar/gui/controls/ToggleSwitch.java +++ b/src/main/java/de/unijena/cheminf/mortar/gui/controls/ToggleSwitch.java @@ -38,14 +38,7 @@ import javafx.util.Duration; /** - * This class implements a toggle switch to en- and disable features in settings. The toggle switch is built by putting - * a circle on Itop of a rectangle. The corners of the rectangle were adjusted to fit the round shape of the circle. - * The transition of the position of the circle is animated and parallel to the rectangle's color change - * which demonstrates the current state. For example, blue and circle on the right means "on"/grey and circle - * transitions to left means "off". This class extends Control, however methods for resizing the switch - * are not implemented yet. - * The following code is inspired by "JavaFX UI: iOS Style Toggle Switch", uploaded by Almas Baimagambetov on YouTube. - * See https://youtu.be/maX5ymmQixM?si=v2ULa57-pjCmoQlf, (last time viewed on 05/17/2024, 10:33) + * A toggle switch to en- and disable features in settings. * * @author Zeynep Dagtekin * @version 1.0.0.0 @@ -63,9 +56,9 @@ public class ToggleSwitch extends Control { /** * Boolean property to keep track of the state. */ - private final SimpleBooleanProperty switchStateBooleanProperty; + private final SimpleBooleanProperty switchedOn; /** - * Transition of the Circle from one side to the other. + * transition of the Circle from one side to the other. */ private final TranslateTransition switchAnimation; /** @@ -79,14 +72,14 @@ public class ToggleSwitch extends Control { // /** * Constructor. - * The toggle switch is built by initializing a layout which includes the sizing of the background (a rectangle) - * and the sizing of the button (a circle), as well as their colors. The transition of the button is initialized by - * adding an animation which also entails a color change. A listener and a mouse listener trigger the animation - * when the button (circle) is clicked on. */ - public ToggleSwitch(boolean anInitialStateOfBooleanProperty) { + public ToggleSwitch() { + /** + * code inspired by "JavaFX UI: iOS Style Toggle Switch", uploaded by Almas Baimagambetov on YouTube + * https://youtu.be/maX5ymmQixM?si=v2ULa57-pjCmoQlf, 05/17/2024, 10:33 + */ super(); - this.switchStateBooleanProperty = new SimpleBooleanProperty(anInitialStateOfBooleanProperty); + this.switchedOn = new SimpleBooleanProperty(false); this.switchBackground = new Rectangle(45, 18); this.switchBackground.setArcWidth(18); this.switchBackground.setArcHeight(18); @@ -105,25 +98,20 @@ public ToggleSwitch(boolean anInitialStateOfBooleanProperty) { this.switchTransition = new ParallelTransition(this.switchAnimation, this.fillAnimation); this.switchAnimation.setNode(this.switchButton); this.fillAnimation.setShape(this.switchBackground); - this.getChildren().addAll(this.switchBackground, this.switchButton); + getChildren().addAll(this.switchBackground, this.switchButton); //Listener - this.switchStateBooleanProperty.addListener((observable, oldValue, newValue) -> { + this.switchedOn.addListener((observable, oldValue, newValue) -> { boolean tmpIsOn = newValue.booleanValue(); - this.switchAnimation.setToX(tmpIsOn ? (44 - 18) : 0); //? + this.switchAnimation.setToX(tmpIsOn ? (44 - 18) : 0); this.fillAnimation.setFromValue(tmpIsOn ? Color.LIGHTGRAY : Color.web("#0099cc")); this.fillAnimation.setToValue(tmpIsOn ? Color.web("#0099cc") : Color.LIGHTGRAY); this.switchTransition.play(); }); //Mouse listener. - this.setOnMouseClicked(event -> this.switchStateBooleanProperty.set(!this.switchStateBooleanProperty.get())); + setOnMouseClicked(event -> this.switchedOn.set(!this.switchedOn.get())); } // // - // - //public setRectangleWidth(int aRectangleWidth) { - //this.switchedBackground.setWidth(aRectangleWidth); - //this.switchedButton.setCenterX(this.switchedButton.setConfigurableCenterX(50)) - //private final const RECTANGLE_HEIGHT = 45 /** * returns switchButton. * @@ -140,6 +128,14 @@ public Circle getSwitchButton() { public Rectangle getSwitchBackground() { return this.switchBackground; } + /** + * returns switchedOn to change the boolean state of the switch. + * + * @return SimpleBooleanProperty + */ + public SimpleBooleanProperty getSwitchedOn() { + return this.switchedOn; + } /** * returns switchAnimation which shows the visual transition of the Circle switchButton. * @@ -165,21 +161,28 @@ public ParallelTransition getSwitchTransition() { return this.switchTransition; } /** - * returns isSwitchedOn, the current boolean state of the Toggleswitch, - * if it is turned on it returns true, otherwise false. + * returns switchedOnProperty. + * + * @return BooleanProperty + */ + public BooleanProperty getSwitchedOnProperty() { + return this.switchedOn; + } + /** + * returns isSwitchedOn to change boolean state to true. * - * @return switch value + * @return switch value. */ - public boolean getSwitchStateBooleanProperty() { - return this.switchStateBooleanProperty.get(); + public boolean isSwitchedOn() { + return this.switchedOn.get(); } /** - * sets switchStateBooleanProperty to update new value. + * sets switchedOn to update new value. * - * @param switchStateBooleanProperty boolean + * @param switchedOn boolean */ - public void setSwitchStateBooleanProperty(boolean switchStateBooleanProperty) { - this.switchStateBooleanProperty.set(switchStateBooleanProperty); + public void setSwitchedOn(boolean switchedOn) { + this.switchedOn.set(switchedOn); } /** * returns valueProperty. @@ -187,7 +190,7 @@ public void setSwitchStateBooleanProperty(boolean switchStateBooleanProperty) { * @return BooleanProperty */ public BooleanProperty valueProperty() { - return this.switchStateBooleanProperty; + return this.switchedOn; } // } diff --git a/src/main/java/de/unijena/cheminf/mortar/gui/views/SettingsView.java b/src/main/java/de/unijena/cheminf/mortar/gui/views/SettingsView.java index bbf25b0c..0909eba6 100644 --- a/src/main/java/de/unijena/cheminf/mortar/gui/views/SettingsView.java +++ b/src/main/java/de/unijena/cheminf/mortar/gui/views/SettingsView.java @@ -207,13 +207,22 @@ private void addPropertyItems(GridPane aGridPane, List> aPropertiesL aRecentPropertiesMap.put(tmpPropName, tmpRecentValue); switch (tmpProperty) { case SimpleBooleanProperty tmpSimpleBooleanProperty -> { - boolean tmpInitialBooleanState = false; - ToggleSwitch tmpToggle = new ToggleSwitch(tmpInitialBooleanState); + //implement toggle switch here; write own class that implements a toggle switch + ToggleSwitch tmpToggle = new ToggleSwitch(); tmpToggle.setTooltip(tmpTooltip); tmpToggle.valueProperty().bindBidirectional(tmpSimpleBooleanProperty); //add to gridpane aGridPane.add(tmpToggle, 1, tmpRowIndex++); GridPane.setMargin(tmpToggle, new Insets(GuiDefinitions.GUI_INSETS_VALUE)); + /*ComboBox tmpBooleanComboBox = new ComboBox<>(); + tmpBooleanComboBox.setPrefWidth(GuiDefinitions.GUI_TEXT_FIELD_PREF_WIDTH_VALUE); + tmpBooleanComboBox.setMaxWidth(GuiDefinitions.GUI_SETTINGS_TEXT_FIELD_MAX_WIDTH_VALUE); + tmpBooleanComboBox.getItems().addAll(Boolean.FALSE, Boolean.TRUE); + tmpBooleanComboBox.valueProperty().bindBidirectional(tmpSimpleBooleanProperty); + tmpBooleanComboBox.setTooltip(tmpTooltip); + //add to gridpane + aGridPane.add(tmpBooleanComboBox, 1, tmpRowIndex++); + GridPane.setMargin(tmpBooleanComboBox, new Insets(GuiDefinitions.GUI_INSETS_VALUE));*/ } case SimpleIntegerProperty simpleIntegerProperty -> { TextField tmpIntegerTextField = new TextField();