<commit_before>package dk.cs.aau.huppaal.presentations;

import dk.cs.aau.huppaal.utility.colors.Color;
import dk.cs.aau.huppaal.utility.colors.EnabledColor;
import com.jfoenix.controls.JFXPopup;
import com.jfoenix.controls.JFXRippler;
import javafx.animation.ScaleTransition;
import javafx.beans.binding.When;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Screen;
import javafx.util.Duration;
import org.kordamp.ikonli.javafx.FontIcon;

import javax.swing.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import static dk.cs.aau.huppaal.utility.colors.EnabledColor.enabledColors;
import static javafx.scene.paint.Color.TRANSPARENT;
import static javafx.scene.paint.Color.WHITE;

public class DropDownMenu {

    public static double x = 0;
    public static double y = 0;
    private final int width;
    private final StackPane content;
    private final VBox list;
    private final JFXPopup popup;
    private final SimpleBooleanProperty isHoveringSubMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty isHoveringMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty showSubMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty canIShowSubMenu = new SimpleBooleanProperty(false);
    private StackPane subMenuContent;
    private final Node source;

    public DropDownMenu(final Node source, final int width, final boolean closeOnMouseExit) {
        this.width = width;
        this.source = source;

        popup = new JFXPopup();

        list = new VBox();
        list.setStyle("-fx-background-color: white; -fx-padding: 8 0 8 0;");
        list.setMaxHeight(1);
        StackPane.setAlignment(list, Pos.TOP_CENTER);

        content = new StackPane(list);
        content.setMinWidth(width);
        content.setMaxWidth(width);
        content.setMinHeight(1);
        content.setMaxHeight(1);

        if (closeOnMouseExit) {
            final Runnable checkIfWeShouldClose = () -> {
                if (!isHoveringMenu.get() && !isHoveringSubMenu.get()) {
                    final Timer timer = new Timer(20, arg0 -> {
                        if (!isHoveringMenu.get() && !isHoveringSubMenu.get()) {
                            this.close();
                        }
                    });
                    timer.setRepeats(false); // Only execute once
                    timer.start(); // Go go go!
                }
            };
            isHoveringMenu.addListener(observable -> checkIfWeShouldClose.run());
            isHoveringSubMenu.addListener(observable -> checkIfWeShouldClose.run());
        }


        list.setOnMouseExited(event -> isHoveringMenu.set(false));
        list.setOnMouseEntered(event -> isHoveringMenu.set(true));

        popup.setPopupContent(content);
    }

    public void close() {
        popup.hide();
    }

    public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) {
        //Needed to update the location of the popup before it is displayed
        this.flashDropdown();

        //Check if the dropdown will appear outside the screen and change the offset accordingly
        double offsetX = initOffsetX;
        double offsetY = initOffsetY;
        double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (event.getScreenX() + offsetX);
        double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (event.getScreenY() + offsetY);

        if(distEdgeX < width + 20){
            offsetX -= (width + 20) - distEdgeX;
        }

        if(distEdgeY < list.getHeight() + 20){
            offsetY -= (list.getHeight() + 20) - distEdgeY;
        }

        popup.show(this.source, vAlign, hAlign, offsetX, offsetY);
    }

    public void addListElement(final String s) {
        final Label label = new Label(s);

        label.setStyle("-fx-padding: 8 16 8 16;");
        label.getStyleClass().add("body2");
        label.setMinWidth(width);

        list.getChildren().add(label);

        label.setOnMouseEntered(event -> canIShowSubMenu.set(false));
    }

    public void addClickableListElement(final String s, final Consumer<MouseEvent> mouseEventConsumer) {<commit_msg>Moved the flashDropdown call further down to account for updated values (does not seem to change anything)<commit_after>package dk.cs.aau.huppaal.presentations;

import dk.cs.aau.huppaal.utility.colors.Color;
import dk.cs.aau.huppaal.utility.colors.EnabledColor;
import com.jfoenix.controls.JFXPopup;
import com.jfoenix.controls.JFXRippler;
import javafx.animation.ScaleTransition;
import javafx.beans.binding.When;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableBooleanValue;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.stage.Screen;
import javafx.util.Duration;
import org.kordamp.ikonli.javafx.FontIcon;

import javax.swing.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

import static dk.cs.aau.huppaal.utility.colors.EnabledColor.enabledColors;
import static javafx.scene.paint.Color.TRANSPARENT;
import static javafx.scene.paint.Color.WHITE;

public class DropDownMenu {

    public static double x = 0;
    public static double y = 0;
    private final int width;
    private final StackPane content;
    private final VBox list;
    private final JFXPopup popup;
    private final SimpleBooleanProperty isHoveringSubMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty isHoveringMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty showSubMenu = new SimpleBooleanProperty(false);
    private final SimpleBooleanProperty canIShowSubMenu = new SimpleBooleanProperty(false);
    private StackPane subMenuContent;
    private final Node source;

    public DropDownMenu(final Node source, final int width, final boolean closeOnMouseExit) {
        this.width = width;
        this.source = source;

        popup = new JFXPopup();

        list = new VBox();
        list.setStyle("-fx-background-color: white; -fx-padding: 8 0 8 0;");
        list.setMaxHeight(1);
        StackPane.setAlignment(list, Pos.TOP_CENTER);

        content = new StackPane(list);
        content.setMinWidth(width);
        content.setMaxWidth(width);
        content.setMinHeight(1);
        content.setMaxHeight(1);

        if (closeOnMouseExit) {
            final Runnable checkIfWeShouldClose = () -> {
                if (!isHoveringMenu.get() && !isHoveringSubMenu.get()) {
                    final Timer timer = new Timer(20, arg0 -> {
                        if (!isHoveringMenu.get() && !isHoveringSubMenu.get()) {
                            this.close();
                        }
                    });
                    timer.setRepeats(false); // Only execute once
                    timer.start(); // Go go go!
                }
            };
            isHoveringMenu.addListener(observable -> checkIfWeShouldClose.run());
            isHoveringSubMenu.addListener(observable -> checkIfWeShouldClose.run());
        }


        list.setOnMouseExited(event -> isHoveringMenu.set(false));
        list.setOnMouseEntered(event -> isHoveringMenu.set(true));

        popup.setPopupContent(content);
    }

    public void close() {
        popup.hide();
    }

    public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) {
        //Check if the dropdown will appear outside the screen and change the offset accordingly
        double offsetX = initOffsetX;
        double offsetY = initOffsetY;
        double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (event.getScreenX() + offsetX);
        double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (event.getScreenY() + offsetY);

        if(distEdgeX < width + 20){
            offsetX -= (width + 20) - distEdgeX;
        }

        if(distEdgeY < list.getHeight() + 20){
            offsetY -= (list.getHeight() + 20) - distEdgeY;
        }

        //Needed to update the location of the popup before it is displayed
        this.flashDropdown();

        popup.show(this.source, vAlign, hAlign, offsetX, offsetY);
    }

    public void addListElement(final String s) {
        final Label label = new Label(s);

        label.setStyle("-fx-padding: 8 16 8 16;");
        label.getStyleClass().add("body2");
        label.setMinWidth(width);

        list.getChildren().add(label);

        label.setOnMouseEntered(event -> canIShowSubMenu.set(false));
    }

    public void addClickableListElement(final String s, final Consumer<MouseEvent> mouseEventConsumer) {
{'fraction_non_alphanumeric': 0.1016661360500902, 'fraction_numerical': 0.0057306590257879654, 'mean_word_length': 2.9414470932664156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1889341', 'n_tokens_mistral': 2778, 'n_tokens_neox': 2682, 'n_words': 616}