mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
improve performance and clarity of next and previous scroll actions
This commit is contained in:
parent
c3bd285bc2
commit
025d9d156b
@ -19,7 +19,6 @@
|
|||||||
package org.sleuthkit.autopsy.timeline.ui.listvew;
|
package org.sleuthkit.autopsy.timeline.ui.listvew;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
@ -43,8 +42,8 @@ import java.util.stream.Collectors;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.Observable;
|
import javafx.beans.Observable;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
|
import javafx.beans.binding.IntegerBinding;
|
||||||
import javafx.beans.binding.StringBinding;
|
import javafx.beans.binding.StringBinding;
|
||||||
import javafx.beans.property.ReadOnlyIntegerProperty;
|
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
@ -74,7 +73,6 @@ import javafx.scene.layout.VBox;
|
|||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.controlsfx.control.Notifications;
|
import org.controlsfx.control.Notifications;
|
||||||
import org.controlsfx.control.action.ActionUtils;
|
import org.controlsfx.control.action.ActionUtils;
|
||||||
@ -124,10 +122,6 @@ class ListTimeline extends BorderPane {
|
|||||||
ChronoField.MINUTE_OF_HOUR,
|
ChronoField.MINUTE_OF_HOUR,
|
||||||
ChronoField.SECOND_OF_MINUTE);
|
ChronoField.SECOND_OF_MINUTE);
|
||||||
|
|
||||||
private static ZonedDateTime getZonedDateTimeFromEvent(CombinedEvent combinedEvent, ZoneId timeZoneID) {
|
|
||||||
return Instant.ofEpochMilli(combinedEvent.getStartMillis()).atZone(timeZoneID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private HBox navControls;
|
private HBox navControls;
|
||||||
|
|
||||||
@ -320,11 +314,9 @@ class ListTimeline extends BorderPane {
|
|||||||
|
|
||||||
private void scrollToAndFocus(Integer index) {
|
private void scrollToAndFocus(Integer index) {
|
||||||
table.requestFocus();
|
table.requestFocus();
|
||||||
|
|
||||||
if (visibleEvents.contains(table.getItems().get(index)) == false) {
|
if (visibleEvents.contains(table.getItems().get(index)) == false) {
|
||||||
table.scrollTo(index);
|
table.scrollTo(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.getFocusModel().focus(index);
|
table.getFocusModel().focus(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,78 +676,95 @@ class ListTimeline extends BorderPane {
|
|||||||
|
|
||||||
private class ScrollToLast extends org.controlsfx.control.action.Action {
|
private class ScrollToLast extends org.controlsfx.control.action.Action {
|
||||||
|
|
||||||
public ScrollToLast() {
|
ScrollToLast() {
|
||||||
super("", actionEvent -> scrollToAndFocus(table.getItems().size() - 1));
|
super("", actionEvent -> scrollToAndFocus(table.getItems().size() - 1));
|
||||||
setGraphic(new ImageView(LAST));
|
setGraphic(new ImageView(LAST));
|
||||||
ReadOnlyIntegerProperty focusedIndexProperty = table.getFocusModel().focusedIndexProperty();
|
IntegerBinding size = Bindings.size(table.getItems());
|
||||||
disabledProperty().bind(focusedIndexProperty.isEqualTo(-1)
|
disabledProperty().bind(size.isEqualTo(0).or(
|
||||||
.or(focusedIndexProperty.greaterThanOrEqualTo(Bindings.size(table.getItems()).subtract(1))));
|
table.getFocusModel().focusedIndexProperty().greaterThanOrEqualTo(size.subtract(1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScrollToNext extends org.controlsfx.control.action.Action {
|
private class ScrollToNext extends org.controlsfx.control.action.Action {
|
||||||
|
|
||||||
public ScrollToNext() {
|
ScrollToNext() {
|
||||||
super("", actionEvent -> {
|
super("", actionEvent -> {
|
||||||
|
|
||||||
ChronoField selectedChronoField = scrollInrementComboBox.getSelectionModel().getSelectedItem();
|
ChronoField selectedChronoField = scrollInrementComboBox.getSelectionModel().getSelectedItem();
|
||||||
ZoneId timeZoneID = TimeLineController.getTimeZoneID();
|
ZoneId timeZoneID = TimeLineController.getTimeZoneID();
|
||||||
TemporalUnit selectedUnit = selectedChronoField.getBaseUnit();
|
TemporalUnit selectedUnit = selectedChronoField.getBaseUnit();
|
||||||
|
|
||||||
|
int focusedIndex = table.getFocusModel().getFocusedIndex();
|
||||||
CombinedEvent focusedItem = table.getFocusModel().getFocusedItem();
|
CombinedEvent focusedItem = table.getFocusModel().getFocusedItem();
|
||||||
|
if (-1 == focusedIndex || null == focusedItem) {
|
||||||
|
focusedItem = visibleEvents.first();
|
||||||
|
focusedIndex = table.getItems().indexOf(focusedItem);
|
||||||
|
}
|
||||||
|
|
||||||
ZonedDateTime nextDateTime = getZonedDateTimeFromEvent(defaultIfNull(focusedItem, visibleEvents.first()), timeZoneID).plus(1, selectedUnit);//
|
ZonedDateTime focusedDateTime = Instant.ofEpochMilli(focusedItem.getStartMillis()).atZone(timeZoneID);
|
||||||
|
ZonedDateTime nextDateTime = focusedDateTime.plus(1, selectedUnit);//
|
||||||
for (ChronoField field : SCROLL_BY_UNITS) {
|
for (ChronoField field : SCROLL_BY_UNITS) {
|
||||||
if (field.getBaseUnit().getDuration().compareTo(selectedUnit.getDuration()) < 0) {
|
if (field.getBaseUnit().getDuration().compareTo(selectedUnit.getDuration()) < 0) {
|
||||||
nextDateTime = nextDateTime.with(field, field.rangeRefinedBy(nextDateTime).getMinimum());//
|
nextDateTime = nextDateTime.with(field, field.rangeRefinedBy(nextDateTime).getMinimum());//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long nextMillis = nextDateTime.toInstant().toEpochMilli();
|
||||||
|
|
||||||
final ZonedDateTime fzdt = nextDateTime;
|
int nextIndex = table.getItems().size() - 1;
|
||||||
|
for (int i = focusedIndex; i < table.getItems().size(); i++) {
|
||||||
scrollToAndFocus(table.getItems()//
|
if (table.getItems().get(i).getStartMillis() >= nextMillis) {
|
||||||
.stream()
|
nextIndex = i;
|
||||||
.filter(combinedEvent -> getZonedDateTimeFromEvent(combinedEvent, timeZoneID).isAfter(fzdt))//
|
break;
|
||||||
.findFirst()
|
}
|
||||||
.map(table.getItems()::indexOf)
|
}
|
||||||
.orElse(table.getItems().size() - 1));
|
scrollToAndFocus(nextIndex);
|
||||||
});
|
});
|
||||||
setGraphic(new ImageView(NEXT));
|
setGraphic(new ImageView(NEXT));
|
||||||
ReadOnlyIntegerProperty focusedIndexProperty = table.getFocusModel().focusedIndexProperty();
|
IntegerBinding size = Bindings.size(table.getItems());
|
||||||
disabledProperty().bind(focusedIndexProperty.isEqualTo(-1)
|
disabledProperty().bind(size.isEqualTo(0).or(
|
||||||
.or(focusedIndexProperty.greaterThanOrEqualTo(Bindings.size(table.getItems()).subtract(1))));
|
table.getFocusModel().focusedIndexProperty().greaterThanOrEqualTo(size.subtract(1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScrollToPrevious extends org.controlsfx.control.action.Action {
|
private class ScrollToPrevious extends org.controlsfx.control.action.Action {
|
||||||
|
|
||||||
public ScrollToPrevious() {
|
ScrollToPrevious() {
|
||||||
super("", actionEvent -> {
|
super("", actionEvent -> {
|
||||||
ZoneId timeZoneID = TimeLineController.getTimeZoneID();
|
ZoneId timeZoneID = TimeLineController.getTimeZoneID();
|
||||||
ChronoField selectedChronoField = scrollInrementComboBox.getSelectionModel().getSelectedItem();
|
ChronoField selectedChronoField = scrollInrementComboBox.getSelectionModel().getSelectedItem();
|
||||||
TemporalUnit selectedUnit = selectedChronoField.getBaseUnit();
|
TemporalUnit selectedUnit = selectedChronoField.getBaseUnit();
|
||||||
|
|
||||||
|
int focusedIndex = table.getFocusModel().getFocusedIndex();
|
||||||
CombinedEvent focusedItem = table.getFocusModel().getFocusedItem();
|
CombinedEvent focusedItem = table.getFocusModel().getFocusedItem();
|
||||||
|
if (-1 == focusedIndex || null == focusedItem) {
|
||||||
|
focusedItem = visibleEvents.last();
|
||||||
|
focusedIndex = table.getItems().indexOf(focusedItem);
|
||||||
|
}
|
||||||
|
|
||||||
ZonedDateTime previousDateTime = getZonedDateTimeFromEvent(defaultIfNull(focusedItem, visibleEvents.last()), timeZoneID).minus(1, selectedUnit);//
|
ZonedDateTime focusedDateTime = Instant.ofEpochMilli(focusedItem.getStartMillis()).atZone(timeZoneID);
|
||||||
|
ZonedDateTime previousDateTime = focusedDateTime.minus(1, selectedUnit);//
|
||||||
|
|
||||||
for (ChronoField field : SCROLL_BY_UNITS) {
|
for (ChronoField field : SCROLL_BY_UNITS) {
|
||||||
if (field.getBaseUnit().getDuration().compareTo(selectedUnit.getDuration()) < 0) {
|
if (field.getBaseUnit().getDuration().compareTo(selectedUnit.getDuration()) < 0) {
|
||||||
previousDateTime = previousDateTime.with(field, field.rangeRefinedBy(previousDateTime).getMaximum());//
|
previousDateTime = previousDateTime.with(field, field.rangeRefinedBy(previousDateTime).getMaximum());//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long previousMillis = previousDateTime.toInstant().toEpochMilli();
|
||||||
|
|
||||||
final ZonedDateTime fzdt = previousDateTime;
|
int previousIndex = 0;
|
||||||
|
for (int i = focusedIndex; i > 0; i--) {
|
||||||
|
if (table.getItems().get(i).getStartMillis() <= previousMillis) {
|
||||||
|
previousIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scrollToAndFocus(Lists.reverse(table.getItems())//
|
scrollToAndFocus(previousIndex);
|
||||||
.stream()
|
|
||||||
.filter(combinedEvent -> getZonedDateTimeFromEvent(combinedEvent, timeZoneID).isBefore(fzdt))//
|
|
||||||
.findFirst()
|
|
||||||
.map(table.getItems()::indexOf)
|
|
||||||
.orElse(0));
|
|
||||||
});
|
});
|
||||||
setGraphic(new ImageView(PREVIOUS));
|
setGraphic(new ImageView(PREVIOUS));
|
||||||
disabledProperty().bind(table.getFocusModel().focusedIndexProperty().lessThan(1));
|
disabledProperty().bind(table.getFocusModel().focusedIndexProperty().lessThan(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class ListViewPane extends AbstractTimeLineView {
|
|||||||
|
|
||||||
@NbBundle.Messages({
|
@NbBundle.Messages({
|
||||||
"ListViewPane.loggedTask.queryDb=Retreiving event data",
|
"ListViewPane.loggedTask.queryDb=Retreiving event data",
|
||||||
"ListViewPane.loggedTask.name=Updating Details View",
|
"ListViewPane.loggedTask.name=Updating List View",
|
||||||
"ListViewPane.loggedTask.updateUI=Populating view"})
|
"ListViewPane.loggedTask.updateUI=Populating view"})
|
||||||
ListUpdateTask() {
|
ListUpdateTask() {
|
||||||
super(Bundle.ListViewPane_loggedTask_name(), true);
|
super(Bundle.ListViewPane_loggedTask_name(), true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user