Skip to content
Snippets Groups Projects
Commit 4128215d authored by Robert Goldmann's avatar Robert Goldmann
Browse files

added basic functionality

parent a2d3888a
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ public class Main extends Application
stage.getIcons().add(new Image("/de/deadlocker8/loadingbar/resources/icon.png"));
stage.setTitle(bundle.getString("app.name"));
stage.setScene(scene);
stage.getScene().getStylesheets().add("de/deadlocker8/loadingbar/ui/style.css");
stage.show();
}
catch(Exception e)
......
package de.deadlocker8.loadingbar.ui;
import java.util.Collections;
import java.util.Locale;
import java.util.Random;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import tools.AlertGenerator;
public class Controller
{
@FXML private Label label;
@FXML private AnchorPane mainPane;
@FXML private Label labelTarget;
@FXML private Label labelUser;
@FXML private Label labelMessage;
@FXML private ProgressBar progressBar;
@FXML private ProgressBar progressBarTarget;
@FXML private StackPane stackPane;
private Stage stage;
private Image icon = new Image("de/deadlocker8/loadingbar/resources/icon.png");
private final ResourceBundle bundle = ResourceBundle.getBundle("de/deadlocker8/loadingbar/main/", Locale.GERMANY);
private CountdownTimer timer;
private int targetPercentage;
private boolean swapped;
public void init(Stage stage)
{
this.stage = stage;
mainPane.setStyle("-fx-background-color: #333333");
stackPane.setStyle("-fx-background-color: derive(#333333, -60%)");
progressBar.setStyle("-fx-accent: white;");
labelTarget.setStyle("-fx-text-fill: white; -fx-font-size: 40; -fx-font-weight: bold;");
labelUser.setStyle("-fx-text-fill: white; -fx-font-size: 30; -fx-font-weight: bold;");
labelMessage.setStyle("-fx-text-fill: white; -fx-font-size: 30; -fx-font-weight: bold;");
}
public void buttonStart()
{
if(swapped)
{
swapProgressBars();
swapped = false;
}
Random random = new Random();
int targetPercentage = 10 + random.nextInt(90 - 10 + 1);
label.setText(String.valueOf(targetPercentage));
targetPercentage = 15 + random.nextInt(90 - 15 + 1);
labelTarget.setText(String.valueOf(targetPercentage));
labelUser.setText("");
labelMessage.setText("");
progressBarTarget.setProgress(0.0);
progressBar.setProgress(0.0);
timer = new CountdownTimer(4.0, this);
......@@ -46,11 +76,42 @@ public class Controller
progressBar.setProgress(value);
}
private void swapProgressBars()
{
ObservableList<Node> workingCollection = FXCollections.observableArrayList(stackPane.getChildren());
Collections.swap(workingCollection, 0, 1);
stackPane.getChildren().setAll(workingCollection);
}
public void stop(double value)
{
int userPercentage = (int)(value * 100);
labelUser.setText(String.valueOf(userPercentage));
progressBar.setProgress(userPercentage / 100.0);
progressBarTarget.setProgress(targetPercentage / 100.0);
progressBarTarget.setStyle("-fx-accent: red");
if(userPercentage < targetPercentage)
{
swapped = true;
swapProgressBars();
}
label.setText(label.getText() + " - " + userPercentage);
int difference = Math.abs(targetPercentage - userPercentage);
switch(difference)
{
case 0:
labelMessage.setText("Awesome!");
break;
case 1:
labelMessage.setText("Close One!");
break;
case 2:
labelMessage.setText("Almost");
break;
default:
labelMessage.setText("Missed by " + difference);
}
}
public Stage getStage()
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.loadingbar.ui.Controller">
<AnchorPane fx:id="mainPane" prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.loadingbar.ui.Controller">
<children>
<ProgressBar fx:id="progressBar" layoutX="25.0" layoutY="129.0" prefWidth="200.0" progress="0.0" AnchorPane.leftAnchor="25.0" AnchorPane.rightAnchor="25.0" />
<Button layoutX="174.0" layoutY="174.0" mnemonicParsing="false" onAction="#buttonStart" text="Start" />
<Label fx:id="label" layoutX="174.0" layoutY="89.0" prefHeight="27.0" prefWidth="147.0">
<VBox alignment="TOP_CENTER" layoutX="25.0" layoutY="16.0" prefHeight="363.0" prefWidth="350.0" AnchorPane.bottomAnchor="25.0" AnchorPane.leftAnchor="25.0" AnchorPane.rightAnchor="25.0" AnchorPane.topAnchor="25.0">
<children>
<Label fx:id="labelMessage" alignment="CENTER" maxWidth="1.7976931348623157E308" prefHeight="27.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<Label fx:id="labelTarget" alignment="CENTER" maxWidth="1.7976931348623157E308" prefHeight="27.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</Label>
<StackPane fx:id="stackPane">
<children>
<ProgressBar fx:id="progressBar" maxWidth="1.7976931348623157E308" progress="0.0" />
<ProgressBar fx:id="progressBarTarget" maxWidth="1.7976931348623157E308" progress="0.0" />
</children>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</StackPane>
<Label fx:id="labelUser" alignment="CENTER" maxWidth="1.7976931348623157E308" prefHeight="27.0">
<font>
<Font name="System Bold" size="18.0" />
</font>
<VBox.margin>
<Insets top="15.0" />
</VBox.margin>
</Label>
<Button layoutX="240.0" layoutY="174.0" mnemonicParsing="false" onAction="#buttonStop" text="Stop" />
<Button mnemonicParsing="false" onAction="#buttonStop" text="STOP">
<VBox.margin>
<Insets top="20.0" />
</VBox.margin>
<font>
<Font name="System Bold" size="24.0" />
</font>
</Button>
<Button mnemonicParsing="false" onAction="#buttonStart" text="Start">
<VBox.margin>
<Insets top="50.0" />
</VBox.margin>
</Button>
</children>
</VBox>
</children>
</AnchorPane>
.progress-bar {
-fx-indeterminate-bar-length: 60;
-fx-indeterminate-bar-escape: true;
-fx-indeterminate-bar-flip: true;
-fx-indeterminate-bar-animation-time: 2;
}
.progress-bar > .bar {
-fx-background-color: -fx-accent;
-fx-background-insets: 0 0 0 0;
-fx-background-radius: 0;
-fx-padding: 0.75em;
}
.progress-bar > .track {
-fx-background-color: transparent;
-fx-background-insets: 0, 0 0 0 0, 0 0 0 0;
-fx-background-radius: 0, 0, 0;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment