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 javafx.collections.ObservableList;
|
||||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||||
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
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
|
* 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());
|
private static final Logger LOGGER = Logger.getLogger(DrawableGroup.class.getName());
|
||||||
|
|
||||||
/**
|
|
||||||
* the string to use when the groupkey is 'empty'
|
public static String getBlankGroupName() {
|
||||||
*/
|
return "unknown";
|
||||||
public static final String UNKNOWN = "unknown";
|
}
|
||||||
|
|
||||||
private final ObservableList<Long> fileIDs = FXCollections.observableArrayList();
|
private final ObservableList<Long> fileIDs = FXCollections.observableArrayList();
|
||||||
|
|
||||||
//cache the number of files in this groups with hashset hits
|
//cache the number of files in this groups with hashset hits
|
||||||
private int filesWithHashSetHitsCount = -1;
|
private int hashSetHitsCount = -1;
|
||||||
|
|
||||||
synchronized public ObservableList<Long> fileIds() {
|
synchronized public ObservableList<Long> fileIds() {
|
||||||
return fileIDs;
|
return fileIDs;
|
||||||
@ -54,6 +55,18 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
|
|||||||
return groupKey;
|
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) {
|
DrawableGroup(GroupKey<?> groupKey, List<Long> filesInGroup) {
|
||||||
this.groupKey = groupKey;
|
this.groupKey = groupKey;
|
||||||
fileIDs.setAll(filesInGroup);
|
fileIDs.setAll(filesInGroup);
|
||||||
@ -64,7 +77,7 @@ public class DrawableGroup implements Comparable<DrawableGroup> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getHashHitDensity() {
|
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.
|
* so the hash counts may not longer be accurate.
|
||||||
*/
|
*/
|
||||||
synchronized public void invalidateHashSetHitsCount() {
|
synchronized public void invalidateHashSetHitsCount() {
|
||||||
filesWithHashSetHitsCount = -1;
|
hashSetHitsCount = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public int getFilesWithHashSetHitsCount() {
|
synchronized public int getHashSetHitsCount() {
|
||||||
//TODO: use the drawable db for this ? -jm
|
//TODO: use the drawable db for this ? -jm
|
||||||
if (filesWithHashSetHitsCount < 0) {
|
if (hashSetHitsCount < 0) {
|
||||||
filesWithHashSetHitsCount = 0;
|
hashSetHitsCount = 0;
|
||||||
for (Long fileID : fileIds()) {
|
for (Long fileID : fileIds()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)) {
|
if (ImageGalleryController.getDefault().getDatabase().isInHashSet(fileID)) {
|
||||||
filesWithHashSetHitsCount++;
|
hashSetHitsCount++;
|
||||||
}
|
}
|
||||||
} catch (IllegalStateException | NullPointerException ex) {
|
} catch (IllegalStateException | NullPointerException ex) {
|
||||||
LOGGER.log(Level.WARNING, "could not access case during getFilesWithHashSetHitsCount()");
|
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
|
@Override
|
||||||
|
@ -33,6 +33,13 @@ public class GroupKey<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
|||||||
|
|
||||||
private final T val;
|
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() {
|
public T getValue() {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@ -41,11 +48,15 @@ public class GroupKey<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
|||||||
return attr;
|
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) {
|
@Override
|
||||||
this.attr = attr;
|
public String toString() {
|
||||||
this.val = val;
|
return "GroupKey: " + getAttribute() + " = " + getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,24 +85,7 @@ public class GroupKey<T extends Comparable<T>> implements Comparable<GroupKey<T>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(GroupKey<T> o) {
|
public int compareTo(GroupKey<T> o) {
|
||||||
if (val instanceof Comparable) {
|
return val.compareTo(o.val);
|
||||||
return ((Comparable<T>) val).compareTo(o.val);
|
|
||||||
} else {
|
|
||||||
return Integer.compare(val.hashCode(), o.val.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 javafx.util.Duration;
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.SwingUtilities;
|
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.GridCell;
|
||||||
import org.controlsfx.control.GridView;
|
import org.controlsfx.control.GridView;
|
||||||
import org.controlsfx.control.SegmentedButton;
|
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 */
|
/** create the string to display in the group header */
|
||||||
protected String getHeaderString() {
|
protected String getHeaderString() {
|
||||||
if (getGrouping() == null) {
|
return isNull(getGrouping()) ? ""
|
||||||
return "";
|
: defaultIfBlank(getGrouping().getGroupByValueDislpayName(), DrawableGroup.getBlankGroupName()) + " -- "
|
||||||
} else {
|
+ getGrouping().getHashSetHitsCount() + " hash set hits / " + getGrouping().getSize() + " files";
|
||||||
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";
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextMenu getContextMenu() {
|
ContextMenu getContextMenu() {
|
||||||
@ -476,7 +468,6 @@ public class GroupPane extends BorderPane implements GroupView {
|
|||||||
ActionUtils.configureButton(forwardAction, forwardButton);
|
ActionUtils.configureButton(forwardAction, forwardButton);
|
||||||
ActionUtils.configureButton(backAction, backButton);
|
ActionUtils.configureButton(backAction, backButton);
|
||||||
|
|
||||||
|
|
||||||
nextGroupAction.disabledProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
nextGroupAction.disabledProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
|
||||||
nextButton.setEffect(newValue ? null : DROP_SHADOW);
|
nextButton.setEffect(newValue ? null : DROP_SHADOW);
|
||||||
if (newValue == false) {
|
if (newValue == false) {
|
||||||
|
@ -81,7 +81,7 @@ class GroupTreeCell extends TreeCell<TreeNode> {
|
|||||||
setGraphic(null);
|
setGraphic(null);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
final String groupName = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.UNKNOWN);
|
final String groupName = StringUtils.defaultIfBlank(tNode.getPath(), DrawableGroup.getBlankGroupName());
|
||||||
|
|
||||||
if (isNull(tNode.getGroup())) {
|
if (isNull(tNode.getGroup())) {
|
||||||
//"dummy" group in file system tree <=> a folder with no drawables
|
//"dummy" group in file system tree <=> a folder with no drawables
|
||||||
@ -119,7 +119,7 @@ class GroupTreeCell extends TreeCell<TreeNode> {
|
|||||||
.map((DrawableGroup t) -> {
|
.map((DrawableGroup t) -> {
|
||||||
return " (" + ((t.groupKey.getAttribute() == DrawableAttribute.HASHSET)
|
return " (" + ((t.groupKey.getAttribute() == DrawableAttribute.HASHSET)
|
||||||
? Integer.toString(t.getSize())
|
? Integer.toString(t.getSize())
|
||||||
: t.getFilesWithHashSetHitsCount() + "/" + t.getSize()) + ")";
|
: t.getHashSetHitsCount() + "/" + t.getSize()) + ")";
|
||||||
}).orElse(""); //if item is null or group is null
|
}).orElse(""); //if item is null or group is null
|
||||||
|
|
||||||
return counts;
|
return counts;
|
||||||
|
@ -159,7 +159,7 @@ public class NavPanel extends TabPane {
|
|||||||
while (change.next()) {
|
while (change.next()) {
|
||||||
for (DrawableGroup g : change.getAddedSubList()) {
|
for (DrawableGroup g : change.getAddedSubList()) {
|
||||||
insertIntoNavTree(g);
|
insertIntoNavTree(g);
|
||||||
if (g.getFilesWithHashSetHitsCount() > 0) {
|
if (g.getHashSetHitsCount() > 0) {
|
||||||
insertIntoHashTree(g);
|
insertIntoHashTree(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,7 +181,7 @@ public class NavPanel extends TabPane {
|
|||||||
|
|
||||||
for (DrawableGroup g : controller.getGroupManager().getAnalyzedGroups()) {
|
for (DrawableGroup g : controller.getGroupManager().getAnalyzedGroups()) {
|
||||||
insertIntoNavTree(g);
|
insertIntoNavTree(g);
|
||||||
if (g.getFilesWithHashSetHitsCount() > 0) {
|
if (g.getHashSetHitsCount() > 0) {
|
||||||
insertIntoHashTree(g);
|
insertIntoHashTree(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ public class NavPanel extends TabPane {
|
|||||||
|
|
||||||
for (DrawableGroup g : groups) {
|
for (DrawableGroup g : groups) {
|
||||||
insertIntoNavTree(g);
|
insertIntoNavTree(g);
|
||||||
if (g.getFilesWithHashSetHitsCount() > 0) {
|
if (g.getHashSetHitsCount() > 0) {
|
||||||
insertIntoHashTree(g);
|
insertIntoHashTree(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ enum TreeNodeComparators implements Comparator<TreeItem<TreeNode>>, NonNullCompa
|
|||||||
@Override
|
@Override
|
||||||
public int nonNullCompare(TreeItem<TreeNode> o1, TreeItem<TreeNode> o2) {
|
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") {
|
}, FILE_COUNT("Group Size") {
|
||||||
@Override
|
@Override
|
||||||
@ -49,8 +49,8 @@ enum TreeNodeComparators implements Comparator<TreeItem<TreeNode>>, NonNullCompa
|
|||||||
@Override
|
@Override
|
||||||
public int nonNullCompare(TreeItem<TreeNode> o1, TreeItem<TreeNode> o2) {
|
public int nonNullCompare(TreeItem<TreeNode> o1, TreeItem<TreeNode> o2) {
|
||||||
|
|
||||||
return -Double.compare(o1.getValue().getGroup().getFilesWithHashSetHitsCount() / (double) o1.getValue().getGroup().getSize(),
|
return -Double.compare(o1.getValue().getGroup().getHashSetHitsCount() / (double) o1.getValue().getGroup().getSize(),
|
||||||
o2.getValue().getGroup().getFilesWithHashSetHitsCount() / (double) o2.getValue().getGroup().getSize());
|
o2.getValue().getGroup().getHashSetHitsCount() / (double) o2.getValue().getGroup().getSize());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user