Autopsy  4.1
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 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 public class IngestProgressSnapshotPanel extends javax.swing.JPanel {
37 
38  private final JDialog parent;
42 
43  IngestProgressSnapshotPanel(JDialog parent) {
44  this.parent = parent;
45  threadActivityTableModel = new IngestThreadActivitySnapshotsTableModel();
46  jobTableModel = new IngestJobTableModel();
47  moduleTableModel = new ModuleTableModel();
50  }
51 
52  private void customizeComponents() {
53  threadActivitySnapshotsTable.setModel(threadActivityTableModel);
54  jobTable.setModel(jobTableModel);
55  moduleTable.setModel(moduleTableModel);
56 
57  int width = snapshotsScrollPane.getPreferredSize().width;
58  for (int i = 0; i < threadActivitySnapshotsTable.getColumnCount(); ++i) {
59  TableColumn column = threadActivitySnapshotsTable.getColumnModel().getColumn(i);
60  switch (i) {
61  case 0:
62  column.setPreferredWidth(((int) (width * 0.02)));
63  break;
64  case 1:
65  column.setPreferredWidth(((int) (width * 0.20)));
66  break;
67  case 2:
68  column.setPreferredWidth(((int) (width * 0.15)));
69  break;
70  case 3:
71  column.setPreferredWidth(((int) (width * 0.35)));
72  break;
73  case 4:
74  column.setPreferredWidth(((int) (width * 0.18)));
75  break;
76  case 5:
77  column.setPreferredWidth(((int) (width * 0.10)));
78  break;
79  }
80  }
81 
82  threadActivitySnapshotsTable.setFillsViewportHeight(true);
83  }
84 
85  private class IngestThreadActivitySnapshotsTableModel extends AbstractTableModel {
86 
87  private final String[] columnNames = {NbBundle.getMessage(this.getClass(),
88  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.threadID"),
89  NbBundle.getMessage(this.getClass(),
90  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.activity"),
91  NbBundle.getMessage(this.getClass(),
92  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.dataSource"),
93  NbBundle.getMessage(this.getClass(),
94  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.file"),
95  NbBundle.getMessage(this.getClass(),
96  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.startTime"),
97  NbBundle.getMessage(this.getClass(),
98  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.elapsedTime"),
99  NbBundle.getMessage(this.getClass(),
100  "IngestProgressSnapshotPanel.SnapshotsTableModel.colNames.jobID")};
102 
104  refresh();
105  }
106 
107  private void refresh() {
108  snapshots = IngestManager.getInstance().getIngestThreadActivitySnapshots();
109  fireTableDataChanged();
110  }
111 
112  @Override
113  public int getRowCount() {
114  return snapshots.size();
115  }
116 
117  @Override
118  public int getColumnCount() {
119  return columnNames.length;
120  }
121 
122  @Override
123  public String getColumnName(int col) {
124  return columnNames[col];
125  }
126 
127  @Override
128  public Object getValueAt(int rowIndex, int columnIndex) {
129  IngestManager.IngestThreadActivitySnapshot snapshot = snapshots.get(rowIndex);
130  Object cellValue;
131  switch (columnIndex) {
132  case 0:
133  cellValue = snapshot.getThreadId();
134  break;
135  case 1:
136  cellValue = snapshot.getActivity();
137  break;
138  case 2:
139  cellValue = snapshot.getDataSourceName();
140  break;
141  case 3:
142  cellValue = snapshot.getFileName();
143  break;
144  case 4:
145  cellValue = snapshot.getStartTime();
146  break;
147  case 5:
148  Date now = new Date();
149  long elapsedTime = now.getTime() - snapshot.getStartTime().getTime();
150  cellValue = DurationFormatUtils.formatDurationHMS(elapsedTime);
151  break;
152  case 6:
153  cellValue = snapshot.getJobId();
154  break;
155  default:
156  cellValue = null;
157  break;
158  }
159  return cellValue;
160  }
161  }
162 
163  private class IngestJobTableModel extends AbstractTableModel {
164 
165  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.jobID"),
166  NbBundle.getMessage(this.getClass(),
167  "IngestJobTableModel.colName.dataSource"),
168  NbBundle.getMessage(this.getClass(), "IngestJobTableModel.colName.start"),
169  NbBundle.getMessage(this.getClass(),
170  "IngestJobTableModel.colName.numProcessed"),
171  NbBundle.getMessage(this.getClass(),
172  "IngestJobTableModel.colName.filesPerSec"),
173  NbBundle.getMessage(this.getClass(),
174  "IngestJobTableModel.colName.inProgress"),
175  NbBundle.getMessage(this.getClass(),
176  "IngestJobTableModel.colName.filesQueued"),
177  NbBundle.getMessage(this.getClass(),
178  "IngestJobTableModel.colName.dirQueued"),
179  NbBundle.getMessage(this.getClass(),
180  "IngestJobTableModel.colName.rootQueued"),
181  NbBundle.getMessage(this.getClass(),
182  "IngestJobTableModel.colName.dsQueued")};
183  private List<DataSourceIngestJob.Snapshot> jobSnapshots;
184 
186  refresh();
187  }
188 
189  private void refresh() {
190  jobSnapshots = IngestManager.getInstance().getIngestJobSnapshots();
191  fireTableDataChanged();
192  }
193 
194  @Override
195  public int getRowCount() {
196  return jobSnapshots.size();
197  }
198 
199  @Override
200  public int getColumnCount() {
201  return columnNames.length;
202  }
203 
204  @Override
205  public String getColumnName(int col) {
206  return columnNames[col];
207  }
208 
209  @Override
210  public Object getValueAt(int rowIndex, int columnIndex) {
211  DataSourceIngestJob.Snapshot snapShot = jobSnapshots.get(rowIndex);
212  Object cellValue;
213  switch (columnIndex) {
214  case 0:
215  cellValue = snapShot.getJobId();
216  break;
217  case 1:
218  cellValue = snapShot.getDataSource();
219  break;
220  case 2:
221  SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
222  cellValue = dateFormat.format(new Date(snapShot.getJobStartTime()));
223  break;
224  case 3:
225  cellValue = snapShot.getFilesProcessed();
226  break;
227  case 4:
228  cellValue = snapShot.getSpeed();
229  break;
230  case 5:
231  cellValue = snapShot.getRunningListSize();
232  break;
233  case 6:
234  cellValue = snapShot.getFileQueueSize();
235  break;
236  case 7:
237  cellValue = snapShot.getDirQueueSize();
238  break;
239  case 8:
240  cellValue = snapShot.getRootQueueSize();
241  break;
242  case 9:
243  cellValue = snapShot.getDsQueueSize();
244  break;
245  default:
246  cellValue = null;
247  break;
248  }
249  return cellValue;
250  }
251  }
252 
253  private class ModuleTableModel extends AbstractTableModel {
254 
255  private class ModuleStats implements Comparable<ModuleStats> {
256 
257  private final String name;
258  private final long duration;
259 
260  ModuleStats(String name, long duration) {
261  this.name = name;
262  this.duration = duration;
263  }
264 
268  protected String getName() {
269  return name;
270  }
271 
275  protected long getDuration() {
276  return duration;
277  }
278 
279  @Override
280  public int compareTo(ModuleStats o) {
281  if (duration > o.getDuration()) {
282  return -1;
283  } else if (duration == o.getDuration()) {
284  return 0;
285  } else {
286  return 1;
287  }
288  }
289 
290  }
291  private final String[] columnNames = {NbBundle.getMessage(this.getClass(), "ModuleTableModel.colName.module"),
292  NbBundle.getMessage(this.getClass(),
293  "ModuleTableModel.colName.duration")};
294  private final List<ModuleStats> moduleStats = new ArrayList<>();
295  private long totalTime;
296 
297  private ModuleTableModel() {
298  refresh();
299  }
300 
301  private void refresh() {
302  Map<String, Long> moduleStatMap = IngestManager.getInstance().getModuleRunTimes();
303  moduleStats.clear();
304  totalTime = 0;
305  for (String k : moduleStatMap.keySet()) {
306  moduleStats.add(new ModuleStats(k, moduleStatMap.get(k)));
307  totalTime += moduleStatMap.get(k);
308  }
309  Collections.sort(moduleStats);
310  fireTableDataChanged();
311  }
312 
313  @Override
314  public int getRowCount() {
315  return moduleStats.size();
316  }
317 
318  @Override
319  public int getColumnCount() {
320  return columnNames.length;
321  }
322 
323  @Override
324  public String getColumnName(int col) {
325  return columnNames[col];
326  }
327 
328  @Override
329  public Object getValueAt(int rowIndex, int columnIndex) {
330  ModuleStats moduleStat = moduleStats.get(rowIndex);
331  Object cellValue;
332  switch (columnIndex) {
333  case 0:
334  cellValue = moduleStat.getName();
335  break;
336  case 1:
337  cellValue = DurationFormatUtils.formatDurationHMS(moduleStat.getDuration()) + " (" + (moduleStat.getDuration() * 100) / totalTime + "%)";
338  break;
339 
340  default:
341  cellValue = null;
342  break;
343  }
344  return cellValue;
345  }
346  }
347 
353  @SuppressWarnings("unchecked")
354  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
355  private void initComponents() {
356 
357  snapshotsScrollPane = new javax.swing.JScrollPane();
358  threadActivitySnapshotsTable = new javax.swing.JTable();
359  jobScrollPane = new javax.swing.JScrollPane();
360  jobTable = new javax.swing.JTable();
361  refreshButton = new javax.swing.JButton();
362  closeButton = new javax.swing.JButton();
363  moduleScrollPane = new javax.swing.JScrollPane();
364  moduleTable = new javax.swing.JTable();
365 
366  threadActivitySnapshotsTable.setModel(new javax.swing.table.DefaultTableModel(
367  new Object [][] {
368 
369  },
370  new String [] {
371 
372  }
373  ));
375 
376  jobTable.setModel(new javax.swing.table.DefaultTableModel(
377  new Object [][] {
378 
379  },
380  new String [] {
381 
382  }
383  ));
384  jobScrollPane.setViewportView(jobTable);
385 
386  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.refreshButton.text")); // NOI18N
387  refreshButton.addActionListener(new java.awt.event.ActionListener() {
388  public void actionPerformed(java.awt.event.ActionEvent evt) {
390  }
391  });
392 
393  org.openide.awt.Mnemonics.setLocalizedText(closeButton, org.openide.util.NbBundle.getMessage(IngestProgressSnapshotPanel.class, "IngestProgressSnapshotPanel.closeButton.text")); // NOI18N
394  closeButton.addActionListener(new java.awt.event.ActionListener() {
395  public void actionPerformed(java.awt.event.ActionEvent evt) {
397  }
398  });
399 
400  moduleTable.setModel(new javax.swing.table.DefaultTableModel(
401  new Object [][] {
402 
403  },
404  new String [] {
405 
406  }
407  ));
408  moduleScrollPane.setViewportView(moduleTable);
409 
410  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
411  this.setLayout(layout);
412  layout.setHorizontalGroup(
413  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
414  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
415  .addContainerGap()
416  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
417  .addComponent(snapshotsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 881, Short.MAX_VALUE)
418  .addGroup(layout.createSequentialGroup()
419  .addGap(0, 0, Short.MAX_VALUE)
420  .addComponent(refreshButton)
421  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
422  .addComponent(closeButton))
423  .addComponent(jobScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 881, Short.MAX_VALUE)
424  .addComponent(moduleScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 881, Short.MAX_VALUE))
425  .addContainerGap())
426  );
427 
428  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {closeButton, refreshButton});
429 
430  layout.setVerticalGroup(
431  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
432  .addGroup(layout.createSequentialGroup()
433  .addContainerGap()
434  .addComponent(snapshotsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
435  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
436  .addComponent(jobScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
437  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
438  .addComponent(moduleScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
439  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
440  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
441  .addComponent(refreshButton)
442  .addComponent(closeButton))
443  .addContainerGap())
444  );
445 
446  layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {closeButton, refreshButton});
447 
448  }// </editor-fold>//GEN-END:initComponents
449 
450  private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
451  parent.dispose();
452  }//GEN-LAST:event_closeButtonActionPerformed
453 
454  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
455  threadActivityTableModel.refresh();
456  jobTableModel.refresh();
457  moduleTableModel.refresh();
458  }//GEN-LAST:event_refreshButtonActionPerformed
459  // Variables declaration - do not modify//GEN-BEGIN:variables
460  private javax.swing.JButton closeButton;
461  private javax.swing.JScrollPane jobScrollPane;
462  private javax.swing.JTable jobTable;
463  private javax.swing.JScrollPane moduleScrollPane;
464  private javax.swing.JTable moduleTable;
465  private javax.swing.JButton refreshButton;
466  private javax.swing.JScrollPane snapshotsScrollPane;
467  private javax.swing.JTable threadActivitySnapshotsTable;
468  // End of variables declaration//GEN-END:variables
469 }
static synchronized IngestManager getInstance()
final IngestThreadActivitySnapshotsTableModel threadActivityTableModel

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.