kauron/estraba
Archived
1
0
Fork 0

Moved Splash HR dialog to Splash

This commit is contained in:
Carlos Galindo 2016-05-25 11:02:05 +02:00
parent cd465af904
commit 435c695ab7
Signed by: kauron
GPG key ID: 83E68706DEE119A3
5 changed files with 67 additions and 74 deletions

View file

@ -30,6 +30,7 @@ import com.jfoenix.controls.JFXSnackbar;
import com.jfoenix.controls.JFXSpinner;
import es.kauron.estraba.App;
import es.kauron.estraba.model.DataBundle;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
@ -37,16 +38,14 @@ import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.*;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
@ -80,6 +79,12 @@ public class SplashController implements Initializable{
@FXML
private JFXButton buttonLoad;
@FXML
private Text textHR, textAge;
@FXML
private Spinner<Integer> spinnerAge, spinnerHR;
private JFXSnackbar snackbar;
private File file;
private int maxHR;
@ -98,9 +103,11 @@ public class SplashController implements Initializable{
}
public void loadGPXFile(File file) {
maxHR = showHRDialog();
if (maxHR < 0) errorLoading();
buttonLoad.setVisible(false);
textAge.setVisible(false);
textHR.setVisible(false);
spinnerAge.setVisible(false);
spinnerHR.setVisible(false);
labelWelcome.setVisible(false);
spinner.setVisible(true);
snackbar.show("Loading file", 5000);
@ -109,7 +116,7 @@ public class SplashController implements Initializable{
protected DataBundle call() throws Exception {
DataBundle db = null;
try {
db = DataBundle.loadFrom(file, maxHR);
db = DataBundle.loadFrom(file, spinnerHR.getValue());
} catch (Exception e) {
e.printStackTrace();
}
@ -158,17 +165,16 @@ public class SplashController implements Initializable{
}
});
Platform.runLater(() -> root.setOnDragOver(e -> {
Platform.runLater(() -> {
root.setOnDragOver(e -> {
Dragboard db = e.getDragboard();
if (db.hasFiles()) {
e.acceptTransferModes(TransferMode.COPY);
} else {
e.consume();
}
}));
// Dropping over surface
Platform.runLater(() -> root.setOnDragDropped(e -> {
});
root.setOnDragDropped(e -> {
Dragboard db = e.getDragboard();
boolean success = false;
if (db.hasFiles()) {
@ -177,46 +183,28 @@ public class SplashController implements Initializable{
}
e.setDropCompleted(success);
e.consume();
}));
});
});
snackbar.registerSnackbarContainer(root);
}
private void errorLoading() {
buttonLoad.setVisible(true);
labelWelcome.setVisible(true);
spinner.setVisible(false);
snackbar.show(App.GENERAL_BUNDLE.getString("error.file"), 3000);
}
private int showHRDialog() {
Dialog<Integer> dialog = new Dialog<>();
dialog.setTitle("Input your maximum heart rate or age");
GridPane grid = new GridPane();
grid.setHgap(5);
grid.setVgap(2);
grid.addColumn(0, new Text("Heart rate:"), new Text("Age:"));
Spinner<Integer> spinnerAge = new Spinner<>(18, 99, 25, 1);
Spinner<Integer> spinnerHR = new Spinner<>(60, 202, 180, 5);
spinnerAge.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(18, 99, 25, 1));
spinnerHR.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(60, 202, 195, 5));
spinnerAge.valueProperty().addListener((obs, oldV, newV) ->
spinnerHR.setValueFactory(new SpinnerValueFactory
.IntegerSpinnerValueFactory(60, 202, 220 - newV, 5)));
spinnerHR.valueProperty().addListener((obs, old, newV) ->
spinnerAge.setValueFactory(new SpinnerValueFactory
.IntegerSpinnerValueFactory(18, 99, 220 - newV, 1)));
grid.addColumn(1, spinnerHR, spinnerAge);
Button buttonOk = new Button("Ok");
buttonOk.setDefaultButton(true);
buttonOk.setOnAction(event -> {
dialog.setResult(spinnerHR.getValue());
dialog.close();
});
grid.add(buttonOk, 1, 2);
dialog.getDialogPane().setContent(grid);
dialog.showAndWait();
if (dialog.getResult() != null)
return dialog.getResult();
else
return -1;
}
private void errorLoading() {
textAge.setVisible(true);
textHR.setVisible(true);
spinnerHR.setVisible(true);
spinnerAge.setVisible(true);
buttonLoad.setVisible(true);
labelWelcome.setVisible(true);
spinner.setVisible(false);
snackbar.show(App.GENERAL_BUNDLE.getString("error.file"), 3000);
}
}

View file

@ -29,24 +29,23 @@
<?import com.jfoenix.controls.JFXSpinner?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" styleClass="background"
stylesheets="@../css/palette.css" xmlns="http://javafx.com/javafx/8.0.76-ea"
fx:controller="es.kauron.estraba.controller.SplashController">
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="300.0" styleClass="background" stylesheets="@../css/palette.css" xmlns="http://javafx.com/javafx/8.0.76-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="es.kauron.estraba.controller.SplashController">
<ImageView fx:id="imgLogo" fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="50.0" AnchorPane.rightAnchor="50.0" AnchorPane.topAnchor="25.0">
</ImageView>
<JFXSpinner fx:id="spinner" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<Label fx:id="labelWelcome" alignment="CENTER" text="%label.welcome" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
<StackPane layoutX="-1.0" layoutY="251.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<JFXButton fx:id="buttonLoad" maxHeight="-Infinity" maxWidth="-Infinity" onAction="#loadGPXFile" styleClass="accent-color" text="%label.loadGPX">
<Label fx:id="labelWelcome" alignment="CENTER" layoutX="101.0" layoutY="91.0" text="%label.welcome" />
<JFXButton fx:id="buttonLoad" layoutX="87.0" layoutY="237.0" maxHeight="-Infinity" maxWidth="-Infinity" onAction="#loadGPXFile" styleClass="default-primary-color" text="%label.loadGPX">
<padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding>
<StackPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</StackPane.margin>
</JFXButton>
</StackPane>
<Spinner fx:id="spinnerHR" layoutX="124.0" layoutY="118.0" />
<Spinner fx:id="spinnerAge" layoutX="124.0" layoutY="150.0" />
<Text fx:id="textHR" layoutX="14.0" layoutY="137.0" strokeType="OUTSIDE" strokeWidth="0.0" text="%label.maxHR" />
<Text fx:id="textAge" layoutX="14.0" layoutY="169.0" strokeType="OUTSIDE" strokeWidth="0.0" text="%label.age" />
</AnchorPane>

View file

@ -26,6 +26,7 @@
app.extension=GPX data files
app.title=ESTRABA
error.file=Error loading file
label.age=Age
label.begin=Salida
label.cadence=Cadence
label.distance=Distance
@ -33,6 +34,7 @@ label.elevation=Elevation
label.end=Meta
label.hr=Heart rate
label.loadGPX=Load GPX file
label.maxHR=Max. heart rate
label.motivation=Welcome!
label.speed=Speed
label.welcome=Welcome!

View file

@ -26,13 +26,15 @@
app.extension=Arxius GPX
app.title=ESTRABA
error.file=Error
label.age=Edat
label.begin=Salida
label.cadence=Cadencia
label.distance=Distancia
label.elevation=Elevacion
label.end=Meta
label.hr=YOLO
label.hr=Pulsacions
label.loadGPX=Obrir arxiu GPX
label.maxHR=Max. pulsacions/min
label.motivation=\u00a1Benvinguts!
label.speed=Speed
label.welcome=Benvingut!

View file

@ -26,6 +26,7 @@
app.extension=Archivos de datos GPX
app.title=ESTRABA
error.file=Error al cargar el archivo
label.age=Edad
label.begin=Salida
label.cadence=Cadencia
label.distance=Distancia
@ -33,6 +34,7 @@ label.elevation=Elevacion
label.end=Meta
label.hr=Pulsaci\u00f3nes
label.loadGPX=Abrir archivo GPX
label.maxHR=Max. pulsaciones/min
label.motivation=\u00a1Bienvenido!
label.speed=Velocidad
label.welcome=¡Bienvenido!