Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportVisualPanel2.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.report.infrastructure;
20 
21 import java.awt.Component;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Map.Entry;
32 import java.util.logging.Level;
33 import javax.swing.JCheckBox;
34 import javax.swing.JFrame;
35 import javax.swing.JLabel;
36 import javax.swing.JList;
37 import javax.swing.JPanel;
38 import javax.swing.ListCellRenderer;
39 import javax.swing.ListModel;
40 import javax.swing.event.ListDataListener;
41 import org.openide.util.NbBundle;
42 import org.openide.windows.WindowManager;
47 import org.sleuthkit.datamodel.BlackboardArtifact;
48 import org.sleuthkit.datamodel.TagName;
49 import org.sleuthkit.datamodel.TskCoreException;
50 import org.sleuthkit.datamodel.TskData;
51 
55 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
56 final class ReportVisualPanel2 extends JPanel {
57 
58  private final ReportWizardPanel2 wizPanel;
59  private final Map<String, Boolean> tagStates = new LinkedHashMap<>();
60  private final List<String> tags = new ArrayList<>();
61  final ArtifactSelectionDialog dialog = new ArtifactSelectionDialog((JFrame) WindowManager.getDefault().getMainWindow(), true);
62  private Map<BlackboardArtifact.Type, Boolean> artifactStates = new HashMap<>();
63  private List<BlackboardArtifact.Type> artifacts = new ArrayList<>();
64  private final boolean useCaseSpecificData;
65  private TagsListModel tagsModel;
66  private TagsListRenderer tagsRenderer;
67 
71  public ReportVisualPanel2(ReportWizardPanel2 wizPanel, boolean useCaseSpecificData, TableReportSettings settings) {
72  this.useCaseSpecificData = useCaseSpecificData;
73  initComponents();
74  initTags();
75  initArtifactTypes();
76  this.wizPanel = wizPanel;
77 
78  this.allResultsRadioButton.addItemListener(new ItemListener() {
79  @Override
80  public void itemStateChanged(ItemEvent e) {
81  tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
82  selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
83  deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
84  advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
85  updateFinishButton();
86  }
87  });
88  this.allTaggedResultsRadioButton.addItemListener(new ItemListener() {
89  @Override
90  public void itemStateChanged(ItemEvent e) {
91  tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
92  selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
93  deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
94  advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
95  updateFinishButton();
96  }
97  });
98  this.specificTaggedResultsRadioButton.addItemListener(new ItemListener() {
99  @Override
100  public void itemStateChanged(ItemEvent e) {
101  tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
102  selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
103  deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
104  advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
105  updateFinishButton();
106  }
107  });
108 
109  // enable things based on input settings
110  advancedButton.setEnabled(useCaseSpecificData);
111  specificTaggedResultsRadioButton.setEnabled(useCaseSpecificData);
112  TableReportSettings.TableReportOption type = TableReportSettings.TableReportOption.ALL_RESULTS;
113  if (settings != null) {
114  type = settings.getSelectedReportOption();
115  }
116  switch (type) {
117  case ALL_TAGGED_RESULTS:
118  allTaggedResultsRadioButton.setSelected(true);
119  tagsList.setEnabled(false);
120  selectAllButton.setEnabled(false);
121  deselectAllButton.setEnabled(false);
122  break;
123  case SPECIFIC_TAGGED_RESULTS:
124  specificTaggedResultsRadioButton.setSelected(useCaseSpecificData);
125  tagsList.setEnabled(useCaseSpecificData);
126  selectAllButton.setEnabled(useCaseSpecificData);
127  deselectAllButton.setEnabled(useCaseSpecificData);
128  break;
129  case ALL_RESULTS:
130  default:
131  allResultsRadioButton.setSelected(true);
132  tagsList.setEnabled(false);
133  selectAllButton.setEnabled(false);
134  deselectAllButton.setEnabled(false);
135  break;
136  }
137  updateFinishButton();
138  }
139 
140  // Initialize the list of Tags
141  private void initTags() {
142 
143  List<TagName> tagNamesInUse = new ArrayList<>();
144  // NOTE: we do not want to load tag names that came from persisted settings
145  // because there might have been new/additional tag names that have been added
146  // by user. We should read tag names from the database each time.
147  try {
148  // only try to load tag names if we are displaying case specific data, otherwise
149  // we will be displaying case specific data in command line wizard if there is
150  // a case open in the background
151  if (useCaseSpecificData) {
152  // get tags and artifact types from current case
153  tagNamesInUse = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
154  }
155  } catch (TskCoreException | NoCurrentCaseException ex) {
156  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
157  return;
158  }
159 
160  for (TagName tagName : tagNamesInUse) {
161  String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() : "";
162  tagStates.put(tagName.getDisplayName() + notableString, Boolean.FALSE);
163  }
164  tags.addAll(tagStates.keySet());
165 
166  tagsModel = new TagsListModel();
167  tagsRenderer = new TagsListRenderer();
168  tagsList.setModel(tagsModel);
169  tagsList.setCellRenderer(tagsRenderer);
170  tagsList.setVisibleRowCount(-1);
171 
172  // Add the ability to enable and disable Tag checkboxes to the list
173  tagsList.addMouseListener(new MouseAdapter() {
174  @Override
175  public void mousePressed(MouseEvent evt) {
176  if (!specificTaggedResultsRadioButton.isSelected()) {
177  return;
178  }
179  int index = tagsList.locationToIndex(evt.getPoint());
180  if (index < tagsModel.getSize() && index >= 0) {
181  String value = tagsModel.getElementAt(index);
182  tagStates.put(value, !tagStates.get(value));
183  tagsList.repaint();
184  updateFinishButton();
185  }
186  }
187  });
188  }
189 
190  // Initialize the list of Artifacts
191  @SuppressWarnings("deprecation")
192  private void initArtifactTypes() {
193 
194  // only try to load existing artifact types if we are displaying case
195  // specific data, otherwise there may not be a case open.
196  if (!useCaseSpecificData) {
197  return;
198  }
199 
200  try {
201  Case openCase = Case.getCurrentCaseThrows();
202  ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>();
203  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
204  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
205  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
206  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
207  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
208  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
209  doNotReport.add(new BlackboardArtifact.Type(
210  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID(),
211  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getLabel(),
212  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getDisplayName()));
213  doNotReport.add(new BlackboardArtifact.Type(
214  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getTypeID(),
215  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getLabel(),
216  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getDisplayName()));
217  // get artifact types that exist in the current case
218  artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
219 
220  artifacts.removeAll(doNotReport);
221 
222  artifactStates = new HashMap<>();
223  for (BlackboardArtifact.Type type : artifacts) {
224  artifactStates.put(type, Boolean.TRUE);
225  }
226  } catch (TskCoreException | NoCurrentCaseException ex) {
227  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex); //NON-NLS
228  }
229  }
230 
231  @Override
232  public String getName() {
233  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel2.getName.text");
234  }
235 
241  Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
242  return artifactStates;
243  }
244 
248  Map<String, Boolean> getTagStates() {
249  return tagStates;
250  }
251 
257  private boolean areTagsSelected() {
258  boolean result = false;
259  for (Entry<String, Boolean> entry : tagStates.entrySet()) {
260  if (entry.getValue()) {
261  result = true;
262  break;
263  }
264  }
265  return result;
266  }
267 
272  private void updateFinishButton() {
273  if (specificTaggedResultsRadioButton.isSelected()) {
274  wizPanel.setFinish(areTagsSelected());
275  } else {
276  wizPanel.setFinish(true);
277  }
278  }
279 
284  TableReportSettings.TableReportOption getSelectedReportType() {
285  if (allTaggedResultsRadioButton.isSelected()) {
286  return TableReportSettings.TableReportOption.ALL_TAGGED_RESULTS;
287  } else if (specificTaggedResultsRadioButton.isSelected()) {
288  return TableReportSettings.TableReportOption.SPECIFIC_TAGGED_RESULTS;
289  }
290  return TableReportSettings.TableReportOption.ALL_RESULTS;
291  }
292 
298  void setAllTaggedResultsSelected(boolean selected) {
299  for (String tag : tags) {
300  tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
301  }
302  tagsList.repaint();
303  }
304 
310  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
311  private void initComponents() {
312 
313  optionsButtonGroup = new javax.swing.ButtonGroup();
314  specificTaggedResultsRadioButton = new javax.swing.JRadioButton();
315  allResultsRadioButton = new javax.swing.JRadioButton();
316  dataLabel = new javax.swing.JLabel();
317  selectAllButton = new javax.swing.JButton();
318  deselectAllButton = new javax.swing.JButton();
319  tagsScrollPane = new javax.swing.JScrollPane();
320  tagsList = new javax.swing.JList<>();
321  advancedButton = new javax.swing.JButton();
322  allTaggedResultsRadioButton = new javax.swing.JRadioButton();
323 
324  setPreferredSize(new java.awt.Dimension(650, 250));
325 
326  optionsButtonGroup.add(specificTaggedResultsRadioButton);
327  org.openide.awt.Mnemonics.setLocalizedText(specificTaggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.specificTaggedResultsRadioButton.text")); // NOI18N
328 
329  optionsButtonGroup.add(allResultsRadioButton);
330  org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allResultsRadioButton.text")); // NOI18N
331  allResultsRadioButton.addActionListener(new java.awt.event.ActionListener() {
332  public void actionPerformed(java.awt.event.ActionEvent evt) {
333  allResultsRadioButtonActionPerformed(evt);
334  }
335  });
336 
337  org.openide.awt.Mnemonics.setLocalizedText(dataLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.dataLabel.text")); // NOI18N
338 
339  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.selectAllButton.text")); // NOI18N
340  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
341  public void actionPerformed(java.awt.event.ActionEvent evt) {
342  selectAllButtonActionPerformed(evt);
343  }
344  });
345 
346  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.deselectAllButton.text")); // NOI18N
347  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
348  public void actionPerformed(java.awt.event.ActionEvent evt) {
349  deselectAllButtonActionPerformed(evt);
350  }
351  });
352 
353  tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
354  tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
355  tagsScrollPane.setViewportView(tagsList);
356 
357  org.openide.awt.Mnemonics.setLocalizedText(advancedButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.advancedButton.text")); // NOI18N
358  advancedButton.addActionListener(new java.awt.event.ActionListener() {
359  public void actionPerformed(java.awt.event.ActionEvent evt) {
360  advancedButtonActionPerformed(evt);
361  }
362  });
363 
364  optionsButtonGroup.add(allTaggedResultsRadioButton);
365  org.openide.awt.Mnemonics.setLocalizedText(allTaggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allTaggedResultsRadioButton.text")); // NOI18N
366  allTaggedResultsRadioButton.addActionListener(new java.awt.event.ActionListener() {
367  public void actionPerformed(java.awt.event.ActionEvent evt) {
368  allTaggedResultsRadioButtonActionPerformed(evt);
369  }
370  });
371 
372  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
373  this.setLayout(layout);
374  layout.setHorizontalGroup(
375  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
376  .addGroup(layout.createSequentialGroup()
377  .addContainerGap()
378  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
379  .addGroup(layout.createSequentialGroup()
380  .addGap(27, 27, 27)
381  .addComponent(tagsScrollPane)
382  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
383  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
384  .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
385  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
386  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
387  .addGroup(layout.createSequentialGroup()
388  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
389  .addComponent(allTaggedResultsRadioButton)
390  .addComponent(dataLabel)
391  .addComponent(allResultsRadioButton)
392  .addComponent(specificTaggedResultsRadioButton))
393  .addGap(0, 402, Short.MAX_VALUE)))
394  .addContainerGap())
395  );
396 
397  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
398 
399  layout.setVerticalGroup(
400  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401  .addGroup(layout.createSequentialGroup()
402  .addContainerGap()
403  .addComponent(dataLabel)
404  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
405  .addComponent(allResultsRadioButton)
406  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
407  .addComponent(allTaggedResultsRadioButton)
408  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
409  .addComponent(specificTaggedResultsRadioButton)
410  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
411  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
412  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
413  .addComponent(selectAllButton)
414  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
415  .addComponent(deselectAllButton)
416  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
417  .addComponent(advancedButton))
418  .addComponent(tagsScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
419  .addContainerGap())
420  );
421  }// </editor-fold>//GEN-END:initComponents
422 
423  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
424  setAllTaggedResultsSelected(true);
425  wizPanel.setFinish(true);
426  }//GEN-LAST:event_selectAllButtonActionPerformed
427 
428  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
429  setAllTaggedResultsSelected(false);
430  wizPanel.setFinish(false);
431  }//GEN-LAST:event_deselectAllButtonActionPerformed
432 
433  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
434  artifactStates = dialog.display();
435  }//GEN-LAST:event_advancedButtonActionPerformed
436 
437  private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allResultsRadioButtonActionPerformed
438  setAllTaggedResultsSelected(false);
439  }//GEN-LAST:event_allResultsRadioButtonActionPerformed
440 
441  private void allTaggedResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allTaggedResultsRadioButtonActionPerformed
442  setAllTaggedResultsSelected(true);
443  }//GEN-LAST:event_allTaggedResultsRadioButtonActionPerformed
444 
445  // Variables declaration - do not modify//GEN-BEGIN:variables
446  private javax.swing.JButton advancedButton;
447  private javax.swing.JRadioButton allResultsRadioButton;
448  private javax.swing.JRadioButton allTaggedResultsRadioButton;
449  private javax.swing.JLabel dataLabel;
450  private javax.swing.JButton deselectAllButton;
451  private javax.swing.ButtonGroup optionsButtonGroup;
452  private javax.swing.JButton selectAllButton;
453  private javax.swing.JRadioButton specificTaggedResultsRadioButton;
454  private javax.swing.JList<String> tagsList;
455  private javax.swing.JScrollPane tagsScrollPane;
456  // End of variables declaration//GEN-END:variables
457 
458  private class TagsListModel implements ListModel<String> {
459 
460  @Override
461  public int getSize() {
462  return tags.size();
463  }
464 
465  @Override
466  public String getElementAt(int index) {
467  return tags.get(index);
468  }
469 
470  @Override
471  public void addListDataListener(ListDataListener l) {
472  }
473 
474  @Override
475  public void removeListDataListener(ListDataListener l) {
476  }
477  }
478 
479  // Render the Tags as JCheckboxes
480  private class TagsListRenderer extends JCheckBox implements ListCellRenderer<String> {
481 
482  @Override
483  public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
484  if (value != null) {
485  setEnabled(list.isEnabled());
486  setSelected(tagStates.get(value));
487  setFont(list.getFont());
488  setBackground(list.getBackground());
489  setForeground(list.getForeground());
490  setText(value);
491  return this;
492  }
493  return new JLabel();
494  }
495  }
496 }
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)

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.