19 package org.sleuthkit.autopsy.casemodule.datasourcesummary;
21 import java.util.ArrayList;
22 import java.util.List;
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;
37 class DataSourceSummaryCountsPanel
extends javax.swing.JPanel {
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();
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);
61 fileCountsByMimeTypeTable.getTableHeader().setReorderingAllowed(
false);
62 fileCountsByCategoryTable.getTableHeader().setReorderingAllowed(
false);
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);
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)});
98 artifactCountsTable.getColumnModel().getColumn(0).setPreferredWidth(230);
99 artifactCountsTable.getColumnModel().getColumn(1).setCellRenderer(rightAlignedRenderer);
107 @SuppressWarnings(
"unchecked")
109 private
void initComponents() {
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();
121 fileCountsByMimeTypeTable.setModel(filesByMimeTypeTableModel);
122 fileCountsByMimeTypeScrollPane.setViewportView(fileCountsByMimeTypeTable);
124 org.openide.awt.Mnemonics.setLocalizedText(byMimeTypeLabel,
org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class,
"DataSourceSummaryCountsPanel.byMimeTypeLabel.text"));
126 fileCountsByCategoryTable.setModel(filesByCategoryTableModel);
127 fileCountsByCategoryScrollPane.setViewportView(fileCountsByCategoryTable);
129 org.openide.awt.Mnemonics.setLocalizedText(byCategoryLabel,
org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class,
"DataSourceSummaryCountsPanel.byCategoryLabel.text"));
131 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(DataSourceSummaryCountsPanel.class,
"DataSourceSummaryCountsPanel.jLabel1.text"));
133 artifactCountsTable.setAutoCreateRowSorter(
true);
134 artifactCountsTable.setModel(
new javax.swing.table.DefaultTableModel(
139 "Result Type",
"Count"
142 boolean[] canEdit =
new boolean [] {
146 public boolean isCellEditable(
int rowIndex,
int columnIndex) {
147 return canEdit [columnIndex];
150 artifactCountsScrollPane.setViewportView(artifactCountsTable);
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()
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))
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))
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))
172 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {fileCountsByCategoryScrollPane, fileCountsByMimeTypeScrollPane});
174 layout.setVerticalGroup(
175 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
176 .addGroup(layout.createSequentialGroup()
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)))
193 layout.linkSize(javax.swing.SwingConstants.VERTICAL,
new java.awt.Component[] {fileCountsByCategoryScrollPane, fileCountsByMimeTypeScrollPane});
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;
214 @Messages({
"DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.type.header=File Type",
215 "DataSourceSummaryCountsPanel.FilesByMimeTypeTableModel.count.header=Count"})
218 private static final long serialVersionUID = 1L;
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;
234 columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_type_header());
235 columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByMimeTypeTableModel_count_header());
236 currentDataSource = selectedDataSource;
247 return columnHeaders.size();
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"
259 if (columnIndex == 0) {
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();
274 }
else if (columnIndex == 1) {
295 return columnHeaders.get(column);
303 @Messages({
"DataSourceSummaryCountsPanel.FilesByCategoryTableModel.type.header=File Type",
304 "DataSourceSummaryCountsPanel.FilesByCategoryTableModel.count.header=Count"})
307 private static final long serialVersionUID = 1L;
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;
322 columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_type_header());
323 columnHeaders.add(Bundle.DataSourceSummaryCountsPanel_FilesByCategoryTableModel_count_header());
324 currentDataSource = selectedDataSource;
335 return columnHeaders.size();
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"
347 if (columnIndex == 0) {
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();
362 }
else if (columnIndex == 1 && currentDataSource != null) {
365 return allFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : allFilesCountsMap.get(currentDataSource.getId());
368 Long unallocatedFilesCount = unallocatedFilesCountsMap.get(currentDataSource.getId());
369 Long allFilesCount = allFilesCountsMap.get(currentDataSource.getId());
370 if (allFilesCount == null) {
372 }
else if (unallocatedFilesCount == null) {
373 return allFilesCount;
375 return allFilesCount - unallocatedFilesCount;
378 return unallocatedFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : unallocatedFilesCountsMap.get(currentDataSource.getId());
380 return slackFilesCountsMap.get(currentDataSource.getId()) == null ? 0 : slackFilesCountsMap.get(currentDataSource.getId());
382 return directoriesCountsMap.get(currentDataSource.getId()) == null ? 0 : directoriesCountsMap.get(currentDataSource.getId());
392 return columnHeaders.get(column);
Object getValueAt(int rowIndex, int columnIndex)
String getColumnName(int column)
final DataSource currentDataSource
final DataSource currentDataSource
String getColumnName(int column)
Object getValueAt(int rowIndex, int columnIndex)