<commit_before>package de.vogel612.helper.ui.jfx;


import static de.vogel612.helper.data.util.DataUtilities.FILENAME_PATTERN;

import de.vogel612.helper.ui.common.ResxChooserCommon;

import java.io.File;
import java.net.URL;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import java.util.regex.Matcher;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.Label;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;

public class JFXResxChooserController extends ResxChooserCommon implements Initializable {

    @FXML
    private Label leftTranslation;

    @FXML
    private Label rightTranslation;

    @FXML
    private Label fileset;

    @FXML
    private Button leftChoose;

    @FXML
    private Button rightChoose;

    @FXML
    private Button filesetChoose;

    @FXML
    private Button submit;

    private final FileChooser fileChooser = new FileChooser();

    public JFXResxChooserController() {
        fileChooser.setTitle("Choose RESX file");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("Resx Files", "resx"));
    }

    @Override
    protected void onFilesetChangeInternal() {
        final Matcher filesetMatcher = FILENAME_PATTERN.matcher(filesetBacking.getFileName().toString());
        if (filesetMatcher.matches()) { // should always be true
            // group is not optional, so we're good
            final String filesetName = filesetMatcher.group(1);
            Platform.runLater(() -> fileset.setText(filesetName));
            // drop locales we cannot use anymore...
            if (!localeOptionCache.contains(left)) {
                left = null;
                Platform.runLater(() -> leftTranslation.setText("(none)"));
            }
            if (!localeOptionCache.contains(right)) {
                right = null;
                Platform.runLater(() -> rightTranslation.setText("(none)"));
            }
        }
    }

    private void showLocaleDialog(Consumer<String> callback) {
        final String[] localeChoices = localeOptionCache.toArray(new String[localeOptionCache.size()]);
        ChoiceDialog<String> dialog = new ChoiceDialog<>(localeChoices[0], localeChoices);
        dialog.setHeaderText("Choose a Language");
        dialog.setContentText("");
        dialog.show();
        dialog.setOnCloseRequest(evt -> {
            dialog.close();
            callback.accept(dialog.getSelectedItem());
        });
    }

    @Override
    public void hide() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void show() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        Objects.requireNonNull(leftTranslation, "leftTranslation was not correctly FXML-injected");
        Objects.requireNonNull(rightTranslation, "rightTranslation was not correctly FXML-injected");
        Objects.requireNonNull(fileset, "fileset was not correctly FXML-injected");
        Objects.requireNonNull(leftChoose, "leftChoose was not correctly FXML-injected");
        Objects.requireNonNull(rightChoose, "rightChoose was not correctly FXML-injected");
        Objects.requireNonNull(filesetChoose, "filesetChoose was not correctly FXML-injected");
        Objects.requireNonNull(submit, "submit was not correctly FXML-injected");

        submit.setOnAction(evt -> completeChoice());<commit_msg>Disabled buttons to choose language instead of crapping out when there's no chosen fileset<commit_after>package de.vogel612.helper.ui.jfx;


import static de.vogel612.helper.data.util.DataUtilities.FILENAME_PATTERN;

import de.vogel612.helper.ui.common.ResxChooserCommon;

import java.io.File;
import java.net.URL;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.function.Consumer;
import java.util.regex.Matcher;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.Label;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;

public class JFXResxChooserController extends ResxChooserCommon implements Initializable {

    @FXML
    private Label leftTranslation;

    @FXML
    private Label rightTranslation;

    @FXML
    private Label fileset;

    @FXML
    private Button leftChoose;

    @FXML
    private Button rightChoose;

    @FXML
    private Button filesetChoose;

    @FXML
    private Button submit;

    private final FileChooser fileChooser = new FileChooser();

    public JFXResxChooserController() {
        fileChooser.setTitle("Choose RESX file");
        fileChooser.getExtensionFilters().add(new ExtensionFilter("Resx Files", "*.resx"));
    }

    @Override
    protected void onFilesetChangeInternal() {
        final Matcher filesetMatcher = FILENAME_PATTERN.matcher(filesetBacking.getFileName().toString());
        if (filesetMatcher.matches()) { // should always be true
            // group is not optional, so we're good
            final String filesetName = filesetMatcher.group(1);
            Platform.runLater(() -> fileset.setText(filesetName));
            // drop locales we cannot use anymore...
            if (!localeOptionCache.contains(left)) {
                left = null;
                Platform.runLater(() -> leftTranslation.setText("(none)"));
            }
            if (!localeOptionCache.contains(right)) {
                right = null;
                Platform.runLater(() -> rightTranslation.setText("(none)"));
            }
            leftChoose.setDisable(false);
            rightChoose.setDisable(false);
        }
    }

    private void showLocaleDialog(Consumer<String> callback) {
        final String[] localeChoices = localeOptionCache.toArray(new String[localeOptionCache.size()]);
        ChoiceDialog<String> dialog = new ChoiceDialog<>(localeChoices[0], localeChoices);
        dialog.setHeaderText("Choose a Language");
        dialog.setContentText("");
        dialog.show();
        dialog.setOnCloseRequest(evt -> {
            dialog.close();
            callback.accept(dialog.getSelectedItem());
        });
    }

    @Override
    public void hide() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void show() {
        throw new UnsupportedOperationException();
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        Objects.requireNonNull(leftTranslation, "leftTranslation was not correctly FXML-injected");
        Objects.requireNonNull(rightTranslation, "rightTranslation was not correctly FXML-injected");
        Objects.requireNonNull(fileset, "fileset was not correctly FXML-injected");
        Objects.requireNonNull(leftChoose, "leftChoose was not correctly FXML-injected");
        Objects.requireNonNull(rightChoose, "rightChoose was not correctly FXML-injected");
        Objects.requireNonNull(filesetChoose, "filesetChoose was not correctly FXML-injected");
        Objects.requireNonNull(submit, "submit was not correctly FXML-injected");

        leftChoose.setDisable(true);
        rightChoose.setDisable(true);
        submit.setOnAction(evt -> completeChoice());
{'fraction_non_alphanumeric': 0.09913043478260869, 'fraction_numerical': 0.00294314381270903, 'mean_word_length': 3.2165820642978002, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1374039', 'n_tokens_mistral': 2091, 'n_tokens_neox': 1971, 'n_words': 452}