<commit_before>package ui.components.pickers;

import backend.resource.TurboIssue;
import backend.resource.TurboLabel;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LabelPickerDialog extends Dialog<List<String>> {

    private static final int VBOX_SPACING = 105; // seems like some magic number
    private static final int ELEMENT_MAX_WIDTH = 400;

    private final LabelPickerUILogic uiLogic;
    private TextField textField;
    private FlowPane topPane;
    private VBox bottomBox;

    LabelPickerDialog(TurboIssue issue, List<TurboLabel> repoLabels, Stage stage) {
        // UI creation
        initialiseDialog(stage, issue);
        createButtons();
        VBox vBox = createVBox();
        Label titleLabel = createTitleLabel(issue);
        titleLabel.setTooltip(createTitleTooltip(issue));
        topPane = createTopPane();
        textField = createTextField();
        bottomBox = createBottomBox();

        setupKeyEvents();
        uiLogic = new LabelPickerUILogic(issue, repoLabels, this);

        vBox.getChildren().addAll(titleLabel, topPane, textField, bottomBox);
        getDialogPane().setContent(vBox);

        Platform.runLater(textField::requestFocus);
    }

    private void setupKeyEvents() {
        textField.textProperty().addListener((observable, oldValue, newValue) -> {
            uiLogic.processTextFieldChange(newValue.toLowerCase());
        });
        textField.setOnKeyPressed(e -> {
            if (!e.isAltDown() && !e.isMetaDown() && !e.isControlDown()) {
                if (e.getCode() == KeyCode.DOWN) {
                    e.consume();
                    uiLogic.moveHighlightOnLabel(true);
                } else if (e.getCode() == KeyCode.UP) {
                    e.consume();
                    uiLogic.moveHighlightOnLabel(false);
                } else if (e.getCode() == KeyCode.SPACE) {
                    e.consume();
                    uiLogic.toggleSelectedLabel(textField.getText());
                }
            }
        });
    }

    private void ______POPULATION______() {}

    protected void populatePanes(List<PickerLabel> topLabels, List<PickerLabel> bottomLabels, List<String> groups) {
        populateTopPane(topLabels);
        populateBottomBox(bottomLabels, groups);
    }

    private void populateTopPane(List<PickerLabel> topLabels) {
        topPane.getChildren().clear();
        if (topLabels.size() == 0) {
            Label label = new Label("No currently selected labels. ");
            label.setPadding(new Insets(2, 5, 2, 5));
            topPane.getChildren().add(label);
        } else {
            topLabels.forEach(label -> topPane.getChildren().add(label.getNode()));
        }
    }

    private void populateBottomBox(List<PickerLabel> bottomLabels, List<String> groups) {
        bottomBox.getChildren().clear();
        if (bottomLabels.size() == 0) {
            Label label = new Label("No labels in repository. ");
            label.setPadding(new Insets(2, 5, 2, 5));
            bottomBox.getChildren().add(label);
        } else {
            FlowPane noGroup = new FlowPane();
            noGroup.setHgap(5);
            noGroup.setVgap(5);
            bottomLabels
                    .stream()
                    .filter(label -> !label.getGroup().isPresent())
                    .forEach(label -> noGroup.getChildren().add(label.getNode()));
            if (noGroup.getChildren().size() > 0) bottomBox.getChildren().add(noGroup);

            groups.stream().forEach(group -> {
                Label groupName = new Label(group);
                groupName.setPadding(new Insets(5));
                groupName.setMaxWidth(ELEMENT_MAX_WIDTH - 10);
                groupName.setStyle("-fx-font-size: 110%");
                FlowPane groupPane = new FlowPane();
                groupPane.setHgap(5);
                groupPane.setVgap(5);
                bottomLabels
                        .stream()
                        .filter(label -> label.getGroup().isPresent())
                        .filter(label -> label.getGroup().get().equalsIgnoreCase(group))
                        .forEach(label -> groupPane.getChildren().add(label.getNode()));
                bottomBox.getChildren().addAll(groupName, groupPane);
            });
        }
    }

    private void ______UI_CREATION______() {}
<commit_msg>tweaked padding for label groups in LabelPickerDialog<commit_after>package ui.components.pickers;

import backend.resource.TurboIssue;
import backend.resource.TurboLabel;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class LabelPickerDialog extends Dialog<List<String>> {

    private static final int VBOX_SPACING = 105; // seems like some magic number
    private static final int ELEMENT_MAX_WIDTH = 400;

    private final LabelPickerUILogic uiLogic;
    private TextField textField;
    private FlowPane topPane;
    private VBox bottomBox;

    LabelPickerDialog(TurboIssue issue, List<TurboLabel> repoLabels, Stage stage) {
        // UI creation
        initialiseDialog(stage, issue);
        createButtons();
        VBox vBox = createVBox();
        Label titleLabel = createTitleLabel(issue);
        titleLabel.setTooltip(createTitleTooltip(issue));
        topPane = createTopPane();
        textField = createTextField();
        bottomBox = createBottomBox();

        setupKeyEvents();
        uiLogic = new LabelPickerUILogic(issue, repoLabels, this);

        vBox.getChildren().addAll(titleLabel, topPane, textField, bottomBox);
        getDialogPane().setContent(vBox);

        Platform.runLater(textField::requestFocus);
    }

    private void setupKeyEvents() {
        textField.textProperty().addListener((observable, oldValue, newValue) -> {
            uiLogic.processTextFieldChange(newValue.toLowerCase());
        });
        textField.setOnKeyPressed(e -> {
            if (!e.isAltDown() && !e.isMetaDown() && !e.isControlDown()) {
                if (e.getCode() == KeyCode.DOWN) {
                    e.consume();
                    uiLogic.moveHighlightOnLabel(true);
                } else if (e.getCode() == KeyCode.UP) {
                    e.consume();
                    uiLogic.moveHighlightOnLabel(false);
                } else if (e.getCode() == KeyCode.SPACE) {
                    e.consume();
                    uiLogic.toggleSelectedLabel(textField.getText());
                }
            }
        });
    }

    private void ______POPULATION______() {}

    protected void populatePanes(List<PickerLabel> topLabels, List<PickerLabel> bottomLabels, List<String> groups) {
        populateTopPane(topLabels);
        populateBottomBox(bottomLabels, groups);
    }

    private void populateTopPane(List<PickerLabel> topLabels) {
        topPane.getChildren().clear();
        if (topLabels.size() == 0) {
            Label label = new Label("No currently selected labels. ");
            label.setPadding(new Insets(2, 5, 2, 5));
            topPane.getChildren().add(label);
        } else {
            topLabels.forEach(label -> topPane.getChildren().add(label.getNode()));
        }
    }

    private void populateBottomBox(List<PickerLabel> bottomLabels, List<String> groups) {
        bottomBox.getChildren().clear();
        if (bottomLabels.size() == 0) {
            Label label = new Label("No labels in repository. ");
            label.setPadding(new Insets(2, 5, 2, 5));
            bottomBox.getChildren().add(label);
        } else {
            FlowPane noGroup = new FlowPane();
            noGroup.setHgap(5);
            noGroup.setVgap(5);
            noGroup.setPadding(new Insets(0, 0, 10, 0));
            bottomLabels
                    .stream()
                    .filter(label -> !label.getGroup().isPresent())
                    .forEach(label -> noGroup.getChildren().add(label.getNode()));
            if (noGroup.getChildren().size() > 0) bottomBox.getChildren().add(noGroup);

            groups.stream().forEach(group -> {
                Label groupName = new Label(group);
                groupName.setPadding(new Insets(0, 0, 5, 5));
                groupName.setMaxWidth(ELEMENT_MAX_WIDTH - 10);
                groupName.setStyle("-fx-font-size: 110%");
                FlowPane groupPane = new FlowPane();
                groupPane.setHgap(5);
                groupPane.setVgap(5);
                groupPane.setPadding(new Insets(0, 0, 10, 0));
                bottomLabels
                        .stream()
                        .filter(label -> label.getGroup().isPresent())
                        .filter(label -> label.getGroup().get().equalsIgnoreCase(group))
                        .forEach(label -> groupPane.getChildren().add(label.getNode()));
                bottomBox.getChildren().addAll(groupName, groupPane);
            });
        }
    }

    private void ______UI_CREATION______() {}

{'fraction_non_alphanumeric': 0.11823859426272891, 'fraction_numerical': 0.0070921985815602835, 'mean_word_length': 2.2356164383561645, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 41, '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': '254534', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2542, 'n_words': 491}