19 package org.sleuthkit.autopsy.discovery;
21 import java.awt.Component;
22 import java.awt.Dimension;
23 import java.awt.Point;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.ImageIcon;
31 import javax.swing.JComponent;
32 import javax.swing.JOptionPane;
33 import javax.swing.JScrollPane;
34 import javax.swing.JTextPane;
35 import org.openide.util.ImageUtilities;
36 import org.openide.util.NbBundle;
50 final class DiscoveryUiUtils {
52 private final static Logger logger = Logger.getLogger(DiscoveryUiUtils.class.getName());
53 private static final int BYTE_UNIT_CONVERSION = 1000;
54 private static final int ICON_SIZE = 16;
55 private static final String RED_CIRCLE_ICON_PATH =
"org/sleuthkit/autopsy/images/red-circle-exclamation.png";
56 private static final String YELLOW_CIRCLE_ICON_PATH =
"org/sleuthkit/autopsy/images/yellow-circle-yield.png";
57 private static final String DELETE_ICON_PATH =
"org/sleuthkit/autopsy/images/file-icon-deleted.png";
58 private static final String UNSUPPORTED_DOC_PATH =
"org/sleuthkit/autopsy/images/image-extraction-not-supported.png";
59 private static final ImageIcon INTERESTING_SCORE_ICON =
new ImageIcon(ImageUtilities.loadImage(YELLOW_CIRCLE_ICON_PATH,
false));
60 private static final ImageIcon NOTABLE_SCORE_ICON =
new ImageIcon(ImageUtilities.loadImage(RED_CIRCLE_ICON_PATH,
false));
61 private static final ImageIcon DELETED_ICON =
new ImageIcon(ImageUtilities.loadImage(DELETE_ICON_PATH,
false));
62 private static final ImageIcon UNSUPPORTED_DOCUMENT_THUMBNAIL =
new ImageIcon(ImageUtilities.loadImage(UNSUPPORTED_DOC_PATH,
false));
64 @NbBundle.Messages({
"# {0} - fileSize",
66 "DiscoveryUiUtility.sizeLabel.text=Size: {0} {1}",
67 "DiscoveryUiUtility.bytes.text=bytes",
68 "DiscoveryUiUtility.kiloBytes.text=KB",
69 "DiscoveryUiUtility.megaBytes.text=MB",
70 "DiscoveryUiUtility.gigaBytes.text=GB",
71 "DiscoveryUiUtility.terraBytes.text=TB"})
80 static String getFileSizeString(
long bytes) {
82 int unitsSwitchValue = 0;
83 while (size > BYTE_UNIT_CONVERSION && unitsSwitchValue < 4) {
84 size /= BYTE_UNIT_CONVERSION;
88 switch (unitsSwitchValue) {
90 units = Bundle.DiscoveryUiUtility_kiloBytes_text();
93 units = Bundle.DiscoveryUiUtility_megaBytes_text();
96 units = Bundle.DiscoveryUiUtility_gigaBytes_text();
99 units = Bundle.DiscoveryUiUtility_terraBytes_text();
102 units = Bundle.DiscoveryUiUtility_bytes_text();
105 return Bundle.DiscoveryUiUtility_sizeLabel_text(size, units);
114 static ImageIcon getUnsupportedImageThumbnail() {
115 return UNSUPPORTED_DOCUMENT_THUMBNAIL;
130 static List<String> getSetNames(BlackboardArtifact.ARTIFACT_TYPE artifactType, BlackboardAttribute.ATTRIBUTE_TYPE setNameAttribute) throws TskCoreException {
131 List<BlackboardArtifact> arts = Case.getCurrentCase().getSleuthkitCase().getBlackboardArtifacts(artifactType);
132 List<String> setNames =
new ArrayList<>();
133 for (BlackboardArtifact art : arts) {
134 for (BlackboardAttribute attr : art.getAttributes()) {
135 if (attr.getAttributeType().getTypeID() == setNameAttribute.getTypeID()) {
136 String setName = attr.getValueString();
137 if (!setNames.contains(setName)) {
138 setNames.add(setName);
143 Collections.sort(setNames);
155 static boolean isPointOnIcon(Component comp, Point point) {
156 return comp instanceof JComponent && point.x >= comp.getX() && point.x <= comp.getX() + ICON_SIZE && point.y >= comp.getY() && point.y <= comp.getY() + ICON_SIZE;
167 static void setDeletedIcon(
boolean isDeleted, javax.swing.JLabel isDeletedLabel) {
169 isDeletedLabel.setIcon(DELETED_ICON);
170 isDeletedLabel.setToolTipText(Bundle.ImageThumbnailPanel_isDeleted_text());
172 isDeletedLabel.setIcon(null);
173 isDeletedLabel.setToolTipText(null);
184 static void setScoreIcon(ResultFile resultFile, javax.swing.JLabel scoreLabel) {
185 switch (resultFile.getScore()) {
187 scoreLabel.setIcon(NOTABLE_SCORE_ICON);
189 case INTERESTING_SCORE:
190 scoreLabel.setIcon(INTERESTING_SCORE_ICON);
194 scoreLabel.setIcon(null);
197 scoreLabel.setToolTipText(resultFile.getScoreDescription());
205 static int getIconSize() {
213 static void displayErrorMessage(DiscoveryDialog dialog) {
216 SleuthkitCase skCase = Case.getCurrentCaseThrows().getSleuthkitCase();
217 Map<Long, DataSourceModulesWrapper> dataSourceIngestModules =
new HashMap<>();
218 for (DataSource dataSource : skCase.getDataSources()) {
219 dataSourceIngestModules.put(dataSource.getId(),
new DataSourceModulesWrapper(dataSource.getName()));
222 for (IngestJobInfo jobInfo : skCase.getIngestJobs()) {
223 dataSourceIngestModules.get(jobInfo.getObjectId()).updateModulesRun(jobInfo);
226 for (DataSourceModulesWrapper dsmodulesWrapper : dataSourceIngestModules.values()) {
227 message += dsmodulesWrapper.getMessage();
229 if (!message.isEmpty()) {
230 JScrollPane messageScrollPane =
new JScrollPane();
231 JTextPane messageTextPane =
new JTextPane();
232 messageTextPane.setText(message);
233 messageTextPane.setVisible(
true);
234 messageTextPane.setEditable(
false);
235 messageTextPane.setCaretPosition(0);
236 messageScrollPane.setMaximumSize(
new Dimension(600, 100));
237 messageScrollPane.setPreferredSize(
new Dimension(600, 100));
238 messageScrollPane.setViewportView(messageTextPane);
239 JOptionPane.showMessageDialog(dialog, messageScrollPane, Bundle.OpenDiscoveryAction_resultsIncomplete_text(), JOptionPane.PLAIN_MESSAGE);
241 }
catch (NoCurrentCaseException | TskCoreException ex) {
242 logger.log(Level.WARNING,
"Exception while determining which modules have been run for Discovery", ex);
244 dialog.validateDialog();
250 private DiscoveryUiUtils() {