<commit_before>package ui.components.pickers;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.apache.logging.log4j.Logger;
import ui.UI;
import util.HTLog;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;

/**
 * @author <NAME>
 */
public class BoardPickerDialog extends Dialog<String> {

    private static final Logger logger = HTLog.get(BoardPickerDialog.class);
    private static final String DIALOG_TITLE = "Switch to board...";

    private List<String> boards;
    private BoardPickerState state;
    private Optional<String> suggestion = Optional.empty();

    @FXML
    private VBox mainLayout;

    @FXML
    private Label title;

    @FXML
    private TextField queryField;

    @FXML
    private VBox boardList;

    @FXML
    private VBox boardNames;

    BoardPickerDialog(List<String> boards, Stage stage) {
        this.boards = boards;

        initUI(stage);
        Platform.runLater(queryField::requestFocus);
    }

    @FXML
    public void initialize() {
        queryField.textProperty().addListener(
                    (observable, oldText, newText) -> handleUserInput(queryField.getText()));
    }

    private void initUI(Stage stage) {
        initializeDialog(stage);
        setMainLayout();
        createButtons();

        state = new BoardPickerState(new HashSet<>(boards), "");
        populateBoards(state);
    }

    private void initializeDialog(Stage stage) {
        initOwner(stage);
        initModality(Modality.APPLICATION_MODAL);
        setTitle(DIALOG_TITLE);
    }

    private void setMainLayout() {
        FXMLLoader loader = new FXMLLoader(UI.class.getResource("fxml/BoardPickerView.fxml"));
        loader.setController(this);
        try {
            mainLayout = loader.load();
            getDialogPane().setContent(mainLayout);
        } catch (IOException e) {
            logger.error("Failed to load FXML. " + e.getMessage());
            close();
        }
    }

    private void createButtons() {
        ButtonType confirmButtonType = new ButtonType("Confirm", ButtonBar.ButtonData.OK_DONE);
        getDialogPane().getButtonTypes().addAll(confirmButtonType, ButtonType.CANCEL);

        setResultConverter(dialogButton -> {
            if (dialogButton == confirmButtonType) {
                // Ensures the last keyword in the query is toggled after confirmation
                return suggestion.orElse(null);
            }
            return null;
        });
    }

    private void populateBoards(BoardPickerState state) {
        boardNames.getChildren().clear();
        state.getMatchedBoards().stream()
                    .map(boardName -> {
                        PickerBoard pb = new PickerBoard(boardName);
                        pb.highlighted(suggestion.isPresent() && suggestion.get().equals(boardName));
                        return pb;
                    })
                    .forEach(boardName -> boardNames.getChildren().add(getPickerBoardNode(boardName)));

        getDialogPane().getScene().getWindow().sizeToScene();
    }

    private final Node getPickerBoardNode(PickerBoard board) {
        Node node = board.getNode();
        node.setOnMouseClicked(e -> handleBoardClick(board));
        return node;
    }

    private final void handleUserInput(String query) {
        state = new BoardPickerState(new HashSet<>(boards), query.toLowerCase());
        suggestion = state.getSuggestion();
        populateBoards(state);
    }

    private void handleBoardClick(PickerBoard board) {
        // TODO
    }
}
<commit_msg>Do not hide unmatched board names<commit_after>package ui.components.pickers;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import org.apache.logging.log4j.Logger;
import ui.UI;
import util.HTLog;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;

/**
 * @author <NAME>
 */
public class BoardPickerDialog extends Dialog<String> {

    private static final Logger logger = HTLog.get(BoardPickerDialog.class);
    private static final String DIALOG_TITLE = "Switch to board...";

    private List<String> boards;
    private BoardPickerState state;
    private Optional<String> suggestion = Optional.empty();

    @FXML
    private VBox mainLayout;

    @FXML
    private Label title;

    @FXML
    private TextField queryField;

    @FXML
    private VBox boardList;

    @FXML
    private VBox boardNames;

    BoardPickerDialog(List<String> boards, Stage stage) {
        this.boards = boards;

        initUI(stage);
        Platform.runLater(queryField::requestFocus);
    }

    @FXML
    public void initialize() {
        queryField.textProperty().addListener(
                    (observable, oldText, newText) -> handleUserInput(queryField.getText()));
    }

    private void initUI(Stage stage) {
        initializeDialog(stage);
        setMainLayout();
        createButtons();

        state = new BoardPickerState(new HashSet<>(boards), "");
        populateBoards(state);
    }

    private void initializeDialog(Stage stage) {
        initOwner(stage);
        initModality(Modality.APPLICATION_MODAL);
        setTitle(DIALOG_TITLE);
    }

    private void setMainLayout() {
        FXMLLoader loader = new FXMLLoader(UI.class.getResource("fxml/BoardPickerView.fxml"));
        loader.setController(this);
        try {
            mainLayout = loader.load();
            getDialogPane().setContent(mainLayout);
        } catch (IOException e) {
            logger.error("Failed to load FXML. " + e.getMessage());
            close();
        }
    }

    private void createButtons() {
        ButtonType confirmButtonType = new ButtonType("Confirm", ButtonBar.ButtonData.OK_DONE);
        getDialogPane().getButtonTypes().addAll(confirmButtonType, ButtonType.CANCEL);

        setResultConverter(dialogButton -> {
            if (dialogButton == confirmButtonType) {
                // Ensures the last keyword in the query is toggled after confirmation
                return suggestion.orElse(null);
            }
            return null;
        });
    }

    private void populateBoards(BoardPickerState state) {
        boardNames.getChildren().clear();
        boards.stream()
                    .map(boardName -> {
                        PickerBoard pb = new PickerBoard(boardName);
                        pb.faded(!state.getMatchedBoards().contains(boardName));
                        pb.highlighted(suggestion.isPresent() && suggestion.get().equals(boardName));
                        return pb;
                    })
                    .forEach(boardName -> boardNames.getChildren().add(getPickerBoardNode(boardName)));

        getDialogPane().getScene().getWindow().sizeToScene();
    }

    private final Node getPickerBoardNode(PickerBoard board) {
        Node node = board.getNode();
        node.setOnMouseClicked(e -> handleBoardClick(board));
        return node;
    }

    private final void handleUserInput(String query) {
        state = new BoardPickerState(new HashSet<>(boards), query.toLowerCase());
        suggestion = state.getSuggestion();
        populateBoards(state);
    }

    private void handleBoardClick(PickerBoard board) {
        // TODO
    }
}

{'fraction_non_alphanumeric': 0.10495478283021271, 'fraction_numerical': 0.0002547446185199338, 'mean_word_length': 2.62010142923006, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '4667589', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2128, 'n_words': 452}