<commit_before>package com.greatwebguy.application;

import java.io.IOException;
import java.net.URL;
import java.time.format.DateTimeFormatter;
import java.util.ResourceBundle;

import javafx.animation.Animation.Status;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Duration;

public class TimeController implements Initializable {
	private Timeline timeline;
	
	private StringProperty timeMinutes = new SimpleStringProperty("Start");
	
    @FXML //  fx:id="startButton"
    private Button startButton; // Value injected by FXMLLoader
    
    @FXML
    private Button stopButton;
    
    @FXML
    private Button settingsButton;
    
    @FXML // fx:id="timerLabel"
    private Label timerLabel;
    
    @FXML // fx:id="turnLabel"
    private Label turnLabel;   
    
    

    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
        assert startButton != null : "fx:id=\"startButton\" was not injected: check your FXML file 'application.fxml'.";
        assert stopButton != null : "fx:id=\"stopButton\" was not injected: check your FXML file 'application.fxml'.";
        assert settingsButton != null : "fx:id=\"settingsButton\" was not injected: check your FXML file 'application.fxml'.";
        assert timerLabel != null : "fx:id=\"timerLabel\" was not injected: check your FXML file 'application.fxml'.";
        assert turnLabel != null : "fx:id=\"turnLabel\" was not injected: check your FXML file 'application.fxml'.";
        
        timerLabel.textProperty().bind(timeMinutes);
        turnLabel.textProperty().bind(Settings.instance().userMessage);
        Settings.instance().displayUserMessage();
        	
        startButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	if(timeline == null || timeline.getStatus().equals(Status.STOPPED)) {
            		resetStartState();
					timeMinutes.set(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")));
					timeline = new Timeline();
					timeline.setCycleCount(Settings.instance().getTimeInSeconds());
					timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), new EventHandler<ActionEvent>() {
						// KeyFrame event handler
						public void handle(ActionEvent event) {
							Settings.instance().setTime(Settings.instance().getTime().minusSeconds(1));
							timeMinutes.set(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")));
							if ("00:00".equals(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")))) {
								showRotate();
							}
						}

					}));
					timeline.playFromStart();
					Settings.instance().displayUserMessage();
					startButton.setStyle("-fx-background-color:#71B284");
					hideWindow();
					
            	} else {
            		switch (timeline.getStatus()) {
					case RUNNING:
						timeline.pause();
						break;
					case PAUSED:
						timeline.play();
						hideWindow();
						break;
					default:
						break;
					}
            	}
            }
        });
        
        //Stop and reset the timer
        stopButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	resetStartState();
            }
        });
        
		settingsButton.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				try {
					Stage stage = new Stage();
					Parent root = FXMLLoader.load(SettingsController.class.getResource("settings-modal.fxml"));
					stage.setScene(new Scene(root));
					stage.setTitle("Settings");
					stage.initModality(Modality.WINDOW_MODAL);
					stage.initOwner(((Node) event.getSource()).getScene().getWindow());
					stage.show();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
    }
    

	private void showRotate() {
    	if(timeline != null) {
    		timeline.stop();
    	}
    	timeMinutes.set("Rotate");
    	startButton.setStyle("-fx-background-color:#FF0000");
    	URL resource = getClass().getResource("door-bell.wav");
    	Media doorBell = new Media(resource.toString());
    	MediaPlayer mediaPlayer = new MediaPlayer(doorBell);
    	mediaPlayer.play();
    	Stage window = (Stage)timerLabel.getScene().getWindow();
    	Settings.instance().incrementCurrentUser();
        window.toFront();
        window.requestFocus();
    	
    }

    private void resetStartState() {
    	if(timeline != null) {
    		timeline.stop();
    	}
    	timeMinutes.set("Start");
    	Settings.instance().initializeTime();
    	startButton.setStyle("-fx-background-color:#333333");
    }
    
	private void hideWindow() {
		Timeline hide = new Timeline(1, new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent actionEvent) {
				Stage window = (Stage) timerLabel.getScene().getWindow();
				window.toBack();<commit_msg>Update Audio<commit_after>package com.greatwebguy.application;

import java.io.IOException;
import java.net.URL;
import java.time.format.DateTimeFormatter;
import java.util.ResourceBundle;

import javafx.animation.Animation.Status;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Duration;

public class TimeController implements Initializable {
	private Timeline timeline;
	
	private StringProperty timeMinutes = new SimpleStringProperty("Start");
	
    @FXML //  fx:id="startButton"
    private Button startButton; // Value injected by FXMLLoader
    
    @FXML
    private Button stopButton;
    
    @FXML
    private Button settingsButton;
    
    @FXML // fx:id="timerLabel"
    private Label timerLabel;
    
    @FXML // fx:id="turnLabel"
    private Label turnLabel;   
    
    

    @Override // This method is called by the FXMLLoader when initialization is complete
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
        assert startButton != null : "fx:id=\"startButton\" was not injected: check your FXML file 'application.fxml'.";
        assert stopButton != null : "fx:id=\"stopButton\" was not injected: check your FXML file 'application.fxml'.";
        assert settingsButton != null : "fx:id=\"settingsButton\" was not injected: check your FXML file 'application.fxml'.";
        assert timerLabel != null : "fx:id=\"timerLabel\" was not injected: check your FXML file 'application.fxml'.";
        assert turnLabel != null : "fx:id=\"turnLabel\" was not injected: check your FXML file 'application.fxml'.";
        
        timerLabel.textProperty().bind(timeMinutes);
        turnLabel.textProperty().bind(Settings.instance().userMessage);
        Settings.instance().displayUserMessage();
       
        	
        startButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	if(timeline == null || timeline.getStatus().equals(Status.STOPPED)) {
            		resetStartState();
					timeMinutes.set(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")));
					timeline = new Timeline();
					timeline.setCycleCount(Settings.instance().getTimeInSeconds());
					timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(1), new EventHandler<ActionEvent>() {
						// KeyFrame event handler
						public void handle(ActionEvent event) {
							Settings.instance().setTime(Settings.instance().getTime().minusSeconds(1));
							timeMinutes.set(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")));
							if ("00:00".equals(Settings.instance().getTime().format(DateTimeFormatter.ofPattern("mm:ss")))) {
								showRotate();
							}
						}

					}));
					timeline.playFromStart();
					Settings.instance().displayUserMessage();
					startButton.setStyle("-fx-background-color:#71B284");
					hideWindow();
					
            	} else {
            		switch (timeline.getStatus()) {
					case RUNNING:
						timeline.pause();
						break;
					case PAUSED:
						timeline.play();
						hideWindow();
						break;
					default:
						break;
					}
            	}
            }
        });
        
        //Stop and reset the timer
        stopButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
            	resetStartState();
            }
        });
        
		settingsButton.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				try {
					Stage stage = new Stage();
					Parent root = FXMLLoader.load(SettingsController.class.getResource("settings-modal.fxml"));
					stage.setScene(new Scene(root));
					stage.setTitle("Settings");
					stage.initModality(Modality.WINDOW_MODAL);
					stage.initOwner(((Node) event.getSource()).getScene().getWindow());
					stage.show();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
    }
    

	private void showRotate() {
		 URL doorBellWav = getClass().getResource("door-bell.wav");
	     AudioClip doorBellSound = new AudioClip(doorBellWav.toString());
	     doorBellSound.play();
    	if(timeline != null) {
    		timeline.stop();
    	}
    	timeMinutes.set("Rotate");
    	startButton.setStyle("-fx-background-color:#FF0000");
    	Stage window = (Stage)timerLabel.getScene().getWindow();
    	Settings.instance().incrementCurrentUser();
        window.toFront();
        window.requestFocus();
    	
    }

    private void resetStartState() {
    	if(timeline != null) {
    		timeline.stop();
    	}
    	timeMinutes.set("Start");
    	Settings.instance().initializeTime();
    	startButton.setStyle("-fx-background-color:#333333");
    }
    
	private void hideWindow() {
		Timeline hide = new Timeline(1, new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent actionEvent) {
				Stage window = (Stage) timerLabel.getScene().getWindow();
				window.toBack();
{'fraction_non_alphanumeric': 0.12463434092722277, 'fraction_numerical': 0.004077652690364329, 'mean_word_length': 3.1738808731039585, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '1692171', 'n_tokens_mistral': 3633, 'n_tokens_neox': 3188, 'n_words': 636}