Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DiscoveryUiUtils.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.discovery;
20 
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;
28 import java.util.Map;
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;
40 import org.sleuthkit.datamodel.BlackboardArtifact;
41 import org.sleuthkit.datamodel.BlackboardAttribute;
42 import org.sleuthkit.datamodel.DataSource;
43 import org.sleuthkit.datamodel.IngestJobInfo;
44 import org.sleuthkit.datamodel.SleuthkitCase;
45 import org.sleuthkit.datamodel.TskCoreException;
46 
50 final class DiscoveryUiUtils {
51 
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));
63 
64  @NbBundle.Messages({"# {0} - fileSize",
65  "# {1} - units",
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) {
81  long size = bytes;
82  int unitsSwitchValue = 0;
83  while (size > BYTE_UNIT_CONVERSION && unitsSwitchValue < 4) {
84  size /= BYTE_UNIT_CONVERSION;
85  unitsSwitchValue++;
86  }
87  String units;
88  switch (unitsSwitchValue) {
89  case 1:
90  units = Bundle.DiscoveryUiUtility_kiloBytes_text();
91  break;
92  case 2:
93  units = Bundle.DiscoveryUiUtility_megaBytes_text();
94  break;
95  case 3:
96  units = Bundle.DiscoveryUiUtility_gigaBytes_text();
97  break;
98  case 4:
99  units = Bundle.DiscoveryUiUtility_terraBytes_text();
100  break;
101  default:
102  units = Bundle.DiscoveryUiUtility_bytes_text();
103  break;
104  }
105  return Bundle.DiscoveryUiUtility_sizeLabel_text(size, units);
106  }
107 
114  static ImageIcon getUnsupportedImageThumbnail() {
115  return UNSUPPORTED_DOCUMENT_THUMBNAIL;
116  }
117 
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);
139  }
140  }
141  }
142  }
143  Collections.sort(setNames);
144  return setNames;
145  }
146 
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;
157  }
158 
167  static void setDeletedIcon(boolean isDeleted, javax.swing.JLabel isDeletedLabel) {
168  if (isDeleted) {
169  isDeletedLabel.setIcon(DELETED_ICON);
170  isDeletedLabel.setToolTipText(Bundle.ImageThumbnailPanel_isDeleted_text());
171  } else {
172  isDeletedLabel.setIcon(null);
173  isDeletedLabel.setToolTipText(null);
174  }
175  }
176 
184  static void setScoreIcon(ResultFile resultFile, javax.swing.JLabel scoreLabel) {
185  switch (resultFile.getScore()) {
186  case NOTABLE_SCORE:
187  scoreLabel.setIcon(NOTABLE_SCORE_ICON);
188  break;
189  case INTERESTING_SCORE:
190  scoreLabel.setIcon(INTERESTING_SCORE_ICON);
191  break;
192  case NO_SCORE: // empty case - this is interpreted as an intentional fall-through
193  default:
194  scoreLabel.setIcon(null);
195  break;
196  }
197  scoreLabel.setToolTipText(resultFile.getScoreDescription());
198  }
199 
205  static int getIconSize() {
206  return ICON_SIZE;
207  }
208 
213  static void displayErrorMessage(DiscoveryDialog dialog) {
214  //check if modules run and assemble message
215  try {
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()));
220  }
221 
222  for (IngestJobInfo jobInfo : skCase.getIngestJobs()) {
223  dataSourceIngestModules.get(jobInfo.getObjectId()).updateModulesRun(jobInfo);
224  }
225  String message = "";
226  for (DataSourceModulesWrapper dsmodulesWrapper : dataSourceIngestModules.values()) {
227  message += dsmodulesWrapper.getMessage();
228  }
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);
240  }
241  } catch (NoCurrentCaseException | TskCoreException ex) {
242  logger.log(Level.WARNING, "Exception while determining which modules have been run for Discovery", ex);
243  }
244  dialog.validateDialog();
245  }
246 
250  private DiscoveryUiUtils() {
251  //private constructor in a utility class intentionally left blank
252  }
253 }

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.