From 8b3cfd26704b3fc2c98ff0c3d944c81ed7992462 Mon Sep 17 00:00:00 2001 From: Obsidiam Date: Mon, 14 Aug 2017 23:58:27 +0200 Subject: [PATCH] Layout changed, disconnection improved, view update improved, baudrate meter added. --- src/main/java/abstracts/LocalEnvironment.java | 2 - .../java/com/neology/net/BaudrateMeter.java | 2 + src/main/java/com/neology/net/Connection.java | 4 + src/main/java/com/neology/net/Transport.java | 16 +- .../com/neology/todosaver/FXMLController.java | 155 +++++++++++------- 5 files changed, 111 insertions(+), 68 deletions(-) diff --git a/src/main/java/abstracts/LocalEnvironment.java b/src/main/java/abstracts/LocalEnvironment.java index 340d72e..0a3ae45 100644 --- a/src/main/java/abstracts/LocalEnvironment.java +++ b/src/main/java/abstracts/LocalEnvironment.java @@ -5,12 +5,10 @@ */ package abstracts; -import com.neology.net.NetController; import com.neology.xml.XMLController; import enums.Local; import java.io.File; import java.io.IOException; -import java.net.Socket; import java.nio.file.Paths; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/main/java/com/neology/net/BaudrateMeter.java b/src/main/java/com/neology/net/BaudrateMeter.java index 1034933..8b47224 100644 --- a/src/main/java/com/neology/net/BaudrateMeter.java +++ b/src/main/java/com/neology/net/BaudrateMeter.java @@ -52,6 +52,7 @@ public void startMeasuringCycle() { public void stopMeasuringCycle() { measure = false; long ms = System.currentTimeMillis() - start; + System.out.println("MS: "+ms); if (0 == ms || bytes < 100) return; // skip with too small portion of data double bps = bytes * 8. / (ms / 1000.); // double bpms = bytes * 8. / ms; @@ -61,5 +62,6 @@ public void stopMeasuringCycle() { // exponential moving-average smoothing ema = ALPHA * bps + (1. - ALPHA) * (0. == ema ? bps : ema); bytes = 0; + } } diff --git a/src/main/java/com/neology/net/Connection.java b/src/main/java/com/neology/net/Connection.java index cd2ecc6..de4db3e 100644 --- a/src/main/java/com/neology/net/Connection.java +++ b/src/main/java/com/neology/net/Connection.java @@ -45,6 +45,10 @@ public boolean isConnected(){ return T.isConnected(); } + public boolean wasConnected(){ + return T.wasConnected(); + } + public Transport getTranportInstance(){ return T; } diff --git a/src/main/java/com/neology/net/Transport.java b/src/main/java/com/neology/net/Transport.java index 67373f9..b917805 100644 --- a/src/main/java/com/neology/net/Transport.java +++ b/src/main/java/com/neology/net/Transport.java @@ -40,16 +40,11 @@ public class Transport { DataOutputStream os; InputStream origIs; OutputStream origOs; - Socket s; + //Socket s; private boolean WAS_CONNECTED = false; private BaudrateMeter baudrateMeter; private String IP; - - public Transport(Socket socket) throws IOException { - this(socket.getInputStream(), socket.getOutputStream()); - this.s = socket; - IP = socket.getInetAddress().getHostAddress(); - } + public Transport(InputStream is) { this(is, null); @@ -82,7 +77,6 @@ void release() { public void close() throws IOException{ release(); - s.close(); IP = ""; } @@ -102,6 +96,10 @@ public void setBaudrateMeter(BaudrateMeter baudrateMeter) { this.baudrateMeter = baudrateMeter; } + public BaudrateMeter getBaudrateMeter(){ + return this.baudrateMeter; + } + public int readUInt8() throws TransportException { return readByte() & 0x0ff; } @@ -355,7 +353,7 @@ public void setIp(String ip){ } public boolean isConnected() { - return s.isConnected(); + return true ? origIs != null && origOs != null : false; } public boolean wasConnected() { diff --git a/src/main/java/com/neology/todosaver/FXMLController.java b/src/main/java/com/neology/todosaver/FXMLController.java index 9e0ecb6..4ca7992 100644 --- a/src/main/java/com/neology/todosaver/FXMLController.java +++ b/src/main/java/com/neology/todosaver/FXMLController.java @@ -20,7 +20,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -40,10 +39,9 @@ import javafx.collections.ObservableList; import javafx.concurrent.Service; import javafx.concurrent.Task; -import javafx.event.EventHandler; +import javafx.event.EventType; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.geometry.Pos; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; @@ -51,7 +49,6 @@ import javafx.scene.control.ListCell; import javafx.scene.control.ListView; import javafx.scene.control.PasswordField; -import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.scene.text.TextAlignment; @@ -89,10 +86,11 @@ public String preparePath(String path) { protected boolean IS_CONNECTED = false; private int INDEX = 0; private HashMap IMAGES = new HashMap<>(); - + private ArrayList DATA = new ArrayList<>(); private HashMap THREADS = new HashMap<>(); final Executor EXEC = Executors.newSingleThreadExecutor(); ObservableList