<commit_before>package ch.woggle.rohonxi.view;

import ch.woggle.rohonxi.MainApp;
import ch.woggle.rohonxi.alphabet.Alphabet;
import ch.woggle.rohonxi.alphabet.AsciiAlphabet;
import ch.woggle.rohonxi.alphabet.BinaryAlphabet;
import ch.woggle.rohonxi.alphabet.CustomDistinctAlphabet;
import ch.woggle.rohonxi.alphabet.DecimalAlphabet;
import ch.woggle.rohonxi.alphabet.HexAlphabet;
import ch.woggle.rohonxi.alphabet.LatinAlphabet;
import ch.woggle.rohonxi.alphabet.LatinLcAlphabet;
import ch.woggle.rohonxi.alphabet.LatinUcAlphabet;
import ch.woggle.rohonxi.export.SimpleTextExport;
import ch.woggle.rohonxi.generator.Generator;
import ch.woggle.rohonxi.generator.SimpleRandomMatrixGenerator;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import javafx.scene.control.TextArea;
import javafx.stage.FileChooser;
import javafx.util.StringConverter;

public class MainViewController {
  private MainApp mainApp;

  @FXML
  private ChoiceBox<Alphabet> alphabets;

  @FXML
  private TextArea availableCharacters;

  @FXML
  private Spinner<Integer> rows;

  @FXML
  private Spinner<Integer> columns;

  @FXML
  private TextArea output;

  @FXML
  private Button generateButton;

  @FXML
  private Button exportButton;

  @FXML
  private void initialize() {
    initializeAlphabetBox();
    initializeSpinners();
  }

  private void initializeSpinners() {
    setIntegerSpinnerFactory(rows, 5, 255, 20);
    setIntegerSpinnerFactory(columns, 5, 255, 20);

  }

  private static void setIntegerSpinnerFactory(Spinner<Integer> spinner, int min, int max,
      int value) {
    IntegerSpinnerValueFactory valueFactory = new IntegerSpinnerValueFactory(min, max);
    valueFactory.setValue(value);
    spinner.setValueFactory(valueFactory);
  }

  /**
   * 
   */
  private void initializeAlphabetBox() {
    ObservableList<Alphabet> alphabetItems = FXCollections.observableArrayList();
    alphabetItems.add(new CustomDistinctAlphabet());
    alphabetItems.add(new BinaryAlphabet());
    alphabetItems.add(new DecimalAlphabet());
    alphabetItems.add(new HexAlphabet());
    alphabetItems.add(new AsciiAlphabet());
    alphabetItems.add(new LatinAlphabet());
    alphabetItems.add(new LatinLcAlphabet());
    alphabetItems.add(new LatinUcAlphabet());
    alphabets.setItems(alphabetItems);

    alphabets.setConverter(new StringConverter<Alphabet>() {
      @Override
      public String toString(Alphabet alphabet) {
        if (alphabet == null) {
          return null;
        }
        return alphabet.getName();
      }

      @Override
      public Alphabet fromString(String string) {
        return null;
      }
    });
  }

  private Alphabet getSelectedAlphabet() {
    Alphabet selected = alphabets.getSelectionModel().getSelectedItem();
    if (selected != null && selected.getClass() == CustomDistinctAlphabet.class) {
      ((CustomDistinctAlphabet) selected).setSymbols(availableCharacters.getText());
    }
    return selected;
  }

  @FXML
  private void handleGenerate() {
    int width = columns.getValue();
    int height = rows.getValue();
    Generator gen = new SimpleRandomMatrixGenerator(width, height);
    gen.setAlphabet(getSelectedAlphabet());
    output.setText(gen.generate());
  }

  @FXML
  private void handleExport() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export code");<commit_msg>Edit Alphabet selector to display selected alphabet symbolString. Only if custom alphabet is selected, the symbols can be edited.<commit_after>package ch.woggle.rohonxi.view;

import ch.woggle.rohonxi.MainApp;
import ch.woggle.rohonxi.alphabet.Alphabet;
import ch.woggle.rohonxi.alphabet.AsciiAlphabet;
import ch.woggle.rohonxi.alphabet.BinaryAlphabet;
import ch.woggle.rohonxi.alphabet.CustomDistinctAlphabet;
import ch.woggle.rohonxi.alphabet.DecimalAlphabet;
import ch.woggle.rohonxi.alphabet.HexAlphabet;
import ch.woggle.rohonxi.alphabet.LatinAlphabet;
import ch.woggle.rohonxi.alphabet.LatinLcAlphabet;
import ch.woggle.rohonxi.alphabet.LatinUcAlphabet;
import ch.woggle.rohonxi.export.SimpleTextExport;
import ch.woggle.rohonxi.generator.Generator;
import ch.woggle.rohonxi.generator.SimpleRandomMatrixGenerator;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory.IntegerSpinnerValueFactory;
import javafx.scene.control.TextArea;
import javafx.stage.FileChooser;
import javafx.util.StringConverter;

public class MainViewController {
  private MainApp mainApp;

  @FXML
  private ChoiceBox<Alphabet> alphabets;

  @FXML
  private TextArea availableCharacters;

  @FXML
  private Spinner<Integer> rows;

  @FXML
  private Spinner<Integer> columns;

  @FXML
  private TextArea output;

  @FXML
  private Button generateButton;

  @FXML
  private Button exportButton;

  @FXML
  private void initialize() {
    initializeAlphabetBox();
    initializeSpinners();
    availableCharacters.setWrapText(true);
  }

  private void initializeSpinners() {
    setIntegerSpinnerFactory(rows, 5, 255, 20);
    setIntegerSpinnerFactory(columns, 5, 255, 20);

  }

  private static void setIntegerSpinnerFactory(Spinner<Integer> spinner, int min, int max,
      int value) {
    IntegerSpinnerValueFactory valueFactory = new IntegerSpinnerValueFactory(min, max);
    valueFactory.setValue(value);
    spinner.setValueFactory(valueFactory);
  }

  /**
   * 
   */
  private void initializeAlphabetBox() {
    ObservableList<Alphabet> alphabetItems = FXCollections.observableArrayList();
    alphabetItems.add(new CustomDistinctAlphabet());
    alphabetItems.add(new BinaryAlphabet());
    alphabetItems.add(new DecimalAlphabet());
    alphabetItems.add(new HexAlphabet());
    alphabetItems.add(new AsciiAlphabet());
    alphabetItems.add(new LatinAlphabet());
    alphabetItems.add(new LatinLcAlphabet());
    alphabetItems.add(new LatinUcAlphabet());
    alphabets.setItems(alphabetItems);

    alphabets.setConverter(new StringConverter<Alphabet>() {
      @Override
      public String toString(Alphabet alphabet) {
        if (alphabet == null) {
          return null;
        }
        return alphabet.getName();
      }

      @Override
      public Alphabet fromString(String string) {
        return null;
      }
    });

    alphabets.getSelectionModel().selectedItemProperty()
        .addListener((observable, oldValue, newValue) -> setSelectedAlphabet(newValue));
    alphabets.getSelectionModel().select(0);

  }

  private void setSelectedAlphabet(Alphabet alphabet) {
    if (alphabet.getClass() == CustomDistinctAlphabet.class) {
      availableCharacters.setEditable(true);
    } else {
      availableCharacters.setEditable(false);
      availableCharacters.setText(alphabet.getSymbolString());
    }
  }

  private Alphabet getSelectedAlphabet() {
    Alphabet selected = alphabets.getSelectionModel().getSelectedItem();
    if (selected != null && selected.getClass() == CustomDistinctAlphabet.class) {
      ((CustomDistinctAlphabet) selected).setSymbols(availableCharacters.getText());
    }
    return selected;
  }

  @FXML
  private void handleGenerate() {
    int width = columns.getValue();
    int height = rows.getValue();
    Generator gen = new SimpleRandomMatrixGenerator(width, height);
    gen.setAlphabet(getSelectedAlphabet());
    output.setText(gen.generate());
  }

  @FXML
  private void handleExport() {
    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export code");
{'fraction_non_alphanumeric': 0.10087998979721974, 'fraction_numerical': 0.003188368830506313, 'mean_word_length': 4.549893842887474, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6612803', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2342, 'n_words': 441}