-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'origin/service' into develop
- Loading branch information
Showing
7 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/fr/coding/pastadellamamma/controller/ChronoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package fr.coding.pastadellamamma.controller; | ||
|
||
import fr.coding.pastadellamamma.model.Chrono; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
|
||
public class ChronoController { | ||
@FXML | ||
private Label timerLabel; | ||
|
||
@FXML | ||
private Button startServiceButton; | ||
|
||
@FXML | ||
public void initialize() { | ||
timerLabel.setText(Chrono.getTime()); | ||
|
||
if (Chrono.isRunning) { | ||
Chrono.setTimerLabel(timerLabel); | ||
startServiceButton.setDisable(true); | ||
} | ||
} | ||
|
||
@FXML | ||
public void onStartServiceButtonClicked() { | ||
startServiceButton.setDisable(true); | ||
Chrono chrono = new Chrono(timerLabel, startServiceButton); | ||
chrono.start(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package fr.coding.pastadellamamma.model; | ||
|
||
import javafx.application.Platform; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
|
||
import java.util.Timer; | ||
|
||
public class Chrono extends Thread { | ||
|
||
private static final int SERVICE_DURATION_SECONDS = 25 * 60; | ||
private static int remainingTime = SERVICE_DURATION_SECONDS; | ||
private static Timer timer; | ||
private static Label timerLabel; | ||
private static Button startServiceButton; | ||
public static boolean isRunning; | ||
|
||
public static boolean endOrder = false; | ||
|
||
public static void stopService() { | ||
isRunning = false; | ||
timer.cancel(); | ||
timer = null; | ||
remainingTime = SERVICE_DURATION_SECONDS; | ||
timerLabel.setText(getTime()); | ||
startServiceButton.setDisable(false); | ||
} | ||
|
||
public static String getTime() { | ||
int minutes = remainingTime / 60; | ||
int remainingSeconds = remainingTime % 60; | ||
return String.format("%02d:%02d", minutes, remainingSeconds); | ||
} | ||
|
||
public static void setTimerLabel(Label label) { | ||
timerLabel = label; | ||
} | ||
|
||
public void run() { | ||
isRunning = true; | ||
|
||
try { | ||
for (;;) { | ||
System.out.println(remainingTime); | ||
Platform.runLater(() -> timerLabel.setText(getTime())); | ||
|
||
Thread.sleep(1000); | ||
remainingTime--; | ||
|
||
if (remainingTime <= 0) { | ||
stopService(); | ||
} | ||
|
||
if (remainingTime <= 900) { | ||
endOrder = true; | ||
} | ||
} | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public Chrono(Label label, Button startButton) { | ||
timerLabel = label; | ||
startServiceButton = startButton; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.SplitPane?> | ||
<?import javafx.scene.layout.AnchorPane?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import javafx.scene.text.Font?> | ||
|
||
|
||
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.coding.pastadellamamma.controller.ChronoController"> | ||
<children> | ||
<SplitPane dividerPositions="0.32357859531772576" prefHeight="457.0" prefWidth="600.0"> | ||
<items> | ||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="631.0" prefWidth="175.0"> | ||
<children> | ||
<Button fx:id="startServiceButton" layoutX="35.0" layoutY="78.0" mnemonicParsing="false" onAction="#onStartServiceButtonClicked" text="Démarer le service" /> | ||
<Label fx:id="timerLabel" layoutX="60.0" layoutY="250.0"> | ||
<font> | ||
<Font size="36.0" /> | ||
</font> | ||
</Label> | ||
<Label layoutY="131.0" prefHeight="68.0" prefWidth="191.0" text="Temps restant avant la fin du service" textAlignment="CENTER" wrapText="true"> | ||
<font> | ||
<Font size="18.0" /> | ||
</font> | ||
</Label> | ||
</children> | ||
</AnchorPane> | ||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="412.0" prefWidth="416.0" /> | ||
</items> | ||
</SplitPane> | ||
</children> | ||
</VBox> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters