From 76745aaac1da09eeac25b1cc3b1e323622d3eeac Mon Sep 17 00:00:00 2001 From: Linus Ahlin-Hamberg Date: Fri, 10 May 2019 21:25:07 +0200 Subject: [PATCH] Implement property for reload of push and database (make later work) --- .../uiProgram/DatabasLoderController.java | 46 ++++++++++++++-- src/main/java/uiProgram/PushaController.java | 53 ++++++++++++++++++- src/main/resources/LoadDatabasUi.fxml | 2 +- src/main/resources/PushTillSIdaUi.fxml | 16 ++++-- 4 files changed, 106 insertions(+), 11 deletions(-) diff --git a/src/main/java/uiProgram/DatabasLoderController.java b/src/main/java/uiProgram/DatabasLoderController.java index 8d25164..124aa48 100644 --- a/src/main/java/uiProgram/DatabasLoderController.java +++ b/src/main/java/uiProgram/DatabasLoderController.java @@ -1,17 +1,15 @@ package uiProgram; import java.io.File; +import java.util.function.UnaryOperator; import hjälpprogram.ReloadDatabasAutomatic; import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.RadioButton; -import javafx.scene.control.ToggleButton; -import javafx.scene.control.ToggleGroup; +import javafx.scene.control.*; import javafx.scene.text.Text; //import javafx.scene.control.ToggleGroup; -import javafx.scene.control.TextField; import javafx.stage.FileChooser; import loadDatabasParts.LoadDatabasInformation; import loadDatabasParts.ParseDatabasToTävling; @@ -35,6 +33,9 @@ public class DatabasLoderController implements LoadDatabasInformation { Button readDatabas; @FXML TextField databasURL; + + @FXML + TextField reloadIntervall; @FXML Text databasInfo; @@ -55,7 +56,36 @@ public void setMainUi(MainUi mainUi) { private void initialize() { on.setToggleGroup(onOfGrop); of.setToggleGroup(onOfGrop); + UnaryOperator filter = change -> { + String text = change.getText(); + + if (text.matches("[0-9]*")) { + return change; + } + + return null; + }; + TextFormatter textFormatter = new TextFormatter<>(filter); + reloadIntervall.setTextFormatter(textFormatter); } + +// @FXML +// protected void initialize() { +// UnaryOperator filter = change -> { +// String text = change.getText(); +// +// if (text.matches("[0-9]*")) { +// return change; +// } +// +// return null; +// }; +// TextFormatter textFormatter = new TextFormatter<>(filter); +// pushSecMellan.setTextFormatter(textFormatter); +// +// +// +// } /** * Handle datafilieShoser button @@ -115,6 +145,12 @@ private void loadDatabas(){ public void autoLoadPdfOn(){ System.out.println("load"); readDatabas.setDisable(true); + int seconds = Integer.parseInt(reloadIntervall.getText()); + if(seconds == 0){ + seconds = 10; + reloadIntervall.setText("10"); + } + rdb.setMilisecondsBetwenDataReading(seconds *1000);//transform to milliseconds rdb.setRuning(true); System.out.println("load2"); diff --git a/src/main/java/uiProgram/PushaController.java b/src/main/java/uiProgram/PushaController.java index 6caf69f..ee3acb8 100644 --- a/src/main/java/uiProgram/PushaController.java +++ b/src/main/java/uiProgram/PushaController.java @@ -13,11 +13,16 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.function.UnaryOperator; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; +import javax.annotation.Resources; + /** * @author ahlin */ @@ -32,6 +37,9 @@ public class PushaController { @FXML private TextField attTaBort; + + @FXML + private TextField pushSecMellan; @FXML private TextField competitionName; @@ -42,6 +50,9 @@ public class PushaController { @FXML private Button puschButton; + @FXML + private Button taBortKnapp; + // Reference to the main application @@ -51,7 +62,32 @@ public class PushaController { private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - /** + @FXML + protected void initialize() { + UnaryOperator filter = change -> { + String text = change.getText(); + + if (text.matches("[0-9]*")) { + return change; + } + + return null; + }; + TextFormatter textFormatter = new TextFormatter<>(filter); + pushSecMellan.setTextFormatter(textFormatter); + + PushInfo.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Object oldValue, + Object newValue) { + PushInfo.setScrollTop(Double.MAX_VALUE); //this will scroll to the bottom + //use Double.MIN_VALUE to scroll to the top + } + }); + + } + + /** * Is called by the main application to give a reference back to itself. * * @param mainApp @@ -79,14 +115,27 @@ public void run() { if(startStopPuschButton.getText().equalsIgnoreCase("Starta")) { executor = Executors.newScheduledThreadPool(1); - executor.scheduleAtFixedRate(puschRunnable, 0, 10, TimeUnit.SECONDS); + int seconds = Integer.parseInt(pushSecMellan.getText()); + if(seconds == 0) { + seconds = 10; + pushSecMellan.setText("10"); + } + pushSecMellan.setDisable(true); + executor.scheduleAtFixedRate(puschRunnable, 0, seconds, TimeUnit.SECONDS); startStopPuschButton.setText("Stop"); puschButton.setDisable(true); + taBortKnapp.setDisable(true); + competitionName.setDisable(true); + serverSokvag.setDisable(true); PushInfo.appendText("Startar automatiskt push"); }else { executor.shutdown(); startStopPuschButton.setText("Starta"); puschButton.setDisable(false); + pushSecMellan.setDisable(false); + taBortKnapp.setDisable(false); + competitionName.setDisable(false); + serverSokvag.setDisable(false); PushInfo.appendText("Stoppar automatiskt push"); } } diff --git a/src/main/resources/LoadDatabasUi.fxml b/src/main/resources/LoadDatabasUi.fxml index a480109..a4e8dbc 100644 --- a/src/main/resources/LoadDatabasUi.fxml +++ b/src/main/resources/LoadDatabasUi.fxml @@ -86,7 +86,7 @@ - + diff --git a/src/main/resources/PushTillSIdaUi.fxml b/src/main/resources/PushTillSIdaUi.fxml index cdc7d91..80c0509 100644 --- a/src/main/resources/PushTillSIdaUi.fxml +++ b/src/main/resources/PushTillSIdaUi.fxml @@ -11,7 +11,7 @@ - +
@@ -22,7 +22,7 @@
- +