diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java index eaa5aa7540..e771797aaa 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/DrawableGroup.java @@ -25,6 +25,7 @@ import javafx.collections.FXCollections; import javafx.collections.ObservableList; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; +import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; /** * Represents a set of image/video files in a group. The UI listens to changes @@ -34,15 +35,15 @@ public class DrawableGroup implements Comparable { private static final Logger LOGGER = Logger.getLogger(DrawableGroup.class.getName()); - /** - * the string to use when the groupkey is 'empty' - */ - public static final String UNKNOWN = "unknown"; + + public static String getBlankGroupName() { + return "unknown"; + } private final ObservableList fileIDs = FXCollections.observableArrayList(); //cache the number of files in this groups with hashset hits - private int filesWithHashSetHitsCount = -1; + private int hashSetHitsCount = -1; synchronized public ObservableList fileIds() { return fileIDs; @@ -54,6 +55,18 @@ public class DrawableGroup implements Comparable { return groupKey; } + public DrawableAttribute getGroupByAttribute() { + return groupKey.getAttribute(); + } + + public Object getGroupByValue() { + return groupKey.getValue(); + } + + public String getGroupByValueDislpayName() { + return groupKey.getValueDisplayName(); + } + DrawableGroup(GroupKey groupKey, List filesInGroup) { this.groupKey = groupKey; fileIDs.setAll(filesInGroup); @@ -64,7 +77,7 @@ public class DrawableGroup implements Comparable { } public double getHashHitDensity() { - return getFilesWithHashSetHitsCount() / (double) getSize(); + return getHashSetHitsCount() / (double) getSize(); } /** @@ -72,18 +85,18 @@ public class DrawableGroup implements Comparable { * so the hash counts may not longer be accurate. */ synchronized public void invalidateHashSetHitsCount() { - filesWithHashSetHitsCount = -1; + hashSetHitsCount = -1; } - synchronized public int getFilesWithHashSetHitsCount() { + synchronized public int getHashSetHitsCount() { //TODO: use the drawable db for this ? -jm - if (filesWithHashSetHitsCount < 0) { - filesWithHashSetHitsCount = 0; + if (hashSetHitsCount < 0) { + hashSetHitsCount = 0; for (Long fileID : fileIds()) { try { if (ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)) { - filesWithHashSetHitsCount++; + hashSetHitsCount++; } } catch (IllegalStateException | NullPointerException ex) { LOGGER.log(Level.WARNING, "could not access case during getFilesWithHashSetHitsCount()"); @@ -91,7 +104,7 @@ public class DrawableGroup implements Comparable { } } } - return filesWithHashSetHitsCount; + return hashSetHitsCount; } @Override diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java index 4826904735..789cac7375 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/grouping/GroupKey.java @@ -33,6 +33,13 @@ public class GroupKey> implements Comparable private final T val; + private final DrawableAttribute attr; + + public GroupKey(DrawableAttribute attr, T val) { + this.attr = attr; + this.val = val; + } + public T getValue() { return val; } @@ -41,11 +48,15 @@ public class GroupKey> implements Comparable return attr; } - private final DrawableAttribute attr; + public String getValueDisplayName() { + return Objects.equals(attr, DrawableAttribute.TAGS) + ? ((TagName) getValue()).getDisplayName() + : getValue().toString(); + } - public GroupKey(DrawableAttribute attr, T val) { - this.attr = attr; - this.val = val; + @Override + public String toString() { + return "GroupKey: " + getAttribute() + " = " + getValue(); } @Override @@ -74,24 +85,7 @@ public class GroupKey> implements Comparable @Override public int compareTo(GroupKey o) { - if (val instanceof Comparable) { - return ((Comparable) val).compareTo(o.val); - } else { - return Integer.compare(val.hashCode(), o.val.hashCode()); - } - + return val.compareTo(o.val); } - public String getValueDisplayName() { - if (attr == DrawableAttribute.TAGS) { - return ((TagName) getValue()).getDisplayName(); - } else { - return getValue().toString(); - } - } - - @Override - public String toString() { - return "GroupKey: " + getAttribute() + " = " + getValue(); - } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java index 52a61fdbd5..06713d6e00 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GroupPane.java @@ -87,7 +87,7 @@ import javafx.scene.paint.Color; import javafx.util.Duration; import javax.swing.Action; import javax.swing.SwingUtilities; -import org.apache.commons.lang3.StringUtils; +import static org.apache.commons.lang3.StringUtils.defaultIfBlank; import org.controlsfx.control.GridCell; import org.controlsfx.control.GridView; import org.controlsfx.control.SegmentedButton; @@ -290,17 +290,9 @@ public class GroupPane extends BorderPane implements GroupView { /** create the string to display in the group header */ protected String getHeaderString() { - if (getGrouping() == null) { - return ""; - } else { - String groupName = (getGrouping().groupKey.getAttribute() == DrawableAttribute.TAGS) - ? ((TagName) getGrouping().groupKey.getValue()).getDisplayName() - : getGrouping().groupKey.getValue().toString(); - return StringUtils.defaultIfBlank(groupName, DrawableGroup.UNKNOWN) + " -- " - + getGrouping().getFilesWithHashSetHitsCount() + " hash set hits / " - + getGrouping().getSize() + " files"; - - } + return isNull(getGrouping()) ? "" + : defaultIfBlank(getGrouping().getGroupByValueDislpayName(), DrawableGroup.getBlankGroupName()) + " -- " + + getGrouping().getHashSetHitsCount() + " hash set hits / " + getGrouping().getSize() + " files"; } ContextMenu getContextMenu() { @@ -476,7 +468,6 @@ public class GroupPane extends BorderPane implements GroupView { ActionUtils.configureButton(forwardAction, forwardButton); ActionUtils.configureButton(backAction, backButton); - nextGroupAction.disabledProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> { nextButton.setEffect(newValue ? null : DROP_SHADOW); if (newValue == false) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java index 2f34aec2e1..d38916aef2 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/GroupTreeCell.java @@ -81,7 +81,7 @@ class GroupTreeCell extends TreeCell { setGraphic(null); }); } else { - final String groupName = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.UNKNOWN); + final String groupName = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.getBlankGroupName()); if (isNull(tNode.getGroup())) { //"dummy" group in file system tree <=> a folder with no drawables @@ -119,7 +119,7 @@ class GroupTreeCell extends TreeCell { .map((DrawableGroup t) -> { return " (" + ((t.groupKey.getAttribute() == DrawableAttribute.HASHSET) ? Integer.toString(t.getSize()) - : t.getFilesWithHashSetHitsCount() + "/" + t.getSize()) + ")"; + : t.getHashSetHitsCount() + "/" + t.getSize()) + ")"; }).orElse(""); //if item is null or group is null return counts; diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java index 79a8e002e3..09b025d75e 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/NavPanel.java @@ -159,7 +159,7 @@ public class NavPanel extends TabPane { while (change.next()) { for (DrawableGroup g : change.getAddedSubList()) { insertIntoNavTree(g); - if (g.getFilesWithHashSetHitsCount() > 0) { + if (g.getHashSetHitsCount() > 0) { insertIntoHashTree(g); } } @@ -181,7 +181,7 @@ public class NavPanel extends TabPane { for (DrawableGroup g : controller.getGroupManager().getAnalyzedGroups()) { insertIntoNavTree(g); - if (g.getFilesWithHashSetHitsCount() > 0) { + if (g.getHashSetHitsCount() > 0) { insertIntoHashTree(g); } } @@ -201,7 +201,7 @@ public class NavPanel extends TabPane { for (DrawableGroup g : groups) { insertIntoNavTree(g); - if (g.getFilesWithHashSetHitsCount() > 0) { + if (g.getHashSetHitsCount() > 0) { insertIntoHashTree(g); } } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNodeComparators.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNodeComparators.java index 128a77e399..f16cc0cef6 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNodeComparators.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/navpanel/TreeNodeComparators.java @@ -37,7 +37,7 @@ enum TreeNodeComparators implements Comparator>, NonNullCompa @Override public int nonNullCompare(TreeItem o1, TreeItem o2) { - return -Integer.compare(o1.getValue().getGroup().getFilesWithHashSetHitsCount(), o2.getValue().getGroup().getFilesWithHashSetHitsCount()); + return -Integer.compare(o1.getValue().getGroup().getHashSetHitsCount(), o2.getValue().getGroup().getHashSetHitsCount()); } }, FILE_COUNT("Group Size") { @Override @@ -49,8 +49,8 @@ enum TreeNodeComparators implements Comparator>, NonNullCompa @Override public int nonNullCompare(TreeItem o1, TreeItem o2) { - return -Double.compare(o1.getValue().getGroup().getFilesWithHashSetHitsCount() / (double) o1.getValue().getGroup().getSize(), - o2.getValue().getGroup().getFilesWithHashSetHitsCount() / (double) o2.getValue().getGroup().getSize()); + return -Double.compare(o1.getValue().getGroup().getHashSetHitsCount() / (double) o1.getValue().getGroup().getSize(), + o2.getValue().getGroup().getHashSetHitsCount() / (double) o2.getValue().getGroup().getSize()); } };