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.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -20,6 +21,7 @@ import ch.qos.logback.classic.spi.StackTraceElementProxy;
|
|||
import ctbrec.event.EventBusHolder;
|
||||
import ctbrec.ui.controls.CustomMouseBehaviorContextMenu;
|
||||
import ctbrec.ui.controls.SearchBox;
|
||||
import ctbrec.ui.tabs.TabSelectionListener;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
|
@ -37,27 +39,36 @@ import javafx.scene.input.ContextMenuEvent;
|
|||
import javafx.scene.input.MouseEvent;
|
||||
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 SearchBox filter = new SearchBox();
|
||||
private TableView<LoggingEvent> table = new TableView<>();
|
||||
private ObservableList<LoggingEvent> history = FXCollections.observableList(Collections.synchronizedList(new LinkedList<>()));
|
||||
private ObservableList<LoggingEvent> filteredEvents = FXCollections.observableArrayList();
|
||||
private List<LoggingEvent> eventBuffer = new LinkedList<>();
|
||||
private DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||
private volatile boolean tabClosed = false;
|
||||
private volatile boolean tabSelected = false;
|
||||
private ContextMenu popup;
|
||||
private Object eventBustSubscriber = new Object() {
|
||||
@Subscribe
|
||||
public void publishLoggingEevent(LoggingEvent event) {
|
||||
if (!tabClosed) {
|
||||
Platform.runLater(() -> {
|
||||
history.add(event);
|
||||
if (history.size() > HISTORY_LENGTH - 1) {
|
||||
history.remove(0);
|
||||
if (tabSelected) {
|
||||
Platform.runLater(() -> {
|
||||
history.add(event);
|
||||
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() {
|
||||
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