Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourceSummaryCountsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
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.casemodule.datasourcesummary;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
25 import javax.swing.JLabel;
26 import javax.swing.table.AbstractTableModel;
27 import javax.swing.table.DefaultTableCellRenderer;
28 import javax.swing.table.DefaultTableModel;
29 import org.openide.util.NbBundle.Messages;
31 import org.sleuthkit.datamodel.DataSource;
32 
37 class DataSourceSummaryCountsPanel extends javax.swing.JPanel {
38 
39  private static final long serialVersionUID = 1L;
40  private FilesByMimeTypeTableModel filesByMimeTypeTableModel = new FilesByMimeTypeTableModel(null);
41  private FilesByCategoryTableModel filesByCategoryTableModel = new FilesByCategoryTableModel(null);
42  private static final Logger logger = Logger.getLogger(DataSourceSummaryCountsPanel.class.getName());
43  private final Map<Long, Long> allFilesCountsMap;
44  private final Map<Long, Long> slackFilesCountsMap;
45  private final Map<Long, Long> directoriesCountsMap;
46  private final Map<Long, Long> unallocatedFilesCountsMap;
47  private final Map<Long, Map<String, Long>> artifactsByTypeCountsMap;
48  private final DefaultTableCellRenderer rightAlignedRenderer = new DefaultTableCellRenderer();
49 
53  DataSourceSummaryCountsPanel(Map<Long, Long> fileCountsMap) {
54  this.allFilesCountsMap = fileCountsMap;
55  this.slackFilesCountsMap = DataSourceInfoUtilities.getCountsOfSlackFiles();
56  this.directoriesCountsMap = DataSourceInfoUtilities.getCountsOfDirectories();
57  this.unallocatedFilesCountsMap = DataSourceInfoUtilities.getCountsOfUnallocatedFiles();
58  this.artifactsByTypeCountsMap = DataSourceInfoUtilities.getCountsOfArtifactsByType();
59  rightAlignedRenderer.setHorizontalAlignment(JLabel.RIGHT);
60  initComponents();
61  fileCountsByMimeTypeTable.getTableHeader().setReorderingAllowed(false);
62  fileCountsByCategoryTable.getTableHeader().setReorderingAllowed(false);
63  }
64 
70  void updateCountsTableData(DataSource selectedDataSource) {
71  filesByMimeTypeTableModel = new FilesByMimeTypeTableModel(selectedDataSource);
72  fileCountsByMimeTypeTable.setModel(filesByMimeTypeTableModel);
73  fileCountsByMimeTypeTable.getColumnModel().getColumn(1).setCellRenderer(rightAlignedRenderer);
74  fileCountsByMimeTypeTable.getColumnModel().getColumn(0).setPreferredWidth(130);
75  filesByCategoryTableModel = new FilesByCategoryTableModel(selectedDataSource);
76  fileCountsByCategoryTable.setModel(filesByCategoryTableModel);
77  fileCountsByCategoryTable.getColumnModel().getColumn(1).setCellRenderer(rightAlignedRenderer);
78  fileCountsByCategoryTable.getColumnModel().getColumn(0).setPreferredWidth(130);
79  updateArtifactCounts(selectedDataSource);
80  this.repaint();
81  }
82 
90  private void updateArtifactCounts(DataSource selectedDataSource) {
91  ((DefaultTableModel) artifactCountsTable.getModel()).setRowCount(0);
92  if (selectedDataSource != null && artifactsByTypeCountsMap.get(selectedDataSource.getId()) != null) {
93  Map<String, Long> artifactCounts = artifactsByTypeCountsMap.get(selectedDataSource.getId());
94  for (String key : artifactCounts.keySet()) {
95  ((DefaultTableModel) artifactCountsTable.getModel()).addRow(new Object[]{key, artifactCounts.get(key)});
96  }
97  }
98  artifactCountsTable.getColumnModel().getColumn(0).setPreferredWidth(230);
99  artifactCountsTable.getColumnModel().getColumn(1).setCellRenderer(rightAlignedRenderer);
100  }
101 
107  @SuppressWarnings("unchecked")
108  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
109  private void initComponents() {
110 
111  fileCountsByMimeTypeScrollPane = new javax.swing.JScrollPane();
112  fileCountsByMimeTypeTable = new javax.swing.JTable();
113  byMimeTypeLabel = new javax.swing.JLabel();
114  fileCountsByCategoryScrollPane = new javax.swing.JScrollPane();
115  fileCountsByCategoryTable = new javax.swing.JTable();
116  byCategoryLabel = new javax.swing.JLabel();
117  jLabel1 = new javax.swing.JLabel();
118  artifactCountsScrollPane = new javax.swing.JScrollPane();
119  artifactCountsTable = new javax.swing.JTable();
120 
121  fileCountsByMimeTypeTable.setModel(filesByMimeTypeTableModel);
122  fileCountsByMimeTypeScrollPane.setViewportView(fileCountsByMimeTypeTable);
123 
124  org.openide.awt.Mnemonics.setLocalizedText(byMimeTypeLabel, org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class, "DataSourceSummaryCountsPanel.byMimeTypeLabel.text")); // NOI18N
125 
126  fileCountsByCategoryTable.setModel(filesByCategoryTableModel);
127  fileCountsByCategoryScrollPane.setViewportView(fileCountsByCategoryTable);
128 
129  org.openide.awt.Mnemonics.setLocalizedText(byCategoryLabel, org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class, "DataSourceSummaryCountsPanel.byCategoryLabel.text")); // NOI18N
130 
131  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class, "DataSourceSummaryCountsPanel.jLabel1.text")); // NOI18N
132 
133  artifactCountsTable.setAutoCreateRowSorter(true);
134  artifactCountsTable.setModel(new javax.swing.table.DefaultTableModel(
135  new Object [][] {
136 
137  },
138  new String [] {
139  "Result Type", "Count"
140  }
141  ) {
142  boolean[] canEdit = new boolean [] {
143  false, false
144  };
145 
146  public boolean isCellEditable(int rowIndex, int columnIndex) {
147  return canEdit [columnIndex];
148  }
149  });
150  artifactCountsScrollPane.setViewportView(artifactCountsTable);
151 
152  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
153  this.setLayout(layout);
154  layout.setHorizontalGroup(
155  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156  .addGroup(layout.createSequentialGroup()
157  .addContainerGap()
158  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
159  .addComponent(fileCountsByMimeTypeScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
160  .addComponent(byMimeTypeLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
161  .addGap(18, 18, 18)
162  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addComponent(byCategoryLabel)
164  .addComponent(fileCountsByCategoryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
165  .addGap(18, 18, 18)
166  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
168  .addComponent(artifactCountsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE))
169  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170  );
171 
172  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {fileCountsByCategoryScrollPane, fileCountsByMimeTypeScrollPane});
173 
174  layout.setVerticalGroup(
175  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176  .addGroup(layout.createSequentialGroup()
177  .addContainerGap()
178  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
179  .addComponent(byMimeTypeLabel)
180  .addComponent(byCategoryLabel)
181  .addComponent(jLabel1))
182  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
183  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184  .addComponent(artifactCountsScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
185  .addGroup(layout.createSequentialGroup()
186  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187  .addComponent(fileCountsByMimeTypeScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
188  .addComponent(fileCountsByCategoryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
189  .addGap(0, 0, Short.MAX_VALUE)))
190  .addContainerGap())
191  );
192 
193  layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {fileCountsByCategoryScrollPane, fileCountsByMimeTypeScrollPane});
194 
195  }// </editor-fold>//GEN-END:initComponents
196 
197 
198  // Variables declaration - do not modify//GEN-BEGIN:variables
199  private javax.swing.JScrollPane artifactCountsScrollPane;
200  private javax.swing.JTable artifactCountsTable;
201  private javax.swing.JLabel byCategoryLabel;
202  private javax.swing.JLabel byMimeTypeLabel;
203  private javax.swing.JScrollPane fileCountsByCategoryScrollPane;
204  private javax.swing.JTable fileCountsByCategoryTable;
205  private javax.swing.JScrollPane fileCountsByMimeTypeScrollPane;
206  private javax.swing.JTable fileCountsByMimeTypeTable;
207  private javax.swing.JLabel jLabel1;
208  // End of variables declaration//GEN-END:variables
209 
214  @Messages({"DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.type.header=File Type",
215  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.count.header=Count"})
216  private class FilesByMimeTypeTableModel extends AbstractTableModel {
217 
218  private static final long serialVersionUID = 1L;
219  private final DataSource currentDataSource;
220  private final List<String> columnHeaders = new ArrayList<>();
221  private static final int IMAGES_ROW_INDEX = 0;
222  private static final int VIDEOS_ROW_INDEX = 1;
223  private static final int AUDIO_ROW_INDEX = 2;
224  private static final int DOCUMENTS_ROW_INDEX = 3;
225  private static final int EXECUTABLES_ROW_INDEX = 4;
226 
233  FilesByMimeTypeTableModel(DataSource selectedDataSource) {
234  columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_type_header());
235  columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_count_header());
236  currentDataSource = selectedDataSource;
237  }
238 
239  @Override
240  public int getRowCount() {
241  //should be kept equal to the number of types we are displaying in the tables
242  return 5;
243  }
244 
245  @Override
246  public int getColumnCount() {
247  return columnHeaders.size();
248  }
249 
250  @Messages({
251  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.images.row=Images",
252  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.videos.row=Videos",
253  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.audio.row=Audio",
254  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.documents.row=Documents",
255  "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.executables.row=Executables"
256  })
257  @Override
258  public Object getValueAt(int rowIndex, int columnIndex) {
259  if (columnIndex == 0) {
260  switch (rowIndex) {
261  case IMAGES_ROW_INDEX:
262  return Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_images_row();
263  case VIDEOS_ROW_INDEX:
264  return Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_videos_row();
265  case AUDIO_ROW_INDEX:
266  return Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_audio_row();
267  case DOCUMENTS_ROW_INDEX:
268  return Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_documents_row();
269  case EXECUTABLES_ROW_INDEX:
270  return Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_executables_row();
271  default:
272  break;
273  }
274  } else if (columnIndex == 1) {
275  switch (rowIndex) {
276  case 0:
277  return DataSourceInfoUtilities.getCountOfFilesForMimeTypes(currentDataSource, FileTypeUtils.FileTypeCategory.IMAGE.getMediaTypes());
278  case 1:
279  return DataSourceInfoUtilities.getCountOfFilesForMimeTypes(currentDataSource, FileTypeUtils.FileTypeCategory.VIDEO.getMediaTypes());
280  case 2:
281  return DataSourceInfoUtilities.getCountOfFilesForMimeTypes(currentDataSource, FileTypeUtils.FileTypeCategory.AUDIO.getMediaTypes());
282  case 3:
283  return DataSourceInfoUtilities.getCountOfFilesForMimeTypes(currentDataSource, FileTypeUtils.FileTypeCategory.DOCUMENTS.getMediaTypes());
284  case 4:
285  return DataSourceInfoUtilities.getCountOfFilesForMimeTypes(currentDataSource, FileTypeUtils.FileTypeCategory.EXECUTABLE.getMediaTypes());
286  default:
287  break;
288  }
289  }
290  return null;
291  }
292 
293  @Override
294  public String getColumnName(int column) {
295  return columnHeaders.get(column);
296  }
297  }
298 
303  @Messages({"DataSourceSummaryCountsPanel.FilesByCategoryTableModel.type.header=File Type",
304  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.count.header=Count"})
305  private class FilesByCategoryTableModel extends AbstractTableModel {
306 
307  private static final long serialVersionUID = 1L;
308  private final DataSource currentDataSource;
309  private final List<String> columnHeaders = new ArrayList<>();
310  private static final int ALL_FILES_ROW_INDEX = 0;
311  private static final int ALLOCATED_FILES_ROW_INDEX = 1;
312  private static final int UNALLOCATED_FILES_ROW_INDEX = 2;
313  private static final int SLACK_FILES_ROW_INDEX = 3;
314  private static final int DIRECTORIES_ROW_INDEX = 4;
321  FilesByCategoryTableModel(DataSource selectedDataSource) {
322  columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_type_header());
323  columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_count_header());
324  currentDataSource = selectedDataSource;
325  }
326 
327  @Override
328  public int getRowCount() {
329  //should be kept equal to the number of types we are displaying in the tables
330  return 5;
331  }
332 
333  @Override
334  public int getColumnCount() {
335  return columnHeaders.size();
336  }
337 
338  @Messages({
339  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.all.row=All",
340  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.allocated.row=Allocated",
341  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.unallocated.row=Unallocated",
342  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.slack.row=Slack",
343  "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.directory.row=Directory"
344  })
345  @Override
346  public Object getValueAt(int rowIndex, int columnIndex) {
347  if (columnIndex == 0) {
348  switch (rowIndex) {
349  case ALL_FILES_ROW_INDEX:
350  return Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_all_row();
351  case ALLOCATED_FILES_ROW_INDEX:
352  return Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_allocated_row();
353  case UNALLOCATED_FILES_ROW_INDEX:
354  return Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_unallocated_row();
355  case SLACK_FILES_ROW_INDEX:
356  return Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_slack_row();
357  case DIRECTORIES_ROW_INDEX:
358  return Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_directory_row();
359  default:
360  break;
361  }
362  } else if (columnIndex == 1 && currentDataSource != null) {
363  switch (rowIndex) {
364  case 0:
365  return allFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : allFilesCountsMap.get(currentDataSource.getId());
366  case 1:
367  //All files should be either allocated or unallocated as dir_flags only has two values so any file that isn't unallocated is allocated
368  Long unallocatedFilesCount = unallocatedFilesCountsMap.get(currentDataSource.getId());
369  Long allFilesCount = allFilesCountsMap.get(currentDataSource.getId());
370  if (allFilesCount == null) {
371  return 0;
372  } else if (unallocatedFilesCount == null) {
373  return allFilesCount;
374  } else {
375  return allFilesCount - unallocatedFilesCount;
376  }
377  case 2:
378  return unallocatedFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : unallocatedFilesCountsMap.get(currentDataSource.getId());
379  case 3:
380  return slackFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : slackFilesCountsMap.get(currentDataSource.getId());
381  case 4:
382  return directoriesCountsMap.get(currentDataSource.getId()) == null ? 0 : directoriesCountsMap.get(currentDataSource.getId());
383  default:
384  break;
385  }
386  }
387  return null;
388  }
389 
390  @Override
391  public String getColumnName(int column) {
392  return columnHeaders.get(column);
393  }
394  }
395 }

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.