<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.atdl4j.ui.javafx.app.impl;

import java.util.ArrayList;
import java.util.List;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.apache.log4j.Logger;
import org.atdl4j.config.Atdl4jConfig;
import org.atdl4j.config.Atdl4jConfiguration;
import org.atdl4j.config.Atdl4jOptions;
import org.atdl4j.fixatdl.core.StrategyT;
import org.atdl4j.ui.Atdl4jWidget;
import org.atdl4j.ui.app.Atdl4jCompositePanel;
import org.atdl4j.ui.app.impl.AbstractAtdl4jTesterApp;
import org.atdl4j.ui.javafx.JavaFXWidget;
import org.atdl4j.ui.javafx.config.JavaFXAtdl4jConfiguration;
import org.atdl4j.ui.javafx.impl.JavaFXStrategiesUI;
import org.atdl4j.ui.javafx.impl.JavaFXStrategyUI;

/**
 *
 * @author daniel.makgonta
 */
public class JavaFXAtdl4jTesterApp extends AbstractAtdl4jTesterApp {

    public static final Logger logger = Logger.getLogger(JavaFXAtdl4jTesterApp.class);
    private ComboBox<StrategyT> strategyList;
    private final ArrayList<Node> strategyWidgets = new ArrayList<Node>();

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        Atdl4jConfiguration config = new JavaFXAtdl4jConfiguration();
        JavaFXAtdl4jTesterApp tempJavaFXAtdl4jTesterApp = new JavaFXAtdl4jTesterApp();
        try {
            tempJavaFXAtdl4jTesterApp.mainLine(config, "samples/sample1.xml");
        } catch (Exception e) {
            if (Atdl4jConfig.getConfig().isCatchAllMainlineExceptions()) {
                JavaFXAtdl4jTesterApp.logger.warn("Fatal Exception in mainLine", e);
            } else {
                throw e;
            }
        }
    }

    public ArrayList<? extends Node> getStrategyWidgets() {
        return strategyWidgets;
    }

    public Pane mainLine(Atdl4jConfiguration config, String XMLFilePath) throws Exception {
        AnchorPane pane = new AnchorPane();
        AnchorPane root = new AnchorPane();

        strategyList = new ComboBox<StrategyT>();
        strategyList.setMinWidth(120);

        HBox containerBox = new HBox();
        containerBox.setPadding(new Insets(5, 0, 5, 0));
        final VBox strategyBox = new VBox();
        root.getChildren().add(containerBox);

        // -- Delegate setup to AbstractAtdl4jTesterApp, construct a new
        // JavaFX-specific Atdl4jOptions --
        Atdl4jOptions atdl4jOptions = new Atdl4jOptions();
        atdl4jOptions.setShowEnabledCheckboxOnOptionalClockControl(true);
        init(config, atdl4jOptions, pane);

        // -- Build the JavaFX panel from Atdl4jTesterPanel (** core GUI component **) --
        getAtdl4jTesterPanel().buildAtdl4jTesterPanel(pane, getAtdl4jOptions());
        Atdl4jCompositePanel panel = getAtdl4jTesterPanel().getAtdl4jCompositePanel();
        panel.parseFixatdlFile(XMLFilePath);
        panel.loadScreenWithFilteredStrategies();
        final JavaFXStrategiesUI uiList = (JavaFXStrategiesUI) panel.getStrategiesUI();
        List<StrategyT> strategies = panel.getStrategiesFilteredStrategyList();

        strategyList.getItems().addAll(strategies);
        strategyList.setCellFactory(new Callback<ListView<StrategyT>, ListCell<StrategyT>>() {
            @Override
            public ListCell<StrategyT> call(ListView<StrategyT> param) {
                return new StrategyListCell();
            }
        });

        strategyList.setConverter(new StringConverter<StrategyT>() {

            @Override
            public String toString(StrategyT strategy) {
                if (strategy != null) {
                    return strategy.getUiRep();
                }
                return null;
            }

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

        strategyList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<StrategyT>() {

            @Override
            public void changed(ObservableValue<? extends StrategyT> observable, StrategyT oldValue, StrategyT newValue) {
                strategyBox.getChildren().clear();
                strategyWidgets.clear();
                JavaFXStrategyUI ui = (JavaFXStrategyUI) uiList.getStrategyUI(newValue, true);
                strategyBox.getChildren().add(ui.getParentComponent());

                for (Atdl4jWidget<?> widget : ui.getAtdl4jWidgetMap().values()) {
                    if (widget != null) {
                        if (((JavaFXWidget) widget).getComponentsExcludingLabel() != null) {
                            for (Object atomicNode : ((JavaFXWidget) widget).getComponentsExcludingLabel()) {
                                Node n = (Node) atomicNode;
                               strategyWidgets.add(n);
                            }
                        }
                    }
                }
            }
        });
<commit_msg>Added function to get Strategy ComboBox<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.atdl4j.ui.javafx.app.impl;

import java.util.ArrayList;
import java.util.List;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.apache.log4j.Logger;
import org.atdl4j.config.Atdl4jConfig;
import org.atdl4j.config.Atdl4jConfiguration;
import org.atdl4j.config.Atdl4jOptions;
import org.atdl4j.fixatdl.core.StrategyT;
import org.atdl4j.ui.Atdl4jWidget;
import org.atdl4j.ui.app.Atdl4jCompositePanel;
import org.atdl4j.ui.app.impl.AbstractAtdl4jTesterApp;
import org.atdl4j.ui.javafx.JavaFXWidget;
import org.atdl4j.ui.javafx.config.JavaFXAtdl4jConfiguration;
import org.atdl4j.ui.javafx.impl.JavaFXStrategiesUI;
import org.atdl4j.ui.javafx.impl.JavaFXStrategyUI;

/**
 *
 * @author daniel.makgonta
 */
public class JavaFXAtdl4jTesterApp extends AbstractAtdl4jTesterApp {

    public static final Logger logger = Logger.getLogger(JavaFXAtdl4jTesterApp.class);
    private ComboBox<StrategyT> strategyList;
    private final ArrayList<Node> strategyWidgets = new ArrayList<Node>();

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {

        Atdl4jConfiguration config = new JavaFXAtdl4jConfiguration();
        JavaFXAtdl4jTesterApp tempJavaFXAtdl4jTesterApp = new JavaFXAtdl4jTesterApp();
        try {
            tempJavaFXAtdl4jTesterApp.mainLine(config, "samples/sample1.xml");
        } catch (Exception e) {
            if (Atdl4jConfig.getConfig().isCatchAllMainlineExceptions()) {
                JavaFXAtdl4jTesterApp.logger.warn("Fatal Exception in mainLine", e);
            } else {
                throw e;
            }
        }
    }

    public ArrayList<? extends Node> getStrategyWidgets() {
        return strategyWidgets;
    }

    public Pane mainLine(Atdl4jConfiguration config, String XMLFilePath) throws Exception {
        AnchorPane pane = new AnchorPane();
        AnchorPane root = new AnchorPane();

        strategyList = new ComboBox<StrategyT>();
        strategyList.setMinWidth(120);

        HBox containerBox = new HBox();
        containerBox.setPadding(new Insets(5, 0, 5, 0));
        final VBox strategyBox = new VBox();
        root.getChildren().add(containerBox);

        // -- Delegate setup to AbstractAtdl4jTesterApp, construct a new
        // JavaFX-specific Atdl4jOptions --
        Atdl4jOptions atdl4jOptions = new Atdl4jOptions();
        atdl4jOptions.setShowEnabledCheckboxOnOptionalClockControl(true);
        init(config, atdl4jOptions, pane);

        // -- Build the JavaFX panel from Atdl4jTesterPanel (** core GUI component **) --
        getAtdl4jTesterPanel().buildAtdl4jTesterPanel(pane, getAtdl4jOptions());
        Atdl4jCompositePanel panel = getAtdl4jTesterPanel().getAtdl4jCompositePanel();
        panel.parseFixatdlFile(XMLFilePath);
        panel.loadScreenWithFilteredStrategies();
        final JavaFXStrategiesUI uiList = (JavaFXStrategiesUI) panel.getStrategiesUI();
        List<StrategyT> strategies = panel.getStrategiesFilteredStrategyList();

        strategyList.getItems().addAll(strategies);
        strategyList.setCellFactory(new Callback<ListView<StrategyT>, ListCell<StrategyT>>() {
            @Override
            public ListCell<StrategyT> call(ListView<StrategyT> param) {
                return new StrategyListCell();
            }
        });

        strategyList.setConverter(new StringConverter<StrategyT>() {

            @Override
            public String toString(StrategyT strategy) {
                if (strategy != null) {
                    return strategy.getUiRep();
                }
                return null;
            }

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

        strategyList.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<StrategyT>() {

            @Override
            public void changed(ObservableValue<? extends StrategyT> observable, StrategyT oldValue, StrategyT newValue) {
                strategyBox.getChildren().clear();
                strategyWidgets.clear();
                JavaFXStrategyUI ui = (JavaFXStrategyUI) uiList.getStrategyUI(newValue, true);
                strategyBox.getChildren().add(ui.getParentComponent());

                for (Atdl4jWidget<?> widget : ui.getAtdl4jWidgetMap().values()) {
                    if (widget != null) {
                        if (((JavaFXWidget) widget).getComponentsExcludingLabel() != null) {
                            for (Object atomicNode : ((JavaFXWidget) widget).getComponentsExcludingLabel()) {
                                Node n = (Node) atomicNode;
                               strategyWidgets.add(n);
                            }
                        }
                    }
                }
            }
        });
        
        
        strategyList.getSelectionModel().selectFirst();

{'fraction_non_alphanumeric': 0.0951223902087833, 'fraction_numerical': 0.010079193664506839, 'mean_word_length': 2.6495894909688014, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '5832986', 'n_tokens_mistral': 3285, 'n_tokens_neox': 3191, 'n_words': 606}