package SW9.model_canvas.edges;

import SW9.model_canvas.Parent;
import SW9.utility.helpers.DragHelper;
import SW9.utility.helpers.LocationAware;
import SW9.utility.helpers.MouseTrackable;
import SW9.utility.mouse.MouseTracker;
import com.jfoenix.controls.JFXTextField;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.value.ObservableDoubleValue;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Rectangle;

public class Properties extends Parent implements LocationAware, MouseTrackable {

    private final DoubleProperty xProperty = new SimpleDoubleProperty(0d);
    private final DoubleProperty yProperty = new SimpleDoubleProperty(0d);

    private static final double ICON_WIDTH = 20d;
    private static final double VALUE_WIDTH = 120d;

    private final MouseTracker localMouseTracker = new MouseTracker(this);

    public Properties() {
        this.getStyleClass().add("edge-properties");

        final VBox propertiesBox = new VBox();
        propertiesBox.getChildren().addAll(
                generatePropertyBox(":", "id : id_t"),
                generatePropertyBox("<", "guard < value"),
                generatePropertyBox("!?", "channel!"),
                generatePropertyBox("=", "var = 42")

        );
        propertiesBox.layoutXProperty().bind(xProperty());
        propertiesBox.layoutYProperty().bind(yProperty());

        getChildren().add(propertiesBox);
    }

    private Parent generateValueBox(final String value, final DoubleProperty sharedHeightProperty) {
        // The textField for the value of the given property
        final JFXTextField textField = new JFXTextField(value);
        textField.getStyleClass().addAll("body1", "value-text-field");
        textField.setPrefWidth(VALUE_WIDTH);

        // Container for the stack pane containing the value
        final Rectangle box = new Rectangle(VALUE_WIDTH, 0);
        box.getStyleClass().add("value-background");
        box.heightProperty().bind(textField.heightProperty());

        // Bind the shared height to the height of the box
        sharedHeightProperty.bind(box.heightProperty());

        // Add a parent that should contain both the container and the value textField
        final Parent parent = new Parent();
        parent.getStyleClass().add("value-container");
        parent.addChildren(box, textField);

        return parent;
    }

    private StackPane generateIconBox(final String iconString, final DoubleProperty height) {
        // Container for the background of the stack pane containing an icon
        final Rectangle box = new Rectangle(ICON_WIDTH, 0);
        box.getStyleClass().add("icon-background");
        box.heightProperty().bind(height);

        // The label representing an icon
        final Label label = new Label(iconString);
        label.getStyleClass().addAll("subhead", "icon-label");

        // Add a stack-pane with both the container and the icon label (will center label)
        final StackPane stackPane = new StackPane();
        stackPane.getStyleClass().add("icon-container");
        stackPane.getChildren().addAll(box, label);

        // Align the box in the top left corner
        StackPane.setAlignment(box, Pos.TOP_LEFT);

        return stackPane;
    }

    private HBox generatePropertyBox(final String iconString, final String value) {
        final HBox propertyBox = new HBox();

        // A shared property to ensure that the icon box and the value box is consistent in height
        final DoubleProperty sharedHeightProperty = new SimpleDoubleProperty();

        // Generate the value and the icon for the property box
        final Parent valueBox = generateValueBox(value, sharedHeightProperty);
        final StackPane iconBox = generateIconBox(iconString, sharedHeightProperty);

        // Add the boxes to this property box
        propertyBox.getChildren().addAll(iconBox, valueBox);

        return propertyBox;
    }


    @Override
    public MouseTracker getMouseTracker() {
        return localMouseTracker;
    }

    public DoubleProperty xProperty() {
        return xProperty;
    }

    public DoubleProperty yProperty() {
        return yProperty;
    }
}

@@ -26,16 +26,53 @@
 edges;%0A%0A
+import SW9.model_canvas.ModelCanvas;%0A
 import S
@@ -95,16 +95,16 @@
 Parent;%0A
-
 import S
@@ -473,16 +473,42 @@
 ry.Pos;%0A
+import javafx.scene.Node;%0A
 import j
@@ -676,16 +676,45 @@
 angle;%0A%0A
+import java.util.ArrayList;%0A%0A
 public c
@@ -1114,24 +1114,95 @@
 ker(this);%0A%0A
+    private final ArrayList%3CNode%3E hiddenElements = new ArrayList%3C%3E();%0A%0A
     public P
@@ -1754,16 +1754,682 @@
 iesBox);
+%0A%0A        // Hide the elements in hiddenElements (input fields) when we are not hovering the properties%0A        localMouseTracker.registerOnMouseEnteredEventHandler(event -%3E %7B%0A            // Do not snow if we have a location on the mouse%0A            if(ModelCanvas.mouseHasLocation()) %7B%0A                hiddenElements.forEach(node -%3E node.setVisible(false));%0A            %7D else %7B%0A                hiddenElements.forEach(node -%3E node.setVisible(true));%0A            %7D%0A        %7D);%0A        localMouseTracker.registerOnMouseExitedEventHandler(event -%3E hiddenElements.forEach(node -%3E node.setVisible(false)));%0A        hiddenElements.forEach(node -%3E node.setVisible(false));
 %0A    %7D%0A%0A
@@ -3305,32 +3305,32 @@
 ue-container%22);%0A
-
         parent.a
@@ -3354,24 +3354,61 @@
 extField);%0A%0A
+        hiddenElements.add(parent);%0A%0A
         retu

Make properties table collapsable