<commit_before>package authoring.actionslogic;

import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;


/**
 * Controller for Action Logic Chart in Authoring Environment
 *
 */
public class ActionLogicController implements Initializable {

    @FXML
    private ListView<String> actionsListView;
    @FXML
    private ChoiceBox<String> actorsChoiceBox;
    @FXML
    private VBox myReceiversVBox;
    @FXML
    private Button saveButton;

    private List<String> myPieceTypes = new ArrayList<String>();
    private Map<String, Map<String, List<String>>> myLogicMap =
            new HashMap<String, Map<String, List<String>>>();
    private List<CheckBox> myCBList = new ArrayList<CheckBox>();

    @Override
    // TODO: [IMPORTANT]
    // This controller needs following:list of piece types, actions and a map, which contains a
    // result of saveLogic.
    public void initialize (URL location, ResourceBundle resources) {

        // for testing
        actionsListView.getItems().addAll("Attack");
        actionsListView.getItems().addAll("Heal");
        actionsListView.getItems().addAll("Run");
        myPieceTypes.add("Piece A");
        myPieceTypes.add("Piece B");
        myPieceTypes.add("Piece C");
        actorsChoiceBox.getItems().addAll(myPieceTypes);

        actorsChoiceBox
                .getSelectionModel()
                .selectedItemProperty()
                .addListener(
                             (observable, oldValue, selectedActor) -> updatePossibleReceivers(selectedActor));
    }

    // will need to be used in initialize method, so that it removes all the pieces, according to
    // given list of piece types
    private void updateLogicMap () {
        for (String actor : myLogicMap.keySet()) {
            if (!myPieceTypes.contains(actor)) {
                myLogicMap.remove(actor);
            }
        }
    }

    private void updatePossibleReceivers (String selectedActor) {
        List<String> myPosReceivers = getReceivers(myPieceTypes, selectedActor);
        myCBList.clear();
        myReceiversVBox.getChildren().clear();
        for (String p : myPosReceivers) {
            CheckBox receiverCB = new CheckBox(p);
            myCBList.add(receiverCB);
            myReceiversVBox.getChildren().add(receiverCB);
        }
    }

    private List<String> getReceivers (List<String> myPieceTypes, String actor) {
        List<String> receivers = new ArrayList<String>();
        for (String p : myPieceTypes) {
            if (!p.equals(actor)) {
                receivers.add(p);
            }
        }
        return receivers;
    }

    @FXML
    private void saveLogic () {
        String currAction = actionsListView.getSelectionModel().getSelectedItem();
        String currActor = actorsChoiceBox.getSelectionModel().getSelectedItem();
        Map<String, List<String>> actionReceiver = myLogicMap.get(currActor);
        List<String> receiverList = new ArrayList<String>();

        for (CheckBox cb : myCBList) {
            if (cb.isSelected()) {
                receiverList.add(cb.getText());
            }
        }
        if (actionReceiver == null) {
            actionReceiver = new HashMap<String, List<String>>();
        }
        actionReceiver.put(currAction, receiverList);
        myLogicMap.put(currActor, actionReceiver);
        System.out.println(myLogicMap);

    }
    
    public Map<String, Map<String, List<String>>> getActionLogic(){
        return myLogicMap;
    }
    
    

}<commit_msg>getting data from authoring controller<commit_after>package authoring.actionslogic;

import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import authoring.data.ActionData;
import authoring.data.PieceTypeData;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.ListView;
import javafx.scene.layout.VBox;


/**
 * Controller for Action Logic Chart in Authoring Environment
 *
 */
public class ActionLogicController implements Initializable {

    @FXML
    private ListView<String> actionsListView;
    @FXML
    private ChoiceBox<String> actorsChoiceBox;
    @FXML
    private VBox myReceiversVBox;
    @FXML
    private Button saveButton;

    private List<String> myPieceTypes;
    private List<String> myActionTypes;
    private Map<String, Map<String, List<String>>> myLogicMap =
            new HashMap<String, Map<String, List<String>>>();
    private List<CheckBox> myCBList = new ArrayList<CheckBox>();

    @Override
    // TODO: [IMPORTANT]
    // This controller needs following:list of piece types, actions and a map, which contains a
    // result of saveLogic.
    public void initialize (URL location, ResourceBundle resources) {
        myPieceTypes = new ArrayList<String>();
        myActionTypes= new ArrayList<String>();
        // for testing
//        actionsListView.getItems().addAll("Attack");
//        actionsListView.getItems().addAll("Heal");
//        actionsListView.getItems().addAll("Run");
//        myPieceTypes.add("Piece A");
//        myPieceTypes.add("Piece B");
//        myPieceTypes.add("Piece C");
        actorsChoiceBox.getItems().addAll(myPieceTypes);

        actorsChoiceBox
                .getSelectionModel()
                .selectedItemProperty()
                .addListener(
                             (observable, oldValue, selectedActor) -> updatePossibleReceivers(selectedActor));
    }

    // will need to be used in initialize method, so that it removes all the pieces, according to
    // given list of piece types
    private void updateLogicMap () {
        for (String actor : myLogicMap.keySet()) {
            if (!myPieceTypes.contains(actor)) {
                myLogicMap.remove(actor);
            }
        }
    }

    private void updatePossibleReceivers (String selectedActor) {
        List<String> myPosReceivers = getReceivers(myPieceTypes, selectedActor);
        myCBList.clear();
        myReceiversVBox.getChildren().clear();
        for (String p : myPosReceivers) {
            CheckBox receiverCB = new CheckBox(p);
            myCBList.add(receiverCB);
            myReceiversVBox.getChildren().add(receiverCB);
        }
    }

    private List<String> getReceivers (List<String> myPieceTypes, String actor) {
        List<String> receivers = new ArrayList<String>();
        for (String p : myPieceTypes) {
            if (!p.equals(actor)) {
                receivers.add(p);
            }
        }
        return receivers;
    }

    @FXML
    private void saveLogic () {
        String currAction = actionsListView.getSelectionModel().getSelectedItem();
        String currActor = actorsChoiceBox.getSelectionModel().getSelectedItem();
        Map<String, List<String>> actionReceiver = myLogicMap.get(currActor);
        List<String> receiverList = new ArrayList<String>();

        for (CheckBox cb : myCBList) {
            if (cb.isSelected()) {
                receiverList.add(cb.getText());
            }
        }
        if (actionReceiver == null) {
            actionReceiver = new HashMap<String, List<String>>();
        }
        actionReceiver.put(currAction, receiverList);
        myLogicMap.put(currActor, actionReceiver);
        System.out.println(myLogicMap);

    }
    
    public Map<String, Map<String, List<String>>> getActionLogic(){
        return myLogicMap;
    }
    
    public void getData(ActionData actionData, PieceTypeData ptData){
        ActionData actData = actionData;
        PieceTypeData pieceData = ptData;
        myPieceTypes = actData.getActionIDs();
        myActionTypes = (List<String>) pieceData.getIdSet();
        
        
    }
    
    

}
{'fraction_non_alphanumeric': 0.10539845758354756, 'fraction_numerical': 0.0, 'mean_word_length': 2.657117278424351, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 60, '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': '1457329', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2269, 'n_words': 512}