fix bug where first packet(s) would not show in logger, HConnection needs reimplementation later

This commit is contained in:
sirjonasxx 2018-11-05 22:59:22 +01:00
parent ca2d750e43
commit 4154e935bc
3 changed files with 71 additions and 32 deletions

View File

@ -4,7 +4,7 @@ import java.io.PrintStream;
import java.util.prefs.Preferences;
/**
* Created by Jeunez on 5/11/2018.
* Created by Jonas on 5/11/2018.
*/
public class AdminValidator {

View File

@ -2,12 +2,11 @@ package gearth.ui;
import gearth.protocol.HPacket;
import gearth.ui.logger.loggerdisplays.PacketLogger;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.Initializable;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Label;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import org.fxmisc.flowless.VirtualizedScrollPane;
@ -15,10 +14,7 @@ import org.fxmisc.richtext.StyleClassedTextArea;
import org.fxmisc.richtext.model.StyleSpansBuilder;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ResourceBundle;
import java.util.*;
public class UiLoggerController implements Initializable {
public FlowPane flowPane;
@ -38,6 +34,9 @@ public class UiLoggerController implements Initializable {
private boolean displayStructure = true;
private boolean autoScroll = true;
private volatile boolean initialized = false;
private final List<Element> appendLater = new ArrayList<>();
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
area = new StyleClassedTextArea();
@ -46,6 +45,15 @@ public class UiLoggerController implements Initializable {
VirtualizedScrollPane<StyleClassedTextArea> vsPane = new VirtualizedScrollPane<>(area);
borderPane.setCenter(vsPane);
synchronized (appendLater) {
initialized = true;
if (!appendLater.isEmpty()) {
appendLog(appendLater);
}
}
}
public void appendMessage(HPacket packet, int types) {
@ -83,10 +91,20 @@ public class UiLoggerController implements Initializable {
elements.add(new Element("\n" + expr, "structure"));
elements.add(new Element("\n--------------------\n", ""));
AppendLog(elements);
synchronized (appendLater) {
if (initialized) {
appendLog(elements);
}
else {
appendLater.addAll(elements);
}
}
private void AppendLog(ArrayList<Element> elements) {
}
private synchronized void appendLog(List<Element> elements) {
Platform.runLater(() -> {
StringBuilder sb = new StringBuilder();
StyleSpansBuilder<Collection<String>> styleSpansBuilder = new StyleSpansBuilder<>(0);
@ -97,13 +115,14 @@ public class UiLoggerController implements Initializable {
int oldLen = area.getLength();
area.appendText(sb.toString());
// System.out.println(sb.toString());
area.setStyleSpans(oldLen, styleSpansBuilder.create());
if (autoScroll) {
area.moveTo(area.getLength());
area.requestFollowCaret();
}
});
}
public void toggleViewIncoming() {

View File

@ -2,24 +2,20 @@ package gearth.ui.logger.loggerdisplays;
import gearth.protocol.HPacket;
import gearth.ui.UiLoggerController;
import javafx.application.Platform;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import javafx.stage.Modality;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class UiLogger implements PacketLogger {
private Stage stage;
private UiLoggerController controller;
private UiLoggerController controller = null;
@Override
public void start() {
@ -27,7 +23,13 @@ public class UiLogger implements PacketLogger {
try {
Parent root = loader.load();
synchronized (appendLater) {
controller = loader.getController();
for (Elem elem : appendLater) {
controller.appendMessage(elem.packet, elem.types);
}
}
stage = new Stage();
stage.setTitle("G-Earth | Packet Logger");
stage.initModality(Modality.NONE);
@ -78,9 +80,27 @@ public class UiLogger implements PacketLogger {
//Platform.runLater(() -> controller.appendSplitLine());
}
private class Elem {
HPacket packet;
int types;
Elem(HPacket packet, int types) {
this.packet = packet;
this.types = types;
}
}
private final List<Elem> appendLater = new ArrayList<>();
@Override
public void appendMessage(HPacket packet, int types) {
Platform.runLater(() -> controller.appendMessage(packet, types));
synchronized (appendLater) {
if (controller == null) {
appendLater.add(new Elem(packet, types));
}
else {
controller.appendMessage(packet, types);
}
}
}
@Override