Autopsy  4.14.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.filequery;
20 
21 import java.awt.Component;
22 import java.awt.Point;
23 import javax.swing.ImageIcon;
24 import javax.swing.JComponent;
25 import org.openide.util.ImageUtilities;
26 import org.openide.util.NbBundle;
27 
31 final class DiscoveryUiUtils {
32 
33  private static final int BYTE_UNIT_CONVERSION = 1000;
34  private static final int ICON_SIZE = 16;
35  private static final String RED_CIRCLE_ICON_PATH = "org/sleuthkit/autopsy/images/red-circle-exclamation.png";
36  private static final String YELLOW_CIRCLE_ICON_PATH = "org/sleuthkit/autopsy/images/yellow-circle-yield.png";
37  private static final String DELETE_ICON_PATH = "/org/sleuthkit/autopsy/images/file-icon-deleted.png";
38  private static final String UNSUPPORTED_DOC_PATH = "/org/sleuthkit/autopsy/images/image-extraction-not-supported.png";
39  private static final ImageIcon INTERESTING_SCORE_ICON = new ImageIcon(ImageUtilities.loadImage(YELLOW_CIRCLE_ICON_PATH, false));
40  private static final ImageIcon NOTABLE_SCORE_ICON = new ImageIcon(ImageUtilities.loadImage(RED_CIRCLE_ICON_PATH, false));
41  private static final ImageIcon DELETED_ICON = new ImageIcon(ImageUtilities.loadImage(DELETE_ICON_PATH, false));
42  private static final ImageIcon UNSUPPORTED_DOCUMENT_THUMBNAIL = new ImageIcon(ImageUtilities.loadImage(UNSUPPORTED_DOC_PATH, false));
43 
44  @NbBundle.Messages({"# {0} - fileSize",
45  "# {1} - units",
46  "DiscoveryUiUtility.sizeLabel.text=Size: {0} {1}",
47  "DiscoveryUiUtility.bytes.text=bytes",
48  "DiscoveryUiUtility.kiloBytes.text=KB",
49  "DiscoveryUiUtility.megaBytes.text=MB",
50  "DiscoveryUiUtility.gigaBytes.text=GB",
51  "DiscoveryUiUtility.terraBytes.text=TB"})
60  static String getFileSizeString(long bytes) {
61  long size = bytes;
62  int unitsSwitchValue = 0;
63  while (size > BYTE_UNIT_CONVERSION && unitsSwitchValue < 4) {
64  size /= BYTE_UNIT_CONVERSION;
65  unitsSwitchValue++;
66  }
67  String units;
68  switch (unitsSwitchValue) {
69  case 1:
70  units = Bundle.DiscoveryUiUtility_kiloBytes_text();
71  break;
72  case 2:
73  units = Bundle.DiscoveryUiUtility_megaBytes_text();
74  break;
75  case 3:
76  units = Bundle.DiscoveryUiUtility_gigaBytes_text();
77  break;
78  case 4:
79  units = Bundle.DiscoveryUiUtility_terraBytes_text();
80  break;
81  default:
82  units = Bundle.DiscoveryUiUtility_bytes_text();
83  break;
84  }
85  return Bundle.DiscoveryUiUtility_sizeLabel_text(size, units);
86  }
87 
94  static ImageIcon getUnsupportedImageThumbnail() {
95  return UNSUPPORTED_DOCUMENT_THUMBNAIL;
96  }
97 
106  static boolean isPointOnIcon(Component comp, Point point) {
107  return comp instanceof JComponent && point.x >= comp.getX() && point.x <= comp.getX() + ICON_SIZE && point.y >= comp.getY() && point.y <= comp.getY() + ICON_SIZE;
108  }
109 
118  static void setDeletedIcon(boolean isDeleted, javax.swing.JLabel isDeletedLabel) {
119  if (isDeleted) {
120  isDeletedLabel.setIcon(DELETED_ICON);
121  isDeletedLabel.setToolTipText(Bundle.ImageThumbnailPanel_isDeleted_text());
122  } else {
123  isDeletedLabel.setIcon(null);
124  isDeletedLabel.setToolTipText(null);
125  }
126  }
127 
135  static void setScoreIcon(ResultFile resultFile, javax.swing.JLabel scoreLabel) {
136  switch (resultFile.getScore()) {
137  case NOTABLE_SCORE:
138  scoreLabel.setIcon(NOTABLE_SCORE_ICON);
139  break;
140  case INTERESTING_SCORE:
141  scoreLabel.setIcon(INTERESTING_SCORE_ICON);
142  break;
143  case NO_SCORE: // empty case - this is interpreted as an intentional fall-through
144  default:
145  scoreLabel.setIcon(null);
146  break;
147  }
148  scoreLabel.setToolTipText(resultFile.getScoreDescription());
149  }
150 
156  static int getIconSize() {
157  return ICON_SIZE;
158  }
159 
163  private DiscoveryUiUtils() {
164  //private constructor in a utility class intentionally left blank
165  }
166 }

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