mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-12 07:56:16 +00:00
use event bus for category change events
This commit is contained in:
parent
06e0a33499
commit
a20f040066
@ -20,7 +20,6 @@ package org.sleuthkit.autopsy.imagegallery;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
@ -358,7 +357,7 @@ public final class ImageGalleryController {
|
||||
hashSetManager.setDb(db);
|
||||
categoryManager.setDb(db);
|
||||
db.initializeImageList();
|
||||
SummaryTablePane.getDefault().handleCategoryChanged(Collections.emptyList());
|
||||
SummaryTablePane.getDefault().refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Autopsy Forensic Browser
|
||||
*
|
||||
* Copyright 2015 Basis Technology Corp.
|
||||
* Contact: carrier <at> sleuthkit <dot> org
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.sleuthkit.autopsy.imagegallery.datamodel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CategoryChangeEvent {
|
||||
|
||||
private final Collection<Long> ids;
|
||||
|
||||
public Collection<Long> getIds() {
|
||||
return Collections.unmodifiableCollection(ids);
|
||||
}
|
||||
|
||||
public CategoryChangeEvent(Collection<Long> ids) {
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
}
|
@ -3,12 +3,11 @@ package org.sleuthkit.autopsy.imagegallery.datamodel;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
import java.util.logging.Level;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
|
||||
@ -19,6 +18,7 @@ public class CategoryManager {
|
||||
|
||||
private static final java.util.logging.Logger LOGGER = Logger.getLogger(CategoryManager.class.getName());
|
||||
private DrawableDB db;
|
||||
private final EventBus categoryEventBus = new EventBus("Category Event Bus");
|
||||
|
||||
public void setDb(DrawableDB db) {
|
||||
this.db = db;
|
||||
@ -94,35 +94,19 @@ public class CategoryManager {
|
||||
}
|
||||
return longAdder;
|
||||
}
|
||||
@GuardedBy("listeners")
|
||||
private final Set<CategoryListener> listeners = new HashSet<>();
|
||||
|
||||
public void fireChange(Collection<Long> ids) {
|
||||
Set<CategoryListener> listenersCopy = new HashSet<>();
|
||||
synchronized (listeners) {
|
||||
listenersCopy.addAll(listeners);
|
||||
}
|
||||
for (CategoryListener list : listenersCopy) {
|
||||
list.handleCategoryChanged(ids);
|
||||
}
|
||||
|
||||
categoryEventBus.post(new CategoryChangeEvent(ids));
|
||||
|
||||
}
|
||||
|
||||
public void registerListener(CategoryListener aThis) {
|
||||
synchronized (listeners) {
|
||||
listeners.add(aThis);
|
||||
}
|
||||
public void registerListener(Object aThis) {
|
||||
categoryEventBus.register(aThis);
|
||||
}
|
||||
|
||||
public void unregisterListener(CategoryListener aThis) {
|
||||
synchronized (listeners) {
|
||||
listeners.remove(aThis);
|
||||
}
|
||||
public void unregisterListener(Object aThis) {
|
||||
categoryEventBus.unregister(aThis);
|
||||
}
|
||||
|
||||
public static interface CategoryListener {
|
||||
|
||||
public void handleCategoryChanged(Collection<Long> ids);
|
||||
|
||||
}
|
||||
}
|
@ -34,7 +34,6 @@ import org.sleuthkit.autopsy.coreutils.ThreadConfined;
|
||||
import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType;
|
||||
import org.sleuthkit.autopsy.imagegallery.FXMLConstructor;
|
||||
import org.sleuthkit.autopsy.imagegallery.TagUtils;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
|
||||
/**
|
||||
* GUI component that represents a single image as a tile with an icon, a label
|
||||
@ -44,7 +43,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
*
|
||||
* TODO: refactor this to extend from {@link Control}? -jm
|
||||
*/
|
||||
public class DrawableTile extends SingleDrawableViewBase implements CategoryManager.CategoryListener, TagUtils.TagListener {
|
||||
public class DrawableTile extends SingleDrawableViewBase implements TagUtils.TagListener {
|
||||
|
||||
private static final DropShadow LAST_SELECTED_EFFECT = new DropShadow(10, Color.BLUE);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.sleuthkit.autopsy.imagegallery.gui;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
import javafx.application.Platform;
|
||||
@ -14,6 +15,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
|
||||
import org.sleuthkit.autopsy.imagegallery.TagUtils;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
||||
|
||||
@ -21,7 +23,7 @@ import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
||||
* TODO: extract common interface out of {@link SingleImageView} and
|
||||
* {@link MetaDataPane}
|
||||
*/
|
||||
public interface DrawableView extends CategoryManager.CategoryListener, TagUtils.TagListener {
|
||||
public interface DrawableView extends TagUtils.TagListener {
|
||||
|
||||
//TODO: do this all in css? -jm
|
||||
static final int CAT_BORDER_WIDTH = 10;
|
||||
@ -52,8 +54,8 @@ public interface DrawableView extends CategoryManager.CategoryListener, TagUtils
|
||||
|
||||
Long getFileID();
|
||||
|
||||
@Override
|
||||
void handleCategoryChanged(Collection<Long> ids);
|
||||
@Subscribe
|
||||
void handleCategoryChanged(CategoryChangeEvent evt);
|
||||
|
||||
@Override
|
||||
void handleTagsChanged(Collection<Long> ids);
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.imagegallery.gui;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
@ -51,6 +52,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
||||
import org.sleuthkit.autopsy.imagegallery.TagUtils;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
||||
@ -60,7 +62,7 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class MetaDataPane extends AnchorPane implements CategoryManager.CategoryListener, TagUtils.TagListener, DrawableView {
|
||||
public class MetaDataPane extends AnchorPane implements TagUtils.TagListener, DrawableView {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(MetaDataPane.class.getName());
|
||||
|
||||
@ -237,9 +239,10 @@ public class MetaDataPane extends AnchorPane implements CategoryManager.Category
|
||||
return imageBorder;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Override
|
||||
public void handleCategoryChanged(Collection<Long> ids) {
|
||||
if (getFile() != null && ids.contains(getFileID())) {
|
||||
public void handleCategoryChanged(CategoryChangeEvent evt) {
|
||||
if (getFile() != null && evt.getIds().contains(getFileID())) {
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.imagegallery.gui;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -71,6 +72,8 @@ import org.sleuthkit.autopsy.imagegallery.TagUtils;
|
||||
import org.sleuthkit.autopsy.imagegallery.actions.AddDrawableTagAction;
|
||||
import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction;
|
||||
import org.sleuthkit.autopsy.imagegallery.actions.SwingMenuItemAdapter;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableFile;
|
||||
import org.sleuthkit.autopsy.imagegallery.grouping.GroupKey;
|
||||
@ -396,9 +399,9 @@ public abstract class SingleDrawableViewBase extends AnchorPane implements Drawa
|
||||
return imageBorder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCategoryChanged(Collection<Long> ids) {
|
||||
if (ids.contains(fileID)) {
|
||||
@Subscribe
|
||||
public void handleCategoryChanged(CategoryChangeEvent evt) {
|
||||
if (evt.getIds().contains(fileID)) {
|
||||
updateCategoryBorder();
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel;
|
||||
import org.sleuthkit.autopsy.imagegallery.TagUtils;
|
||||
import org.sleuthkit.autopsy.imagegallery.actions.CategorizeAction;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.ImageFile;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.VideoFile;
|
||||
@ -65,7 +64,7 @@ import org.sleuthkit.datamodel.TskCoreException;
|
||||
* GroupPane. TODO: Extract a subclass for video files in slideshow mode-jm
|
||||
* TODO: reduce coupling to GroupPane
|
||||
*/
|
||||
public class SlideShowView extends SingleDrawableViewBase implements TagUtils.TagListener, CategoryManager.CategoryListener {
|
||||
public class SlideShowView extends SingleDrawableViewBase implements TagUtils.TagListener {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(SlideShowView.class.getName());
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
*/
|
||||
package org.sleuthkit.autopsy.imagegallery.gui;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.logging.Level;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
@ -38,13 +38,14 @@ import org.sleuthkit.autopsy.coreutils.Logger;
|
||||
import org.sleuthkit.autopsy.imagegallery.FXMLConstructor;
|
||||
import org.sleuthkit.autopsy.imagegallery.ImageGalleryController;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.Category;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryChangeEvent;
|
||||
import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager;
|
||||
import org.sleuthkit.datamodel.TskCoreException;
|
||||
|
||||
/**
|
||||
* Displays summary statistics (counts) for each group
|
||||
*/
|
||||
public class SummaryTablePane extends AnchorPane implements CategoryManager.CategoryListener {
|
||||
public class SummaryTablePane extends AnchorPane {
|
||||
|
||||
private static SummaryTablePane instance;
|
||||
|
||||
@ -95,8 +96,12 @@ public class SummaryTablePane extends AnchorPane implements CategoryManager.Cate
|
||||
/**
|
||||
* listen to Category updates and rebuild the table
|
||||
*/
|
||||
@Override
|
||||
public void handleCategoryChanged(Collection<Long> ids) {
|
||||
@Subscribe
|
||||
public void handleCategoryChanged(CategoryChangeEvent evt) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
final ObservableList<Pair<Category, Long>> data = FXCollections.observableArrayList();
|
||||
if (Case.isCaseOpen()) {
|
||||
for (Category cat : Category.values()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user