2 * Copyright (C) 2019 Michael Zucchi
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package au.notzed.busyalert;
19 import java.time.Duration;
20 import java.time.Instant;
21 import java.time.temporal.ChronoUnit;
22 import java.util.concurrent.Executors;
23 import java.util.concurrent.ScheduledExecutorService;
24 import java.util.concurrent.TimeUnit;
25 import javafx.application.Application;
26 import javafx.application.Platform;
27 import javafx.geometry.Insets;
28 import javafx.geometry.Pos;
29 import javafx.scene.Scene;
30 import javafx.scene.control.Label;
31 import javafx.scene.layout.Background;
32 import javafx.scene.layout.BackgroundFill;
33 import javafx.scene.layout.CornerRadii;
34 import javafx.scene.layout.VBox;
35 import javafx.scene.paint.Color;
36 import javafx.scene.text.Font;
37 import javafx.stage.Stage;
39 public class BusyAlert extends Application {
41 long timeout = 60 * 5;
43 ScheduledExecutorService queue = Executors.newSingleThreadScheduledExecutor((r) -> {
44 Thread t = new Thread(r);
50 public void start(Stage primaryStage) throws Exception {
51 Stage stage = new Stage();
53 Label time = new Label();
54 Label text = new Label("BREAK NOW!");
55 VBox box = new VBox(text, time);
57 box.setAlignment(Pos.CENTER);
58 box.setBackground(new Background(new BackgroundFill(Color.GRAY, CornerRadii.EMPTY, Insets.EMPTY)));
60 VBox.setMargin(time, new Insets(20));
61 VBox.setMargin(text, new Insets(20));
63 time.setText(String.format("%3d:%02d", timeout / 60, timeout % 60));
64 time.setFont(Font.font("monspaced", 64));
66 text.setFont(Font.font("monspaced", 96));
68 Instant start = Instant.now();
70 Scene scene = new Scene(box);
72 stage.setFullScreen(true);
73 stage.setFullScreenExitHint("");
74 stage.setScene(scene);
79 Duration delta = Duration.between(start, Instant.now());
80 long waited = delta.get(ChronoUnit.SECONDS);
81 long left = timeout - waited;
83 time.setText(String.format("%3d:%02d", left / 60, left % 60));
86 queue.schedule(() -> Platform.runLater(stage::close),
87 timeout, TimeUnit.SECONDS);
90 void queueForever(Runnable r) {
91 queue.schedule(() -> {
102 public static void main(String[] args) {