Skip to content

Commit

Permalink
Implement property for reload of push and database (make later work)
Browse files Browse the repository at this point in the history
  • Loading branch information
flaime authored and Linus Ahlin-Hamberg committed May 10, 2019
1 parent 4642df6 commit 76745aa
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 11 deletions.
46 changes: 41 additions & 5 deletions src/main/java/uiProgram/DatabasLoderController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -35,6 +33,9 @@ public class DatabasLoderController implements LoadDatabasInformation {
Button readDatabas;
@FXML
TextField databasURL;

@FXML
TextField reloadIntervall;

@FXML
Text databasInfo;
Expand All @@ -55,7 +56,36 @@ public void setMainUi(MainUi mainUi) {
private void initialize() {
on.setToggleGroup(onOfGrop);
of.setToggleGroup(onOfGrop);
UnaryOperator<TextFormatter.Change> filter = change -> {
String text = change.getText();

if (text.matches("[0-9]*")) {
return change;
}

return null;
};
TextFormatter<String> textFormatter = new TextFormatter<>(filter);
reloadIntervall.setTextFormatter(textFormatter);
}

// @FXML
// protected void initialize() {
// UnaryOperator<TextFormatter.Change> filter = change -> {
// String text = change.getText();
//
// if (text.matches("[0-9]*")) {
// return change;
// }
//
// return null;
// };
// TextFormatter<String> textFormatter = new TextFormatter<>(filter);
// pushSecMellan.setTextFormatter(textFormatter);
//
//
//
// }

/**
* Handle datafilieShoser button
Expand Down Expand Up @@ -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");

Expand Down
53 changes: 51 additions & 2 deletions src/main/java/uiProgram/PushaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -32,6 +37,9 @@ public class PushaController {

@FXML
private TextField attTaBort;

@FXML
private TextField pushSecMellan;

@FXML
private TextField competitionName;
Expand All @@ -42,6 +50,9 @@ public class PushaController {
@FXML
private Button puschButton;

@FXML
private Button taBortKnapp;



// Reference to the main application
Expand All @@ -51,7 +62,32 @@ public class PushaController {

private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

/**
@FXML
protected void initialize() {
UnaryOperator<TextFormatter.Change> filter = change -> {
String text = change.getText();

if (text.matches("[0-9]*")) {
return change;
}

return null;
};
TextFormatter<String> textFormatter = new TextFormatter<>(filter);
pushSecMellan.setTextFormatter(textFormatter);

PushInfo.textProperty().addListener(new ChangeListener<Object>() {
@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
Expand Down Expand Up @@ -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");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/LoadDatabasUi.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<HBox alignment="CENTER_RIGHT">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Reload intervall:" />
<TextField editable="false" prefWidth="45.0" text="4">
<TextField fx:id="reloadIntervall" prefWidth="45.0" text="4">
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
Expand Down
16 changes: 13 additions & 3 deletions src/main/resources/PushTillSIdaUi.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<AnchorPane prefHeight="250.0" prefWidth="500.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uiProgram.PushaController">
<AnchorPane prefHeight="250.0" prefWidth="570.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="uiProgram.PushaController">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>
Expand All @@ -22,7 +22,7 @@
</TextArea>
</center>
<top>
<HBox prefWidth="200.0" spacing="10.0" BorderPane.alignment="CENTER">
<HBox prefWidth="230.0" spacing="10.0" BorderPane.alignment="CENTER">
<children>
<Label text="Server sökväg" />
<TextField fx:id="serverSokvag" prefWidth="360.0" text="http://localhost:8080" />
Expand All @@ -37,6 +37,16 @@
<children>
<HBox>
<children>
<TextField fx:id="pushSecMellan" prefWidth="60.0" text="10">
<HBox.margin>
<Insets left="10.0" top="10.0" />
</HBox.margin>
</TextField>
<Label text="sec/pusch">
<HBox.margin>
<Insets left="7.0" top="15.0" />
</HBox.margin>
</Label>
<ButtonBar>
<buttons>
<Button fx:id="startStopPuschButton" mnemonicParsing="false" onAction="#startStopKnapp" text="Starta" />
Expand All @@ -56,7 +66,7 @@
<Insets left="10.0" right="10.0" top="10.0" />
</HBox.margin>
</TextField>
<Button mnemonicParsing="false" onAction="#handleTaBort" text="Ta bort">
<Button fx:id="taBortKnapp" mnemonicParsing="false" onAction="#handleTaBort" text="Ta bort">
<HBox.margin>
<Insets top="10.0" />
</HBox.margin>
Expand Down

0 comments on commit 76745aa

Please sign in to comment.