Made ServerGui usable and prepared for 3.0

This commit is contained in:
ChococookieOS 2019-04-28 12:06:49 +02:00
parent 510cb9c295
commit ffdd3e6dee
6 changed files with 33 additions and 14 deletions

View File

@ -1,4 +1,4 @@
#Mon Apr 15 11:15:43 CEST 2019
#Sun Apr 28 11:53:19 CEST 2019
Load-File-on-startup=true
key2=44
key1=29

View File

@ -14,7 +14,7 @@ public class UpdateChecker {
public void requestServerData(){
try {
Socket socket = new Socket();
socket.connect(new InetSocketAddress(InetAddress.getByName(/*"cookiestudios.org"*/"localhost"), 9999), 2000);
socket.connect(new InetSocketAddress(InetAddress.getByName("cookiestudios.org"), 9999), 2000);
DataInputStream in = new DataInputStream(socket.getInputStream());
DataOutputStream out = new DataOutputStream(socket.getOutputStream());

View File

@ -0,0 +1,12 @@
package data;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class ServerTime {
public static String getTimestamp() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm");
LocalDateTime ldt = LocalDateTime.now();
return formatter.format(ldt);
}
}

View File

@ -6,13 +6,13 @@ import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import data.ServerData;
import scenes.LogScene;
public class ServerThread
implements Runnable {
private final int PORT = 9999;
public static float version = -1.0f;
LogScene display;
@ -36,10 +36,10 @@ implements Runnable {
out = new DataOutputStream(s.getOutputStream());
in = new DataInputStream(s.getInputStream());
String data = in.readUTF();
display.appendText(data);
display.appendText(data, data.split(";")[0]);
System.out.println(data);
out.writeUTF("VERSION="+version);
out.writeUTF("VERSION="+ServerData.version);
out.close();
in.close();

View File

@ -3,6 +3,7 @@ package scenes;
import java.util.Optional;
import data.ServerData;
import data.ServerTime;
import customNodes.LogTextArea;
import customNodes.NewUpdateButton;
import javafx.collections.FXCollections;
@ -14,6 +15,7 @@ import javafx.scene.chart.PieChart;
import javafx.scene.chart.PieChart.Data;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class LogScene extends AnchorPane{
@ -28,6 +30,11 @@ public class LogScene extends AnchorPane{
this.setPrefHeight(600);
this.setMaxHeight(600);
Text versionText = new Text();
versionText.setLayoutX(10);
versionText.setLayoutY(30);
versionText.setText("Current version: "+ServerData.version);
mNewUpdate = new NewUpdateButton("New update");
mNewUpdate.setOnAction(new EventHandler<ActionEvent>() {
@ -41,6 +48,7 @@ public class LogScene extends AnchorPane{
Optional<String> result = dialog.showAndWait();
if (result.isPresent()){
ServerData.version = Float.parseFloat(result.get());
versionText.setText("Current version: "+ServerData.version);
}
}
});
@ -48,30 +56,29 @@ public class LogScene extends AnchorPane{
mLogView = new LogTextArea();
pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Win 7", 0),
new PieChart.Data("Win 10", 0),
new PieChart.Data("Windows 7", 0),
new PieChart.Data("Windows 10", 0),
new PieChart.Data("Linux", 0));
final PieChart chart = new PieChart(pieChartData);
chart.setLayoutX(500);
chart.setLayoutY(35);
chart.setMaxHeight(200);
chart.setMaxHeight(150);
chart.setMaxWidth(300);
chart.setLabelsVisible(true);
chart.setLegendSide(Side.RIGHT);
chart.setLabelLineLength(10);
chart.setStyle("-fx-font-size: 8pt");
this.getChildren().add(mNewUpdate);
this.getChildren().add(mLogView);
this.getChildren().add(chart);
this.getChildren().add(versionText);
}
public void appendText(String text) {
public void appendText(String text, String osName) {
for(Data d : pieChartData) {
if(d.getName().equals("Linux")) {
if(d.getName().equals(osName)) {
d.setPieValue(d.getPieValue()+1);
}
}
mLogView.appendText(text+"\n");
mLogView.appendText(ServerTime.getTimestamp()+" "+text+"\n");
}