<commit_before>package gui;

import Game.Panel;
import Game.Player;
import Game.Team;
import gui.panel.IPanel;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.TimerTask;

/**
 * Created by <NAME> on 6-10-2015.
 */
public class GameController implements Initializable {
    @FXML
    private Button buttonStart;
    @FXML
    private Button buttonStartTimer;
    @FXML
    private ProgressBar progressBar = new ProgressBar(1);
    @FXML
    private Label timeLabel;
    @FXML
    private Label secondenLabel;
    @FXML
    private Label instructionLabel;

    private Timer timer;
    @FXML
    private GridPane gridPane = new GridPane();

    @FXML
    private Label labelCorrectInstructions;
    @FXML
    private ImageView Team1Leven1;
    @FXML
    private ImageView Team1Leven2;
    @FXML
    private ImageView Team1Leven3;
    @FXML
    private ImageView Team2Leven1;
    @FXML
    private ImageView Team2Leven2;
    @FXML
    private ImageView Team2Leven3;
    @FXML
    private TextField lblTeamName1;
    @FXML
    private TextField lblTeamName2;

    private GameView view;
    private Runnable runnable;
    private PanelFactory panelFactory;
    private java.util.Timer timerRefresh;
    private TimerTask timerTask;
    private ArrayList<Panel> panelHolder;
    private boolean panelPushed;
    private AudioPlayer explosionPlayer;

    /**
     * Called to initialize a controller after its root element has been
     * completely processed.
     *
     * start a timer for refreshView
     *
     * @param location  The location used to resolve relative paths for the root object, or
     *                  <tt>null</tt> if the location is not known.
     * @param resources The resources used to localize the root object, or <tt>null</tt> if
     */
    public void initialize(URL location, ResourceBundle resources) {

        panelFactory = new PanelFactory();

        buttonStartTimer.setOnMouseClicked(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                buttonStartTimerOnClick(event);
            }
        });

        timerRefresh = new java.util.Timer();
        timerTask = new TimerTask() {
            @Override
            public void run() {
                refreshView();
            }
        };
        timerRefresh.schedule(timerTask, 0, 30);

        URL url = this.getClass().getClassLoader().getResource("audio/ExplosieMetBliep.mp3");

        try (FileInputStream fileInputStream = new FileInputStream(url.getPath())) {
            explosionPlayer = new AudioPlayer(fileInputStream.toString());
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    /**
     * Call methods to refresh the View
     */
    private void refreshView() {
        showTeamLevens();
        showTeamInstructionCount();
        showPlayerInstruction();
        panelChecker();
    }

    /**
     * checks if grid with panels is filled
     */
    private void panelChecker() {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                if (!panelHolder.equals(view.stageController.game.getPlayerByName(view.stageController.playerName).getPanels())) {
                    fillGridWithPanels();
                }
            }
        });
    }

    /**
     * Sets the GameView
     * refreshes the View
     * @param gameView
     */
    public void setView(GameView gameView) {
        view = gameView;
        fillGridWithPanels();
        showTeamLevens();
        setTeamNames();
    }

    /**
     * Fills the gridPane with panels in the right row and column
     * refreshes every Round
     */
    public void fillGridWithPanels() {
        gridPane.getChildren().clear();
        gridPane.setMinSize(0, 0);
        gridPane.setAlignment(Pos.CENTER);
        final ArrayList<Panel> panels = view.stageController.game.getPlayerByName(StageController.playerName).getPanels();
        panelHolder = panels;
        int column = 0;
        int row = 0;
        for (Panel panel : panels) {
            IPanel iPanel = PanelFactory.getPanel(panel, this);
            System.out.println(panel.getText());
            if (row < 4) {
                gridPane.add((Node) iPanel, row, column);
            } else {
                row = 0;
                column++;
                gridPane.add((Node) iPanel, row, column);
            }
            row++;
        }

    }

    /**
     * Shows the player Instruction in instructionLabel
     * refreshes ever 30 ms
     */
    private void showPlayerInstruction() {
        Platform.runLater(new Runnable() {
            public void run() {
                if (view.stageController.game.getPlayerByName(StageController.playerName) != null)
                    instructionLabel.setText(view.stageController.game.getPlayerByName(StageController.playerName).getInstruction().toString() + " to: " + view.stageController.game.getPlayerByName(StageController.playerName).getInstruction().getValue());<commit_msg>Toevoegen van de logger aan de gamecontroller en zijn methodes<commit_after>package gui;

import Game.Panel;
import Game.Player;
import Game.Team;
import gui.panel.IPanel;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TextField;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javassist.bytecode.stackmap.TypeData;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by <NAME> on 6-10-2015.
 */
public class GameController implements Initializable {
    @FXML
    private Button buttonStart;
    @FXML
    private Button buttonStartTimer;
    @FXML
    private ProgressBar progressBar = new ProgressBar(1);
    @FXML
    private Label timeLabel;
    @FXML
    private Label secondenLabel;
    @FXML
    private Label instructionLabel;

    private Timer timer;
    @FXML
    private GridPane gridPane = new GridPane();

    @FXML
    private Label labelCorrectInstructions;
    @FXML
    private ImageView Team1Leven1;
    @FXML
    private ImageView Team1Leven2;
    @FXML
    private ImageView Team1Leven3;
    @FXML
    private ImageView Team2Leven1;
    @FXML
    private ImageView Team2Leven2;
    @FXML
    private ImageView Team2Leven3;
    @FXML
    private TextField lblTeamName1;
    @FXML
    private TextField lblTeamName2;

    private GameView view;
    private Runnable runnable;
    private PanelFactory panelFactory;
    private java.util.Timer timerRefresh;
    private TimerTask timerTask;
    private ArrayList<Panel> panelHolder;
    private boolean panelPushed;
    private AudioPlayer explosionPlayer;
    private static final Logger log = Logger.getLogger(TypeData.ClassName.class.getName());

    /**
     * Called to initialize a controller after its root element has been
     * completely processed.
     *
     * start a timer for refreshView
     *
     * @param location  The location used to resolve relative paths for the root object, or
     *                  <tt>null</tt> if the location is not known.
     * @param resources The resources used to localize the root object, or <tt>null</tt> if
     */
    public void initialize(URL location, ResourceBundle resources) {
        log.log(Level.INFO,"Start initializing the gamecontroller");
        panelFactory = new PanelFactory();

        buttonStartTimer.setOnMouseClicked(new EventHandler<MouseEvent>() {
            public void handle(MouseEvent event) {
                buttonStartTimerOnClick(event);
            }
        });

        timerRefresh = new java.util.Timer();
        timerTask = new TimerTask() {
            @Override
            public void run() {
                refreshView();
            }
        };
        timerRefresh.schedule(timerTask, 0, 30);

        URL url = this.getClass().getClassLoader().getResource("audio/ExplosieMetBliep.mp3");
        log.log(Level.INFO, "Audiofile url set to: {0}", url.toString());
        try (FileInputStream fileInputStream = new FileInputStream(url.getPath())) {
            explosionPlayer = new AudioPlayer(fileInputStream.toString());
            log.log(Level.INFO,"explosion audioplayer created");
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
            log.log(Level.SEVERE, e1.toString(), e1);
        } catch (IOException e1) {
            e1.printStackTrace();
            log.log(Level.SEVERE, e1.toString(), e1);
        }
    }

    /**
     * Call methods to refresh the View
     */
    private void refreshView() {
        log.log(Level.FINER,"refreshView started");
        showTeamLevens();
        showTeamInstructionCount();
        showPlayerInstruction();
        panelChecker();
        log.log(Level.FINER, "refreshView ended");
    }

    /**
     * checks if grid with panels is filled
     */
    private void panelChecker() {
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                if (!panelHolder.equals(view.stageController.game.getPlayerByName(view.stageController.playerName).getPanels())) {
                    fillGridWithPanels();
                    log.log(Level.INFO,"Gridview filled with panels");
                }
            }
        });
    }

    /**
     * Sets the GameView
     * refreshes the View
     * @param gameView
     */
    public void setView(GameView gameView) {
        log.log(Level.FINER,"setView started");
        view = gameView;
        fillGridWithPanels();
        showTeamLevens();
        setTeamNames();
        log.log(Level.FINER, "setView ended");
    }

    /**
     * Fills the gridPane with panels in the right row and column
     * refreshes every Round
     */
    public void fillGridWithPanels() {
        log.log(Level.INFO,"fillGridWithPanels started");
        gridPane.getChildren().clear();
        gridPane.setMinSize(0, 0);
        gridPane.setAlignment(Pos.CENTER);
        log.log(Level.INFO,"gridPane children cleared, minsize set and alignment set");
        final ArrayList<Panel> panels = view.stageController.game.getPlayerByName(StageController.playerName).getPanels();
        panelHolder = panels;
        int column = 0;
        int row = 0;
        log.log(Level.INFO,"Add panels to the gridpane");
        for (Panel panel : panels) {
            IPanel iPanel = PanelFactory.getPanel(panel, this);
            System.out.println(panel.getText());
            if (row < 4) {
                gridPane.add((Node) iPanel, row, column);
            } else {
                row = 0;
                column++;
                gridPane.add((Node) iPanel, row, column);
            }
            log.log(Level.FINER, "Added panel with text {0}", panel.getText());
            row++;
        }
        log.log(Level.INFO, "Loaded {0} panels in the gridPane",panels.size());
    }

    /**
     * Shows the player Instruction in instructionLabel
     * refreshes ever 30 ms
     */
    private void showPlayerInstruction() {

        Platform.runLater(new Runnable() {
            public void run() {
                if (view.stageController.game.getPlayerByName(StageController.playerName) != null)
                    instructionLabel.setText(view.stageController.game.getPlayerByName(StageController.playerName).getInstruction().toString() + " to: " + view.stageController.game.getPlayerByName(StageController.playerName).getInstruction().getValue());
{'fraction_non_alphanumeric': 0.09642521166509878, 'fraction_numerical': 0.006506741925368454, 'mean_word_length': 2.529883785279469, 'pattern_counts': {'":': 0, '<': 21, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1994429', 'n_tokens_mistral': 3546, 'n_tokens_neox': 3464, 'n_words': 869}