From 68d28db500b45881e2ee7cea98b95b8ec626b20a Mon Sep 17 00:00:00 2001 From: jmillman Date: Mon, 22 Jun 2015 14:11:44 -0400 Subject: [PATCH] rename method in CategoryManager to be more descriptive; fix tag and category grouping when tags aer added / removed --- .../datamodel/CategoryManager.java | 6 ++-- .../imagegallery/grouping/GroupManager.java | 35 +++++++++++-------- .../imagegallery/gui/SlideShowView.java | 28 +++++++-------- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java index 4d2591aa1e..3a1a81e72d 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/CategoryManager.java @@ -211,7 +211,7 @@ public class CategoryManager { } - public static Category fromTagName(TagName tagName) { + public static Category categoryFromTagName(TagName tagName) { return Category.fromDisplayName(tagName.getDisplayName()); } @@ -246,7 +246,7 @@ public class CategoryManager { } catch (TskCoreException tskException) { LOGGER.log(Level.SEVERE, "Failed to get content tags for content. Unable to maintain category in a consistent state.", tskException); } - Category newCat = CategoryManager.fromTagName(addedTag.getName()); + Category newCat = CategoryManager.categoryFromTagName(addedTag.getName()); if (newCat != Category.ZERO) { incrementCategoryCount(newCat); } @@ -259,7 +259,7 @@ public class CategoryManager { ContentTag deleted = event.getDeletedTag(); if (isCategoryTagName(deleted.getName())) { - Category deletedCat = CategoryManager.fromTagName(deleted.getName()); + Category deletedCat = CategoryManager.categoryFromTagName(deleted.getName()); if (deletedCat != Category.ZERO) { decrementCategoryCount(deletedCat); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java index 9ac899742c..90adfa76b8 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupManager.java @@ -539,20 +539,25 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagAdded(ContentTagAddedEvent evt) { - if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getAddedTag().getName()); - final long fileID = evt.getAddedTag().getContent().getId(); - DrawableGroup g = getGroupForKey(groupKey); - addFileToGroup(g, groupKey, fileID); + GroupKey groupKey = null; + if (groupBy == DrawableAttribute.TAGS) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getAddedTag().getName()); + } else if (groupBy == DrawableAttribute.CATEGORY) { + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getAddedTag().getName())); } + final long fileID = evt.getAddedTag().getContent().getId(); + DrawableGroup g = getGroupForKey(groupKey); + addFileToGroup(g, groupKey, fileID); } + @SuppressWarnings("AssignmentToMethodParameter") private void addFileToGroup(DrawableGroup g, final GroupKey groupKey, final long fileID) { if (g == null) { //if there wasn't already a group check if there should be one now - popuplateIfAnalyzed(groupKey, null); - } else { + g = popuplateIfAnalyzed(groupKey, null); + } + if (g != null) { //if there is aleady a group that was previously deemed fully analyzed, then add this newly analyzed file to it. g.addFile(fileID); } @@ -560,11 +565,14 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { @Subscribe public void handleTagDeleted(ContentTagDeletedEvent evt) { - if (groupBy == DrawableAttribute.TAGS || groupBy == DrawableAttribute.CATEGORY) { - final GroupKey groupKey = new GroupKey<>(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); - final long fileID = evt.getDeletedTag().getContent().getId(); - DrawableGroup g = removeFromGroup(groupKey, fileID); + GroupKey groupKey = null; + if (groupBy == DrawableAttribute.TAGS) { + groupKey = new GroupKey(DrawableAttribute.TAGS, evt.getDeletedTag().getName()); + } else if (groupBy == DrawableAttribute.CATEGORY) { + groupKey = new GroupKey(DrawableAttribute.CATEGORY, CategoryManager.categoryFromTagName(evt.getDeletedTag().getName())); } + final long fileID = evt.getDeletedTag().getContent().getId(); + DrawableGroup g = removeFromGroup(groupKey, fileID); } @Override @@ -631,7 +639,7 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { if ((groupKey.getAttribute() != DrawableAttribute.PATH) || db.isGroupAnalyzed(groupKey)) { /* for attributes other than path we can't be sure a group is * fully analyzed because we don't know all the files that - * will be a part of that group */ + * will be a part of that group,. just show them no matter what. */ try { Set fileIDs = getFileIDsInGroup(groupKey); @@ -643,9 +651,8 @@ public class GroupManager implements FileUpdateEvent.FileUpdateListener { group = groupMap.get(groupKey); group.setFiles(ObjectUtils.defaultIfNull(fileIDs, Collections.emptySet())); } else { - group = new DrawableGroup(groupKey, fileIDs, groupSeen); - group.seenProperty().addListener((observable, oldSeen, newSeen) -> { + group.seenProperty().addListener((o, oldSeen, newSeen) -> { markGroupSeen(group, newSeen); }); groupMap.put(groupKey, group); diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java index 99944d6d19..d7d0f684ed 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/SlideShowView.java @@ -25,6 +25,7 @@ import javafx.application.Platform; import javafx.beans.Observable; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; @@ -282,24 +283,20 @@ public class SlideShowView extends DrawableTileBase { @Override protected String getTextForLabel() { - return getFile().map(file -> file.getName() + " " + getSupplementalText()).orElse(""); + return getFile().map(file -> file.getName()).orElse("") + " " + getSupplementalText(); } @ThreadConfined(type = ThreadType.JFX) - private void cycleSlideShowImage(int d) { + private void cycleSlideShowImage(int direction) { stopVideo(); - if (getFileID().isPresent()) { - int index = getGroupPane().getGrouping().fileIds().indexOf(getFileID()); - final int size = getGroupPane().getGrouping().fileIds().size(); - index = (index + d) % size; - if (index < 0) { - index += size; - } - setFile(getGroupPane().getGrouping().fileIds().get(index)); + final int groupSize = getGroupPane().getGrouping().fileIds().size(); + final Integer nextIndex = getFileID().map(fileID -> { + final int currentIndex = getGroupPane().getGrouping().fileIds().indexOf(fileID); + return (currentIndex + direction + groupSize) % groupSize; + }).orElse(0); + setFile(getGroupPane().getGrouping().fileIds().get(nextIndex) + ); - } else { - setFile(getGroupPane().getGrouping().fileIds().get(0)); - } } /** @@ -307,7 +304,10 @@ public class SlideShowView extends DrawableTileBase { * of y" */ private String getSupplementalText() { - return " ( " + (getGroupPane().getGrouping().fileIds().indexOf(getFileID()) + 1) + " of " + getGroupPane().getGrouping().fileIds().size() + " in group )"; + final ObservableList fileIds = getGroupPane().getGrouping().fileIds(); + return getFileID().map(fileID -> " ( " + (fileIds.indexOf(fileID) + 1) + " of " + fileIds.size() + " in group )") + .orElse(""); + } @Override