diff --git a/src/main/java/es/kauron/estraba/controller/SplashController.java b/src/main/java/es/kauron/estraba/controller/SplashController.java index e09e97f..19a7642 100644 --- a/src/main/java/es/kauron/estraba/controller/SplashController.java +++ b/src/main/java/es/kauron/estraba/controller/SplashController.java @@ -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 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,65 +165,46 @@ public class SplashController implements Initializable{ } }); - Platform.runLater(() -> root.setOnDragOver(e -> { - Dragboard db = e.getDragboard(); - if (db.hasFiles()) { - e.acceptTransferModes(TransferMode.COPY); - } else { + Platform.runLater(() -> { + root.setOnDragOver(e -> { + Dragboard db = e.getDragboard(); + if (db.hasFiles()) { + e.acceptTransferModes(TransferMode.COPY); + } else { + e.consume(); + } + }); + root.setOnDragDropped(e -> { + Dragboard db = e.getDragboard(); + boolean success = false; + if (db.hasFiles()) { + success = true; + loadGPXFile(db.getFiles().get(0).getAbsoluteFile()); + } + e.setDropCompleted(success); e.consume(); - } - })); - - // Dropping over surface - Platform.runLater(() -> root.setOnDragDropped(e -> { - Dragboard db = e.getDragboard(); - boolean success = false; - if (db.hasFiles()) { - success = true; - loadGPXFile(db.getFiles().get(0).getAbsoluteFile()); - } - e.setDropCompleted(success); - e.consume(); - })); + }); + }); snackbar.registerSnackbarContainer(root); + 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))); } 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); } - - private int showHRDialog() { - Dialog 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 spinnerAge = new Spinner<>(18, 99, 25, 1); - Spinner spinnerHR = new Spinner<>(60, 202, 180, 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; - } } diff --git a/src/main/resources/es/kauron/estraba/fxml/Splash.fxml b/src/main/resources/es/kauron/estraba/fxml/Splash.fxml index fded0bd..7be32ac 100644 --- a/src/main/resources/es/kauron/estraba/fxml/Splash.fxml +++ b/src/main/resources/es/kauron/estraba/fxml/Splash.fxml @@ -29,24 +29,23 @@ + - - + + + + - diff --git a/src/main/resources/general.properties b/src/main/resources/general.properties index 4156188..d0c31b1 100644 --- a/src/main/resources/general.properties +++ b/src/main/resources/general.properties @@ -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! diff --git a/src/main/resources/general_ca.properties b/src/main/resources/general_ca.properties index 5cb615a..6c05642 100644 --- a/src/main/resources/general_ca.properties +++ b/src/main/resources/general_ca.properties @@ -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! diff --git a/src/main/resources/general_es.properties b/src/main/resources/general_es.properties index c072112..6d68538 100644 --- a/src/main/resources/general_es.properties +++ b/src/main/resources/general_es.properties @@ -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!