From 3e3a48e184492050ecdcc7378db97146a98c6667 Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 29 Jun 2015 16:05:23 -0400 Subject: [PATCH] replace buggy JavaFX SortedLists with explicit sorting --- .../datamodel/grouping/GroupManager.java | 23 +++++++++---------- .../autopsy/imagegallery/gui/Toolbar.java | 1 - 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index ec63a51740..c5c3479a46 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -25,7 +25,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -44,7 +43,6 @@ import javafx.beans.property.ReadOnlyDoubleProperty; import javafx.beans.property.ReadOnlyDoubleWrapper; import javafx.collections.FXCollections; import javafx.collections.ObservableList; -import javafx.collections.transformation.SortedList; import static javafx.concurrent.Worker.State.CANCELLED; import static javafx.concurrent.Worker.State.FAILED; import static javafx.concurrent.Worker.State.READY; @@ -108,12 +106,12 @@ public class GroupManager { */ @ThreadConfined(type = ThreadType.JFX) private final ObservableList analyzedGroups = FXCollections.observableArrayList(); - private final SortedList unmodifiableAnalyzedGroups = new SortedList<>(analyzedGroups); + private final ObservableList unmodifiableAnalyzedGroups = FXCollections.unmodifiableObservableList(analyzedGroups); /** list of unseen groups */ @ThreadConfined(type = ThreadType.JFX) private final ObservableList unSeenGroups = FXCollections.observableArrayList(); - private final SortedList unmodifiableUnSeenGroups = new SortedList<>(unSeenGroups); + private final ObservableList unmodifiableUnSeenGroups = FXCollections.unmodifiableObservableList(unSeenGroups); private ReGroupTask groupByTask; @@ -270,6 +268,7 @@ public class GroupManager { } else if (unSeenGroups.contains(group) == false) { unSeenGroups.add(group); } + FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); } /** @@ -294,11 +293,12 @@ public class GroupManager { Platform.runLater(() -> { if (analyzedGroups.contains(group)) { analyzedGroups.remove(group); + FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); } if (unSeenGroups.contains(group)) { unSeenGroups.remove(group); + FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); } - }); } } else { //group == null @@ -535,8 +535,8 @@ public class GroupManager { setSortBy(sortBy); setSortOrder(sortOrder); Platform.runLater(() -> { - unmodifiableAnalyzedGroups.setComparator(sortBy.getGrpComparator(sortOrder)); - unmodifiableUnSeenGroups.setComparator(sortBy.getGrpComparator(sortOrder)); + FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); + FXCollections.sort(unSeenGroups, sortBy.getGrpComparator(sortOrder)); }); } } @@ -679,6 +679,9 @@ public class GroupManager { Platform.runLater(() -> { if (analyzedGroups.contains(group) == false) { analyzedGroups.add(group); + if (Objects.isNull(task)) { + FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); + } } markGroupSeen(group, groupSeen); }); @@ -731,10 +734,6 @@ public class GroupManager { Platform.runLater(() -> { analyzedGroups.clear(); unSeenGroups.clear(); - - final Comparator grpComparator = sortBy.getGrpComparator(sortOrder); - unmodifiableAnalyzedGroups.setComparator(grpComparator); - unmodifiableUnSeenGroups.setComparator(grpComparator); }); // Get the list of group keys @@ -754,7 +753,7 @@ public class GroupManager { groupProgress.progress("regrouping files by " + groupBy.attrName.toString() + " : " + val, p); popuplateIfAnalyzed(new GroupKey(groupBy, val), this); } - + FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); updateProgress(1, 1); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java index 33083c45b4..ea8cb26b00 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java @@ -41,7 +41,6 @@ import javafx.scene.image.ImageView; import javafx.scene.layout.HBox; import javax.swing.SortOrder; import org.openide.util.Exceptions; -import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableTagsManager; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;