Improved Backend

This commit is contained in:
ChococookieOS 2019-04-28 11:19:53 +02:00
parent c4ed32689d
commit 02e63e14c0
29 changed files with 175 additions and 42 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
#Mon Apr 15 11:05:55 CEST 2019 #Thu Apr 18 14:02:07 CEST 2019
Load-File-on-startup=true Load-File-on-startup=true
key2=44 key2=44
key1=29 key1=29

View File

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

View File

@ -0,0 +1,25 @@
package customNodes;
import javafx.geometry.Insets;
import javafx.scene.control.TextArea;
public class LogTextArea extends TextArea{
private final int WIDTH = 500;
private final int HEIGHT = 515;
public LogTextArea() {
this.setLayoutX(25);
this.setLayoutY(65);
this.setEditable(false);
this.setMinWidth(WIDTH);
this.setMaxWidth(WIDTH);
this.setPadding(new Insets(0,0,0,-10));
this.setMinHeight(HEIGHT);
this.setMaxHeight(HEIGHT);
this.setStyle("-fx-background-color: transparent;"
+ "-fx-control-inner-background: white;"
+ "-fx-text-fill: black");
}
}

View File

@ -0,0 +1,16 @@
package customNodes;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
public class NewUpdateButton extends Button{
public NewUpdateButton(String text) {
this.setText(text);
this.setLayoutX(550);
this.setLayoutY(400);
this.setTextFill(Color.WHITE);
this.setStyle("-fx-background-color: blue");
}
}

View File

@ -0,0 +1,5 @@
package data;
public class ServerData {
public static float version = 0.0f;
}

View File

@ -1,20 +1,26 @@
package run; package network;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import run.Start;
import scenes.LogScene;
public class ServerThread public class ServerThread
implements Runnable { implements Runnable {
int PORT;
public ServerThread(int port) { private final int PORT = 9999;
this.PORT = port; public static float version = -1.0f;
LogScene display;
public ServerThread(LogScene scene) {
display = scene;
} }
ServerSocket ses; ServerSocket ses;
Socket s; Socket s;
DataOutputStream out; DataOutputStream out;
@ -29,8 +35,11 @@ implements Runnable {
System.out.println("Connected with: " + s.getInetAddress()); System.out.println("Connected with: " + s.getInetAddress());
out = new DataOutputStream(s.getOutputStream()); out = new DataOutputStream(s.getOutputStream());
in = new DataInputStream(s.getInputStream()); in = new DataInputStream(s.getInputStream());
System.out.println(in.readUTF()); String data = in.readUTF();
out.writeUTF("VERSION="+Start.version); display.appendText(data);
System.out.println(data);
out.writeUTF("VERSION="+version);
out.close(); out.close();
in.close(); in.close();

View File

@ -1,23 +1,12 @@
package run; package run;
import javax.swing.JOptionPane; import javafx.application.Application;
import run.ServerThread; import stages.AppStage;
import run.UpdateThread;
public class Start { public class Start {
public static float version = -1.0f;
private static final int PORT = 9999;
public static void main(String[] args) { public static void main(String[] args) {
Application.launch(AppStage.class);
version = Float.parseFloat(JOptionPane.showInputDialog("QuickLaunch version:"));
Thread ut = new Thread(new UpdateThread());
ut.start();
System.out.println("Update thread started");
Thread st = new Thread(new ServerThread(PORT));
st.start();
System.out.println("Server listening");
} }
} }

View File

@ -1,14 +0,0 @@
package run;
import javax.swing.JOptionPane;
import run.Start;
public class UpdateThread
implements Runnable {
@Override
public void run() {
do {
Start.version = Float.parseFloat(JOptionPane.showInputDialog("QuickLaunch version (" + Start.version + "): "));
} while (true);
}
}

View File

@ -0,0 +1,78 @@
package scenes;
import java.util.Optional;
import data.ServerData;
import customNodes.LogTextArea;
import customNodes.NewUpdateButton;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Side;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.PieChart.Data;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class LogScene extends AnchorPane{
private NewUpdateButton mNewUpdate;
private LogTextArea mLogView;
private ObservableList<PieChart.Data> pieChartData;
public LogScene(Stage primaryStage) {
this.setPrefWidth(800);
this.setPrefHeight(600);
this.setMaxHeight(600);
mNewUpdate = new NewUpdateButton("New update");
mNewUpdate.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
TextInputDialog dialog = new TextInputDialog();
dialog.setTitle("Create new update");
dialog.setHeaderText("Realese new Update");
dialog.setContentText("New version:");
Optional<String> result = dialog.showAndWait();
if (result.isPresent()){
ServerData.version = Float.parseFloat(result.get());
}
}
});
mLogView = new LogTextArea();
pieChartData =
FXCollections.observableArrayList(
new PieChart.Data("Win 7", 0),
new PieChart.Data("Win 10", 0),
new PieChart.Data("Linux", 0));
final PieChart chart = new PieChart(pieChartData);
chart.setLayoutX(500);
chart.setLayoutY(35);
chart.setMaxHeight(200);
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);
}
public void appendText(String text) {
for(Data d : pieChartData) {
if(d.getName().equals("Linux")) {
d.setPieValue(d.getPieValue()+1);
}
}
mLogView.appendText(text+"\n");
}
}

View File

@ -0,0 +1,25 @@
package stages;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import network.ServerThread;
import scenes.LogScene;
public class AppStage extends Application{
public void start(Stage primaryStage) throws Exception {
primaryStage.setOnCloseRequest(event -> {
System.exit(0);
});
LogScene ls = new LogScene(primaryStage);
Thread st = new Thread(new ServerThread(ls));
st.start();
primaryStage.setScene(new Scene(ls));
primaryStage.setResizable(false);
primaryStage.show();
}
}