mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-15 09:17:42 +00:00
added convenience methods to access attrubutes of GroupKey; cleanup
This commit is contained in:
parent
7bf122e1d6
commit
a08fa13c5f
@ -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<DrawableGroup> {
|
||||
|
||||
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<Long> 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<Long> fileIds() {
|
||||
return fileIDs;
|
||||
@ -54,6 +55,18 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
|
||||
return groupKey;
|
||||
}
|
||||
|
||||
public DrawableAttribute<?> getGroupByAttribute() {
|
||||
return groupKey.getAttribute();
|
||||
}
|
||||
|
||||
public Object getGroupByValue() {
|
||||
return groupKey.getValue();
|
||||
}
|
||||
|
||||
public String getGroupByValueDislpayName() {
|
||||
return groupKey.getValueDisplayName();
|
||||
}
|
||||
|
||||
DrawableGroup(GroupKey<?> groupKey, List<Long> filesInGroup) {
|
||||
this.groupKey = groupKey;
|
||||
fileIDs.setAll(filesInGroup);
|
||||
@ -64,7 +77,7 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
|
||||
}
|
||||
|
||||
public double getHashHitDensity() {
|
||||
return getFilesWithHashSetHitsCount() / (double) getSize();
|
||||
return getHashSetHitsCount() / (double) getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,18 +85,18 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
|
||||
* 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<DrawableGroup> {
|
||||
}
|
||||
}
|
||||
}
|
||||
return filesWithHashSetHitsCount;
|
||||
return hashSetHitsCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,6 +33,13 @@ public class GroupKey<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
||||
|
||||
private final T val;
|
||||
|
||||
private final DrawableAttribute<T> attr;
|
||||
|
||||
public GroupKey(DrawableAttribute<T> attr, T val) {
|
||||
this.attr = attr;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return val;
|
||||
}
|
||||
@ -41,11 +48,15 @@ public class GroupKey<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
||||
return attr;
|
||||
}
|
||||
|
||||
private final DrawableAttribute<T> attr;
|
||||
public String getValueDisplayName() {
|
||||
return Objects.equals(attr, DrawableAttribute.TAGS)
|
||||
? ((TagName) getValue()).getDisplayName()
|
||||
: getValue().toString();
|
||||
}
|
||||
|
||||
public GroupKey(DrawableAttribute<T> 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<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
||||
|
||||
@Override
|
||||
public int compareTo(GroupKey<T> o) {
|
||||
if (val instanceof Comparable) {
|
||||
return ((Comparable<T>) 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();
|
||||
}
|
||||
}
|
||||
|
@ -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<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
||||
nextButton.setEffect(newValue ? null : DROP_SHADOW);
|
||||
if (newValue == false) {
|
||||
|
@ -81,7 +81,7 @@ class GroupTreeCell extends TreeCell<TreeNode> {
|
||||
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<TreeNode> {
|
||||
.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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ enum TreeNodeComparators implements Comparator<TreeItem<TreeNode>>, NonNullCompa
|
||||
@Override
|
||||
public int nonNullCompare(TreeItem<TreeNode> o1, TreeItem<TreeNode> 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<TreeItem<TreeNode>>, NonNullCompa
|
||||
@Override
|
||||
public int nonNullCompare(TreeItem<TreeNode> o1, TreeItem<TreeNode> 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());
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user