Autopsy  4.18.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestProgressSnapshotPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014-2018 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.ingest;
20 
21 import java.text.SimpleDateFormat;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.Map;
27 import javax.swing.JDialog;
28 import javax.swing.table.AbstractTableModel;
29 import javax.swing.table.TableColumn;
30 import org.apache.commons.lang3.time.DurationFormatUtils;
31 import org.openide.util.NbBundle;
32 
36 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
37 class IngestProgressSnapshotPanel extends javax.swing.JPanel {
38 
39  private final JDialog parent;
40  private final IngestProgressSnapshotProvider snapshotProvider;
41  private final IngestThreadActivitySnapshotsTableModel threadActivityTableModel;
42  private final IngestJobTableModel jobTableModel;
43  private final ModuleTableModel moduleTableModel;
44 
45  IngestProgressSnapshotPanel(JDialog parent, IngestProgressSnapshotProvider snapshotProvider) {
46  this.parent = parent;
47  this.snapshotProvider = snapshotProvider;
48  threadActivityTableModel = new IngestThreadActivitySnapshotsTableModel();
49  jobTableModel = new IngestJobTableModel();
50  moduleTableModel = new ModuleTableModel();
51  initComponents();
52  customizeComponents();
53  }
54 
55  private void customizeComponents() {
56  threadActivitySnapshotsTable.setModel(threadActivityTableModel);
57  jobTable.setModel(jobTableModel);
58  moduleTable.setModel(moduleTableModel);
59 
60  int width = snapshotsScrollPane.getPreferredSize().width;
61  for (int i = 0; i < threadActivitySnapshotsTable.getColumnCount(); ++i) {
62  TableColumn column = threadActivitySnapshotsTable.getColumnModel().getColumn(i);
63  switch (i) {
64  case 0:
65  column.setPreferredWidth(((int) (width * 0.02)));
66  break;
67  case 1:
68  column.setPreferredWidth(((int) (width * 0.20)));
69  break;
70  case 2:
71  column.setPreferredWidth(((int) (width * 0.15)));
72  break;
73  case 3:
74  column.setPreferredWidth(((int) (width * 0.35)));
75  break;
76  case 4:
77  column.setPreferredWidth(((int) (width * 0.18)));
78  break;
79  case 5:
80  column.setPreferredWidth(((int) (width * 0.10)));
81  break;
82  }
83  }
84 
85  threadActivitySnapshotsTable.setFillsViewportHeight(true);
86  }
87 
88  private class IngestThreadActivitySnapshotsTableModel extends AbstractTableModel {
89 
90  private final String[] columnNames = {NbBundle.getMessage(this.getClass(),
91  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.threadID"),
92  NbBundle.getMessage(this.getClass(),
93  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.activity"),
94  NbBundle.getMessage(this.getClass(),
95  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.dataSource"),
96  NbBundle.getMessage(this.getClass(),
97  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.file"),
98  NbBundle.getMessage(this.getClass(),
99  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.startTime"),
100  NbBundle.getMessage(this.getClass(),
101  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.elapsedTime"),
102  NbBundle.getMessage(this.getClass(),
103  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.jobID")};
105 
107  refresh();
108  }
109 
110  private void refresh() {
111  snapshots = snapshotProvider.getIngestThreadActivitySnapshots();
112  fireTableDataChanged();
113  }
114 
115  @Override
116  public int getRowCount() {
117  return snapshots.size();
118  }
119 
120  @Override
121  public int getColumnCount() {
122  return columnNames.length;
123  }
124 
125  @Override
126  public String getColumnName(int col) {
127  return columnNames[col];
128  }
129 
130  @Override
131  public Object getValueAt(int rowIndex, int columnIndex) {
132  IngestManager.IngestThreadActivitySnapshot snapshot = snapshots.get(rowIndex);
133  Object cellValue;
134  switch (columnIndex) {
135  case 0:
136  cellValue = snapshot.getThreadId();
137  break;
138  case 1:
139  cellValue = snapshot.getActivity();
140  break;
141  case 2:
142  cellValue = snapshot.getDataSourceName();
143  break;
144  case 3:
145  cellValue = snapshot.getFileName();
146  break;
147  case 4:
148  cellValue = snapshot.getStartTime();
149  break;
150  case 5:
151  Date now = new Date();
152  long elapsedTime = now.getTime() - snapshot.getStartTime().getTime();
153  cellValue = DurationFormatUtils.formatDurationHMS(elapsedTime);
154  break;
155  case 6:
156  cellValue = snapshot.getIngestJobId();
157  break;
158  default:
159  cellValue = null;
160  break;
161  }
162  return cellValue;
163  }
164  }
165 
166  private class IngestJobTableModel extends AbstractTableModel {
167 
168  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.jobID"),
169  NbBundle.getMessage(this.getClass(),
170  "IngestJobTableModel.colName.dataSource"),
171  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.start"),
172  NbBundle.getMessage(this.getClass(),
173  "IngestJobTableModel.colName.numProcessed"),
174  NbBundle.getMessage(this.getClass(),
175  "IngestJobTableModel.colName.filesPerSec"),
176  NbBundle.getMessage(this.getClass(),
177  "IngestJobTableModel.colName.inProgress"),
178  NbBundle.getMessage(this.getClass(),
179  "IngestJobTableModel.colName.filesQueued"),
180  NbBundle.getMessage(this.getClass(),
181  "IngestJobTableModel.colName.dirQueued"),
182  NbBundle.getMessage(this.getClass(),
183  "IngestJobTableModel.colName.rootQueued"),
184  NbBundle.getMessage(this.getClass(),
185  "IngestJobTableModel.colName.streamingQueued"),
186  NbBundle.getMessage(this.getClass(),
187  "IngestJobTableModel.colName.dsQueued")};
188  private List<Snapshot> jobSnapshots;
189 
191  refresh();
192  }
193 
194  private void refresh() {
195  jobSnapshots = snapshotProvider.getIngestJobSnapshots();
196  fireTableDataChanged();
197  }
198 
199  @Override
200  public int getRowCount() {
201  return jobSnapshots.size();
202  }
203 
204  @Override
205  public int getColumnCount() {
206  return columnNames.length;
207  }
208 
209  @Override
210  public String getColumnName(int col) {
211  return columnNames[col];
212  }
213 
214  @Override
215  public Object getValueAt(int rowIndex, int columnIndex) {
216  Snapshot snapShot = jobSnapshots.get(rowIndex);
217  Object cellValue;
218  switch (columnIndex) {
219  case 0:
220  cellValue = snapShot.getJobId();
221  break;
222  case 1:
223  cellValue = snapShot.getDataSource();
224  break;
225  case 2:
226  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
227  cellValue = dateFormat.format(new Date(snapShot.getJobStartTime()));
228  break;
229  case 3:
230  cellValue = snapShot.getFilesProcessed();
231  break;
232  case 4:
233  cellValue = snapShot.getSpeed();
234  break;
235  case 5:
236  cellValue = snapShot.getRunningListSize();
237  break;
238  case 6:
239  cellValue = snapShot.getFileQueueSize();
240  break;
241  case 7:
242  cellValue = snapShot.getDirQueueSize();
243  break;
244  case 8:
245  cellValue = snapShot.getRootQueueSize();
246  break;
247  case 9:
248  cellValue = snapShot.getStreamingQueueSize();
249  break;
250  case 10:
251  cellValue = snapShot.getDsQueueSize();
252  break;
253  default:
254  cellValue = null;
255  break;
256  }
257  return cellValue;
258  }
259  }
260 
261  private class ModuleTableModel extends AbstractTableModel {
262 
263  private class ModuleStats implements Comparable<ModuleStats> {
264 
265  private final String name;
266  private final long duration;
267 
268  ModuleStats(String name, long duration) {
269  this.name = name;
270  this.duration = duration;
271  }
272 
276  protected String getName() {
277  return name;
278  }
279 
283  protected long getDuration() {
284  return duration;
285  }
286 
287  @Override
288  public int compareTo(ModuleStats o) {
289  if (duration > o.getDuration()) {
290  return -1;
291  } else if (duration == o.getDuration()) {
292  return 0;
293  } else {
294  return 1;
295  }
296  }
297 
298  }
299  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "ModuleTableModel.colName.module"),
300  NbBundle.getMessage(this.getClass(),
301  "ModuleTableModel.colName.duration")};
302  private final List<ModuleStats> moduleStats = new ArrayList<>();
303  private long totalTime;
304 
305  private ModuleTableModel() {
306  refresh();
307  }
308 
309  private void refresh() {
310  Map<String, Long> moduleStatMap = snapshotProvider.getModuleRunTimes();
311  moduleStats.clear();
312  totalTime = 0;
313  for (String k : moduleStatMap.keySet()) {
314  moduleStats.add(new ModuleStats(k, moduleStatMap.get(k)));
315  totalTime += moduleStatMap.get(k);
316  }
317  Collections.sort(moduleStats);
318  fireTableDataChanged();
319  }
320 
321  @Override
322  public int getRowCount() {
323  return moduleStats.size();
324  }
325 
326  @Override
327  public int getColumnCount() {
328  return columnNames.length;
329  }
330 
331  @Override
332  public String getColumnName(int col) {
333  return columnNames[col];
334  }
335 
336  @Override
337  public Object getValueAt(int rowIndex, int columnIndex) {
338  ModuleStats moduleStat = moduleStats.get(rowIndex);
339  Object cellValue;
340  switch (columnIndex) {
341  case 0:
342  cellValue = moduleStat.getName();
343  break;
344  case 1:
345  cellValue = DurationFormatUtils.formatDurationHMS(moduleStat.getDuration()) + " (" + (moduleStat.getDuration() * 100) / totalTime + "%)";
346  break;
347 
348  default:
349  cellValue = null;
350  break;
351  }
352  return cellValue;
353  }
354  }
355 
361  @SuppressWarnings("unchecked")
362  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
363  private void initComponents() {
364  java.awt.GridBagConstraints gridBagConstraints;
365 
366  snapshotsScrollPane = new javax.swing.JScrollPane();
367  threadActivitySnapshotsTable = new javax.swing.JTable();
368  jobScrollPane = new javax.swing.JScrollPane();
369  jobTable = new javax.swing.JTable();
370  refreshButton = new javax.swing.JButton();
371  closeButton = new javax.swing.JButton();
372  moduleScrollPane = new javax.swing.JScrollPane();
373  moduleTable = new javax.swing.JTable();
374 
375  setMinimumSize(new java.awt.Dimension(500, 500));
376  setPreferredSize(new java.awt.Dimension(1100, 500));
377  setLayout(new java.awt.GridBagLayout());
378 
379  threadActivitySnapshotsTable.setModel(new javax.swing.table.DefaultTableModel(
380  new Object [][] {
381 
382  },
383  new String [] {
384 
385  }
386  ));
387  snapshotsScrollPane.setViewportView(threadActivitySnapshotsTable);
388 
389  gridBagConstraints = new java.awt.GridBagConstraints();
390  gridBagConstraints.gridx = 0;
391  gridBagConstraints.gridy = 0;
392  gridBagConstraints.gridwidth = 2;
393  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
394  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
395  gridBagConstraints.weightx = 1.0;
396  gridBagConstraints.weighty = 1.0;
397  gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 10);
398  add(snapshotsScrollPane, gridBagConstraints);
399 
400  jobTable.setModel(new javax.swing.table.DefaultTableModel(
401  new Object [][] {
402 
403  },
404  new String [] {
405 
406  }
407  ));
408  jobScrollPane.setViewportView(jobTable);
409 
410  gridBagConstraints = new java.awt.GridBagConstraints();
411  gridBagConstraints.gridx = 0;
412  gridBagConstraints.gridy = 1;
413  gridBagConstraints.gridwidth = 2;
414  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
415  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
416  gridBagConstraints.weightx = 1.0;
417  gridBagConstraints.weighty = 1.0;
418  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
419  add(jobScrollPane, gridBagConstraints);
420 
421  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.refreshButton.text")); // NOI18N
422  refreshButton.addActionListener(new java.awt.event.ActionListener() {
423  public void actionPerformed(java.awt.event.ActionEvent evt) {
424  refreshButtonActionPerformed(evt);
425  }
426  });
427  gridBagConstraints = new java.awt.GridBagConstraints();
428  gridBagConstraints.gridx = 0;
429  gridBagConstraints.gridy = 3;
430  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
431  gridBagConstraints.weightx = 1.0;
432  add(refreshButton, gridBagConstraints);
433 
434  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.closeButton.text")); // NOI18N
435  closeButton.addActionListener(new java.awt.event.ActionListener() {
436  public void actionPerformed(java.awt.event.ActionEvent evt) {
437  closeButtonActionPerformed(evt);
438  }
439  });
440  gridBagConstraints = new java.awt.GridBagConstraints();
441  gridBagConstraints.gridx = 1;
442  gridBagConstraints.gridy = 3;
443  gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
444  gridBagConstraints.insets = new java.awt.Insets(6, 6, 11, 10);
445  add(closeButton, gridBagConstraints);
446 
447  moduleTable.setModel(new javax.swing.table.DefaultTableModel(
448  new Object [][] {
449 
450  },
451  new String [] {
452 
453  }
454  ));
455  moduleScrollPane.setViewportView(moduleTable);
456 
457  gridBagConstraints = new java.awt.GridBagConstraints();
458  gridBagConstraints.gridx = 0;
459  gridBagConstraints.gridy = 2;
460  gridBagConstraints.gridwidth = 2;
461  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
462  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
463  gridBagConstraints.weightx = 1.0;
464  gridBagConstraints.weighty = 1.0;
465  gridBagConstraints.insets = new java.awt.Insets(6, 10, 0, 10);
466  add(moduleScrollPane, gridBagConstraints);
467  }// </editor-fold>//GEN-END:initComponents
468 
469  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
470  parent.dispose();
471  }//GEN-LAST:event_closeButtonActionPerformed
472 
473  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
474  threadActivityTableModel.refresh();
475  jobTableModel.refresh();
476  moduleTableModel.refresh();
477  }//GEN-LAST:event_refreshButtonActionPerformed
478  // Variables declaration - do not modify//GEN-BEGIN:variables
479  private javax.swing.JButton closeButton;
480  private javax.swing.JScrollPane jobScrollPane;
481  private javax.swing.JTable jobTable;
482  private javax.swing.JScrollPane moduleScrollPane;
483  private javax.swing.JTable moduleTable;
484  private javax.swing.JButton refreshButton;
485  private javax.swing.JScrollPane snapshotsScrollPane;
486  private javax.swing.JTable threadActivitySnapshotsTable;
487  // End of variables declaration//GEN-END:variables
488 }

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