Autopsy  4.15.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
VideoThumbnailPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 2019 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.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.Image;
25 import java.awt.GridBagConstraints;
26 import java.awt.Point;
27 import java.awt.event.MouseEvent;
28 import java.util.concurrent.TimeUnit;
29 import javax.swing.ImageIcon;
30 import javax.swing.JComponent;
31 import javax.swing.JLabel;
32 import javax.swing.JList;
33 import javax.swing.ListCellRenderer;
34 import org.openide.util.NbBundle.Messages;
35 
39 final class VideoThumbnailPanel extends javax.swing.JPanel implements ListCellRenderer<VideoThumbnailsWrapper> {
40 
41  private static final int GAP_SIZE = 4;
42  private static final Color SELECTION_COLOR = new Color(0, 120, 215);
43  private static final int BYTE_UNIT_CONVERSION = 1000;
44  private static final long serialVersionUID = 1L;
45  private static final int MAX_NAME_STRING = 120;
46 
50  VideoThumbnailPanel() {
51  initComponents();
52  this.setFocusable(true);
53  }
54 
61  private void addThumbnails(VideoThumbnailsWrapper thumbnailWrapper) {
62  imagePanel.removeAll();
63  GridBagConstraints gridBagConstraints = new GridBagConstraints();
64  gridBagConstraints.gridx = 0;
65  gridBagConstraints.gridy = 0;
66  gridBagConstraints.anchor = GridBagConstraints.LINE_START;
67  imagePanel.add(new javax.swing.Box.Filler(new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 32767)), gridBagConstraints);
68  gridBagConstraints.gridy = 1;
69  imagePanel.add(new javax.swing.Box.Filler(new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 32767)), gridBagConstraints);
70  gridBagConstraints.gridx++;
71  int timeIndex = 0;
72  int[] timeStamps = thumbnailWrapper.getTimeStamps();
73  for (Image image : thumbnailWrapper.getThumbnails()) {
74  gridBagConstraints.gridy = 0;
75  imagePanel.add(new JLabel(new ImageIcon(image)), gridBagConstraints);
76 
77  gridBagConstraints.gridy = 1;
78  long millis = timeStamps[timeIndex];
79  long hours = TimeUnit.MILLISECONDS.toHours(millis);
80  millis -= TimeUnit.HOURS.toMillis(hours);
81  long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
82  millis -= TimeUnit.MINUTES.toMillis(minutes);
83  long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
84  imagePanel.add(new JLabel(String.format("%01d:%02d:%02d", hours, minutes, seconds)), gridBagConstraints);
85  gridBagConstraints.gridx++;
86  gridBagConstraints.gridy = 0;
87  imagePanel.add(new javax.swing.Box.Filler(new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 32767)), gridBagConstraints);
88  gridBagConstraints.gridy = 1;
89  imagePanel.add(new javax.swing.Box.Filler(new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 0), new java.awt.Dimension(GAP_SIZE, 32767)), gridBagConstraints);
90  gridBagConstraints.gridx++;
91  timeIndex++;
92  }
93  }
94 
100  @SuppressWarnings("unchecked")
101  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
102  private void initComponents() {
103 
104  imagePanel = new javax.swing.JPanel();
105  fileSizeLabel = new javax.swing.JLabel();
106  nameLabel = new javax.swing.JLabel();
107  scoreLabel = new javax.swing.JLabel();
108  deletedLabel = new javax.swing.JLabel();
109 
110  setBorder(javax.swing.BorderFactory.createEtchedBorder());
111 
112  imagePanel.setPreferredSize(new java.awt.Dimension(776, 115));
113  imagePanel.setLayout(new java.awt.GridBagLayout());
114 
115  scoreLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/red-circle-exclamation.png"))); // NOI18N
116  scoreLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
117  scoreLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
118  scoreLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
119 
120  deletedLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/file-icon-deleted.png"))); // NOI18N
121  deletedLabel.setMaximumSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
122  deletedLabel.setMinimumSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
123  deletedLabel.setPreferredSize(new Dimension(org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize(),org.sleuthkit.autopsy.discovery.DiscoveryUiUtils.getIconSize()));
124 
125  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
126  this.setLayout(layout);
127  layout.setHorizontalGroup(
128  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129  .addGroup(layout.createSequentialGroup()
130  .addContainerGap()
131  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132  .addComponent(imagePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
133  .addGroup(layout.createSequentialGroup()
134  .addComponent(fileSizeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
135  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
136  .addComponent(deletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
137  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
138  .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
139  .addComponent(nameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
140  .addContainerGap())
141  );
142  layout.setVerticalGroup(
143  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144  .addGroup(layout.createSequentialGroup()
145  .addContainerGap()
146  .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
147  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
148  .addComponent(imagePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
149  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
150  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
151  .addComponent(deletedLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152  .addComponent(fileSizeLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
153  .addComponent(scoreLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
154  .addContainerGap())
155  );
156  }// </editor-fold>//GEN-END:initComponents
157 
158 
159  // Variables declaration - do not modify//GEN-BEGIN:variables
160  private javax.swing.JLabel deletedLabel;
161  private javax.swing.JLabel fileSizeLabel;
162  private javax.swing.JPanel imagePanel;
163  private javax.swing.JLabel nameLabel;
164  private javax.swing.JLabel scoreLabel;
165  // End of variables declaration//GEN-END:variables
166 
167  @Messages({
168  "# {0} - otherInstanceCount",
169  "VideoThumbnailPanel.nameLabel.more.text= and {0} more",
170  "VideoThumbnailPanel.deleted.text=All instances of file are deleted."})
171  @Override
172  public Component getListCellRendererComponent(JList<? extends VideoThumbnailsWrapper> list, VideoThumbnailsWrapper value, int index, boolean isSelected, boolean cellHasFocus) {
173  fileSizeLabel.setText(getFileSizeString(value.getResultFile().getFirstInstance().getSize()));
174  String nameText = value.getResultFile().getFirstInstance().getParentPath() + value.getResultFile().getFirstInstance().getName();
175  if (value.getResultFile().getAllInstances().size() > 1) {
176  nameText += Bundle.VideoThumbnailPanel_nameLabel_more_text(value.getResultFile().getAllInstances().size() - 1);
177  }
178  if (nameText.length() > MAX_NAME_STRING) {
179  nameText = "..." + nameText.substring(nameText.length() - (MAX_NAME_STRING - 3));
180  }
181  nameLabel.setText(nameText);
182  addThumbnails(value);
183  imagePanel.setBackground(isSelected ? SELECTION_COLOR : list.getBackground());
184  DiscoveryUiUtils.setDeletedIcon(value.getResultFile().isDeleted(), deletedLabel);
185  DiscoveryUiUtils.setScoreIcon(value.getResultFile(), scoreLabel);
186  setBackground(isSelected ? SELECTION_COLOR : list.getBackground());
187  return this;
188  }
189 
190  @Messages({"# {0} - fileSize",
191  "# {1} - units",
192  "VideoThumbnailPanel.sizeLabel.text=Size: {0} {1}",
193  "VideoThumbnailPanel.bytes.text=bytes",
194  "VideoThumbnailPanel.kiloBytes.text=KB",
195  "VideoThumbnailPanel.megaBytes.text=MB",
196  "VideoThumbnailPanel.gigaBytes.text=GB",
197  "VideoThumbnailPanel.terraBytes.text=TB"})
206  private String getFileSizeString(long bytes) {
207  long size = bytes;
208  int unitsSwitchValue = 0;
209  while (size > BYTE_UNIT_CONVERSION && unitsSwitchValue < 4) {
210  size /= BYTE_UNIT_CONVERSION;
211  unitsSwitchValue++;
212  }
213  String units;
214  switch (unitsSwitchValue) {
215  case 1:
216  units = Bundle.VideoThumbnailPanel_kiloBytes_text();
217  break;
218  case 2:
219  units = Bundle.VideoThumbnailPanel_megaBytes_text();
220  break;
221  case 3:
222  units = Bundle.VideoThumbnailPanel_gigaBytes_text();
223  break;
224  case 4:
225  units = Bundle.VideoThumbnailPanel_terraBytes_text();
226  break;
227  default:
228  units = Bundle.VideoThumbnailPanel_bytes_text();
229  break;
230  }
231  return Bundle.VideoThumbnailPanel_sizeLabel_text(size, units);
232  }
233 
234  @Override
235  public String getToolTipText(MouseEvent event) {
236  if (event != null) {
237  //gets tooltip of internal panel item mouse is over
238  Point point = event.getPoint();
239  for (Component comp : getComponents()) {
240  if (DiscoveryUiUtils.isPointOnIcon(comp, point)) {
241  String toolTip = ((JComponent) comp).getToolTipText();
242  if (toolTip == null || toolTip.isEmpty()) {
243  return null;
244  } else {
245  return toolTip;
246  }
247  }
248  }
249  }
250  return null;
251  }
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.