forked from j62/ctbrec
Only update the logging tab if it is selected
This commit is contained in:
parent
bab8392430
commit
c44749ac16
|
@ -5,6 +5,7 @@ import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -20,6 +21,7 @@ import ch.qos.logback.classic.spi.StackTraceElementProxy;
|
||||||
import ctbrec.event.EventBusHolder;
|
import ctbrec.event.EventBusHolder;
|
||||||
import ctbrec.ui.controls.CustomMouseBehaviorContextMenu;
|
import ctbrec.ui.controls.CustomMouseBehaviorContextMenu;
|
||||||
import ctbrec.ui.controls.SearchBox;
|
import ctbrec.ui.controls.SearchBox;
|
||||||
|
import ctbrec.ui.tabs.TabSelectionListener;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
|
@ -37,27 +39,36 @@ import javafx.scene.input.ContextMenuEvent;
|
||||||
import javafx.scene.input.MouseEvent;
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
|
|
||||||
public class LoggingTab extends Tab {
|
public class LoggingTab extends Tab implements TabSelectionListener {
|
||||||
|
|
||||||
private static final int HISTORY_LENGTH = 10_000;
|
private static final int HISTORY_LENGTH = 10_000;
|
||||||
private SearchBox filter = new SearchBox();
|
private SearchBox filter = new SearchBox();
|
||||||
private TableView<LoggingEvent> table = new TableView<>();
|
private TableView<LoggingEvent> table = new TableView<>();
|
||||||
private ObservableList<LoggingEvent> history = FXCollections.observableList(Collections.synchronizedList(new LinkedList<>()));
|
private ObservableList<LoggingEvent> history = FXCollections.observableList(Collections.synchronizedList(new LinkedList<>()));
|
||||||
private ObservableList<LoggingEvent> filteredEvents = FXCollections.observableArrayList();
|
private ObservableList<LoggingEvent> filteredEvents = FXCollections.observableArrayList();
|
||||||
|
private List<LoggingEvent> eventBuffer = new LinkedList<>();
|
||||||
private DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
private DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||||
private volatile boolean tabClosed = false;
|
private volatile boolean tabClosed = false;
|
||||||
|
private volatile boolean tabSelected = false;
|
||||||
private ContextMenu popup;
|
private ContextMenu popup;
|
||||||
private Object eventBustSubscriber = new Object() {
|
private Object eventBustSubscriber = new Object() {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void publishLoggingEevent(LoggingEvent event) {
|
public void publishLoggingEevent(LoggingEvent event) {
|
||||||
if (!tabClosed) {
|
if (!tabClosed) {
|
||||||
Platform.runLater(() -> {
|
if (tabSelected) {
|
||||||
history.add(event);
|
Platform.runLater(() -> {
|
||||||
if (history.size() > HISTORY_LENGTH - 1) {
|
history.add(event);
|
||||||
history.remove(0);
|
if (history.size() > HISTORY_LENGTH - 1) {
|
||||||
|
history.remove(0);
|
||||||
|
}
|
||||||
|
filter();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
eventBuffer.add(event);
|
||||||
|
if (eventBuffer.size() > HISTORY_LENGTH - 1) {
|
||||||
|
eventBuffer.remove(0);
|
||||||
}
|
}
|
||||||
filter();
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -200,4 +211,20 @@ public class LoggingTab extends Tab {
|
||||||
private void subscribeToEventBus() {
|
private void subscribeToEventBus() {
|
||||||
EventBusHolder.BUS.register(eventBustSubscriber);
|
EventBusHolder.BUS.register(eventBustSubscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void selected() {
|
||||||
|
history.addAll(eventBuffer);
|
||||||
|
tabSelected = true;
|
||||||
|
while (history.size() > HISTORY_LENGTH - 1) {
|
||||||
|
history.remove(0);
|
||||||
|
}
|
||||||
|
filter();
|
||||||
|
eventBuffer.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deselected() {
|
||||||
|
tabSelected = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue