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

View file

@ -29,24 +29,23 @@
<?import com.jfoenix.controls.JFXSpinner?> <?import com.jfoenix.controls.JFXSpinner?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" <?import javafx.scene.text.Text?>
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" <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">
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 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> </ImageView>
<JFXSpinner fx:id="spinner" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> <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" /> <Label fx:id="labelWelcome" alignment="CENTER" layoutX="101.0" layoutY="91.0" text="%label.welcome" />
<StackPane layoutX="-1.0" layoutY="251.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"> <JFXButton fx:id="buttonLoad" layoutX="87.0" layoutY="237.0" maxHeight="-Infinity" maxWidth="-Infinity" onAction="#loadGPXFile" styleClass="default-primary-color" text="%label.loadGPX">
<JFXButton fx:id="buttonLoad" maxHeight="-Infinity" maxWidth="-Infinity" onAction="#loadGPXFile" styleClass="accent-color" text="%label.loadGPX">
<padding> <padding>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" /> <Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</padding> </padding>
<StackPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</StackPane.margin>
</JFXButton> </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> </AnchorPane>

View file

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

View file

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

View file

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