Autopsy  4.20.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));
204  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT)); // output is too unstructured for table review
205  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT));
206  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT));
207  // get artifact types that exist in the current case
208  artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
209 
210  artifacts.removeAll(doNotReport);
211 
212  artifactStates = new HashMap<>();
213  for (BlackboardArtifact.Type type : artifacts) {
214  artifactStates.put(type, Boolean.TRUE);
215  }
216  } catch (TskCoreException | NoCurrentCaseException ex) {
217  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex); //NON-NLS
218  }
219  }
220 
221  @Override
222  public String getName() {
223  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel2.getName.text");
224  }
225 
231  Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
232  return artifactStates;
233  }
234 
238  Map<String, Boolean> getTagStates() {
239  return tagStates;
240  }
241 
247  private boolean areTagsSelected() {
248  boolean result = false;
249  for (Entry<String, Boolean> entry : tagStates.entrySet()) {
250  if (entry.getValue()) {
251  result = true;
252  break;
253  }
254  }
255  return result;
256  }
257 
262  private void updateFinishButton() {
263  if (specificTaggedResultsRadioButton.isSelected()) {
264  wizPanel.setFinish(areTagsSelected());
265  } else {
266  wizPanel.setFinish(true);
267  }
268  }
269 
274  TableReportSettings.TableReportOption getSelectedReportType() {
275  if (allTaggedResultsRadioButton.isSelected()) {
276  return TableReportSettings.TableReportOption.ALL_TAGGED_RESULTS;
277  } else if (specificTaggedResultsRadioButton.isSelected()) {
278  return TableReportSettings.TableReportOption.SPECIFIC_TAGGED_RESULTS;
279  }
280  return TableReportSettings.TableReportOption.ALL_RESULTS;
281  }
282 
288  void setAllTaggedResultsSelected(boolean selected) {
289  for (String tag : tags) {
290  tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
291  }
292  tagsList.repaint();
293  }
294 
300  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
301  private void initComponents() {
302 
303  optionsButtonGroup = new javax.swing.ButtonGroup();
304  specificTaggedResultsRadioButton = new javax.swing.JRadioButton();
305  allResultsRadioButton = new javax.swing.JRadioButton();
306  dataLabel = new javax.swing.JLabel();
307  selectAllButton = new javax.swing.JButton();
308  deselectAllButton = new javax.swing.JButton();
309  tagsScrollPane = new javax.swing.JScrollPane();
310  tagsList = new javax.swing.JList<>();
311  advancedButton = new javax.swing.JButton();
312  allTaggedResultsRadioButton = new javax.swing.JRadioButton();
313 
314  setPreferredSize(new java.awt.Dimension(834, 374));
315 
316  optionsButtonGroup.add(specificTaggedResultsRadioButton);
317  org.openide.awt.Mnemonics.setLocalizedText(specificTaggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.specificTaggedResultsRadioButton.text")); // NOI18N
318 
319  optionsButtonGroup.add(allResultsRadioButton);
320  org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allResultsRadioButton.text")); // NOI18N
321  allResultsRadioButton.addActionListener(new java.awt.event.ActionListener() {
322  public void actionPerformed(java.awt.event.ActionEvent evt) {
323  allResultsRadioButtonActionPerformed(evt);
324  }
325  });
326 
327  org.openide.awt.Mnemonics.setLocalizedText(dataLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.dataLabel.text")); // NOI18N
328 
329  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.selectAllButton.text")); // NOI18N
330  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
331  public void actionPerformed(java.awt.event.ActionEvent evt) {
332  selectAllButtonActionPerformed(evt);
333  }
334  });
335 
336  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.deselectAllButton.text")); // NOI18N
337  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
338  public void actionPerformed(java.awt.event.ActionEvent evt) {
339  deselectAllButtonActionPerformed(evt);
340  }
341  });
342 
343  tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
344  tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
345  tagsScrollPane.setViewportView(tagsList);
346 
347  org.openide.awt.Mnemonics.setLocalizedText(advancedButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.advancedButton.text")); // NOI18N
348  advancedButton.addActionListener(new java.awt.event.ActionListener() {
349  public void actionPerformed(java.awt.event.ActionEvent evt) {
350  advancedButtonActionPerformed(evt);
351  }
352  });
353 
354  optionsButtonGroup.add(allTaggedResultsRadioButton);
355  org.openide.awt.Mnemonics.setLocalizedText(allTaggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allTaggedResultsRadioButton.text")); // NOI18N
356  allTaggedResultsRadioButton.addActionListener(new java.awt.event.ActionListener() {
357  public void actionPerformed(java.awt.event.ActionEvent evt) {
358  allTaggedResultsRadioButtonActionPerformed(evt);
359  }
360  });
361 
362  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
363  this.setLayout(layout);
364  layout.setHorizontalGroup(
365  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
366  .addGroup(layout.createSequentialGroup()
367  .addContainerGap()
368  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
369  .addComponent(allTaggedResultsRadioButton)
370  .addComponent(dataLabel)
371  .addComponent(allResultsRadioButton)
372  .addComponent(specificTaggedResultsRadioButton)
373  .addGroup(layout.createSequentialGroup()
374  .addGap(10, 10, 10)
375  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
376  .addComponent(advancedButton)
377  .addGroup(layout.createSequentialGroup()
378  .addComponent(tagsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 699, Short.MAX_VALUE)
379  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
380  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
381  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
382  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
383  .addContainerGap())
384  );
385 
386  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deselectAllButton, selectAllButton});
387 
388  layout.setVerticalGroup(
389  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
390  .addGroup(layout.createSequentialGroup()
391  .addContainerGap()
392  .addComponent(dataLabel)
393  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
394  .addComponent(allResultsRadioButton)
395  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
396  .addComponent(allTaggedResultsRadioButton)
397  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398  .addComponent(specificTaggedResultsRadioButton)
399  .addGap(18, 18, 18)
400  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401  .addGroup(layout.createSequentialGroup()
402  .addComponent(selectAllButton)
403  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
404  .addComponent(deselectAllButton)
405  .addGap(136, 136, 136))
406  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
407  .addGap(1, 1, 1)
408  .addComponent(tagsScrollPane)
409  .addGap(5, 5, 5)
410  .addComponent(advancedButton)))
411  .addContainerGap())
412  );
413  }// </editor-fold>//GEN-END:initComponents
414 
415  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
416  setAllTaggedResultsSelected(true);
417  wizPanel.setFinish(true);
418  }//GEN-LAST:event_selectAllButtonActionPerformed
419 
420  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
421  setAllTaggedResultsSelected(false);
422  wizPanel.setFinish(false);
423  }//GEN-LAST:event_deselectAllButtonActionPerformed
424 
425  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
426  artifactStates = dialog.display();
427  }//GEN-LAST:event_advancedButtonActionPerformed
428 
429  private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allResultsRadioButtonActionPerformed
430  setAllTaggedResultsSelected(false);
431  }//GEN-LAST:event_allResultsRadioButtonActionPerformed
432 
433  private void allTaggedResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allTaggedResultsRadioButtonActionPerformed
434  setAllTaggedResultsSelected(true);
435  }//GEN-LAST:event_allTaggedResultsRadioButtonActionPerformed
436 
437  // Variables declaration - do not modify//GEN-BEGIN:variables
438  private javax.swing.JButton advancedButton;
439  private javax.swing.JRadioButton allResultsRadioButton;
440  private javax.swing.JRadioButton allTaggedResultsRadioButton;
441  private javax.swing.JLabel dataLabel;
442  private javax.swing.JButton deselectAllButton;
443  private javax.swing.ButtonGroup optionsButtonGroup;
444  private javax.swing.JButton selectAllButton;
445  private javax.swing.JRadioButton specificTaggedResultsRadioButton;
446  private javax.swing.JList<String> tagsList;
447  private javax.swing.JScrollPane tagsScrollPane;
448  // End of variables declaration//GEN-END:variables
449 
450  private class TagsListModel implements ListModel<String> {
451 
452  @Override
453  public int getSize() {
454  return tags.size();
455  }
456 
457  @Override
458  public String getElementAt(int index) {
459  return tags.get(index);
460  }
461 
462  @Override
463  public void addListDataListener(ListDataListener l) {
464  }
465 
466  @Override
467  public void removeListDataListener(ListDataListener l) {
468  }
469  }
470 
471  // Render the Tags as JCheckboxes
472  private class TagsListRenderer extends JCheckBox implements ListCellRenderer<String> {
473 
474  @Override
475  public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
476  if (value != null) {
477  setEnabled(list.isEnabled());
478  setSelected(tagStates.get(value));
479  setFont(list.getFont());
480  setBackground(list.getBackground());
481  setForeground(list.getForeground());
482  setText(value);
483  return this;
484  }
485  return new JLabel();
486  }
487  }
488 }
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.