-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a preloader to notify users of the status of startup routines (#445)
- Loading branch information
1 parent
4a1d68e
commit 155e250
Showing
5 changed files
with
201 additions
and
19 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
38 changes: 38 additions & 0 deletions
38
app/src/main/java/edu/wpi/first/shuffleboard/app/PreloaderController.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,38 @@ | ||
package edu.wpi.first.shuffleboard.app; | ||
|
||
import edu.wpi.first.shuffleboard.api.util.FxUtils; | ||
|
||
import org.controlsfx.tools.Utils; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.ProgressBar; | ||
import javafx.scene.layout.Pane; | ||
|
||
public class PreloaderController { | ||
|
||
@FXML | ||
private Pane root; | ||
@FXML | ||
private Label versionLabel; | ||
@FXML | ||
private Label stateLabel; | ||
@FXML | ||
private ProgressBar progressBar; | ||
|
||
@FXML | ||
private void initialize() { | ||
progressBar.setProgress(-1); | ||
versionLabel.setText(Shuffleboard.getVersion()); | ||
FxUtils.setController(root, this); | ||
} | ||
|
||
public void setStateText(String text) { | ||
stateLabel.setText(text + "..."); | ||
} | ||
|
||
public void setProgress(double progress) { | ||
progressBar.setProgress(Utils.clamp(0, progress, 1)); | ||
} | ||
|
||
} |
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
91 changes: 91 additions & 0 deletions
91
app/src/main/java/edu/wpi/first/shuffleboard/app/ShuffleboardPreloader.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,91 @@ | ||
package edu.wpi.first.shuffleboard.app; | ||
|
||
import edu.wpi.first.shuffleboard.api.util.FxUtils; | ||
import edu.wpi.first.shuffleboard.app.prefs.AppPreferences; | ||
|
||
import javafx.application.Preloader; | ||
import javafx.fxml.FXMLLoader; | ||
import javafx.scene.Scene; | ||
import javafx.scene.layout.Pane; | ||
import javafx.stage.Stage; | ||
import javafx.stage.StageStyle; | ||
|
||
/** | ||
* The preloader for shuffleboard. This will display the progress of various startup routines until the main window | ||
* appears. | ||
*/ | ||
public class ShuffleboardPreloader extends Preloader { | ||
|
||
private Stage preloaderStage; | ||
private PreloaderController controller; | ||
|
||
@Override | ||
public void start(Stage stage) throws Exception { | ||
preloaderStage = stage; | ||
|
||
Pane preloaderPane = FXMLLoader.load(PreloaderController.class.getResource("Preloader.fxml")); | ||
controller = FxUtils.getController(preloaderPane); | ||
|
||
Scene scene = new Scene(preloaderPane); | ||
scene.getStylesheets().setAll(AppPreferences.getInstance().getTheme().getStyleSheets()); | ||
stage.setScene(scene); | ||
stage.initStyle(StageStyle.UNDECORATED); | ||
stage.show(); | ||
} | ||
|
||
@Override | ||
public void handleApplicationNotification(PreloaderNotification info) { | ||
if (info instanceof StateNotification) { | ||
StateNotification notification = (StateNotification) info; | ||
controller.setStateText(notification.getState()); | ||
controller.setProgress(notification.getProgress()); | ||
} | ||
} | ||
|
||
@Override | ||
public void handleStateChangeNotification(StateChangeNotification info) { | ||
if (info.getType() == StateChangeNotification.Type.BEFORE_START) { | ||
preloaderStage.close(); | ||
} | ||
} | ||
|
||
/** | ||
* A notification for the progress of a state in the preloader. | ||
*/ | ||
public static final class StateNotification implements PreloaderNotification { | ||
|
||
private final String state; | ||
private final double progress; | ||
|
||
/** | ||
* Creates a new state notification. | ||
* | ||
* @param state the state | ||
* @param progress the progress of the state, in the range [0, 1] | ||
*/ | ||
public StateNotification(String state, double progress) { | ||
this.state = state; | ||
this.progress = progress; | ||
} | ||
|
||
/** | ||
* Gets the state. | ||
*/ | ||
public String getState() { | ||
return state; | ||
} | ||
|
||
/** | ||
* Gets the progress. | ||
*/ | ||
public double getProgress() { | ||
return progress; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("StateNotification(state='%s', progress=%s)", state, progress); | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/resources/edu/wpi/first/shuffleboard/app/Preloader.fxml
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.ProgressBar?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.VBox?> | ||
<BorderPane xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1" | ||
fx:controller="edu.wpi.first.shuffleboard.app.PreloaderController" | ||
fx:id="root" | ||
prefWidth="480.0" prefHeight="240.0"> | ||
<center> | ||
<VBox alignment="CENTER_LEFT" styleClass="shuffleboard-dialog-header"> | ||
<padding> | ||
<Insets topRightBottomLeft="32"/> | ||
</padding> | ||
<Label text="WPILib Shuffleboard" styleClass="shuffleboard-dialog-header-title"/> | ||
<Label fx:id="versionLabel" styleClass="shuffleboard-dialog-header-subtitle"/> | ||
</VBox> | ||
</center> | ||
<bottom> | ||
<VBox> | ||
<Label fx:id="stateLabel" alignment="CENTER" maxWidth="Infinity" textAlignment="CENTER"/> | ||
<ProgressBar fx:id="progressBar" maxWidth="Infinity" maxHeight="6"/> | ||
</VBox> | ||
</bottom> | ||
</BorderPane> |