Autopsy  4.9.1
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;
20 
21 import java.awt.Component;
22 import java.awt.event.MouseAdapter;
23 import java.awt.event.MouseEvent;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.LinkedHashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Map.Entry;
30 import java.util.logging.Level;
31 import javax.swing.JCheckBox;
32 import javax.swing.JFrame;
33 import javax.swing.JLabel;
34 import javax.swing.JList;
35 import javax.swing.JPanel;
36 import javax.swing.ListCellRenderer;
37 import javax.swing.ListModel;
38 import javax.swing.event.ChangeEvent;
39 import javax.swing.event.ChangeListener;
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  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 TagsListModel tagsModel;
65  private TagsListRenderer tagsRenderer;
66 
70  public ReportVisualPanel2(ReportWizardPanel2 wizPanel) {
71  initComponents();
72  initTags();
73  initArtifactTypes();
74  tagsList.setEnabled(false);
75  selectAllButton.setEnabled(false);
76  deselectAllButton.setEnabled(false);
77  allResultsRadioButton.setSelected(true);
78  this.wizPanel = wizPanel;
79  this.allResultsRadioButton.addChangeListener(new ChangeListener() {
80  @Override
81  public void stateChanged(ChangeEvent e) {
82  tagsList.setEnabled(taggedResultsRadioButton.isSelected());
83  selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
84  deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
85  advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
86  updateFinishButton();
87  }
88  });
89  this.taggedResultsRadioButton.addChangeListener(new ChangeListener() {
90  @Override
91  public void stateChanged(ChangeEvent e) {
92  tagsList.setEnabled(taggedResultsRadioButton.isSelected());
93  selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
94  deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
95  advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
96  updateFinishButton();
97  }
98  });
99  }
100 
101  // Initialize the list of Tags
102  private void initTags() {
103  List<TagName> tagNamesInUse;
104  try {
105  tagNamesInUse = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
106  } catch (TskCoreException | NoCurrentCaseException ex) {
107  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Failed to get tag names", ex); //NON-NLS
108  return;
109  }
110 
111  for (TagName tagName : tagNamesInUse) {
112  String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() : "";
113  tagStates.put(tagName.getDisplayName() + notableString, Boolean.FALSE);
114  }
115  tags.addAll(tagStates.keySet());
116 
117  tagsModel = new TagsListModel();
118  tagsRenderer = new TagsListRenderer();
119  tagsList.setModel(tagsModel);
120  tagsList.setCellRenderer(tagsRenderer);
121  tagsList.setVisibleRowCount(-1);
122 
123  // Add the ability to enable and disable Tag checkboxes to the list
124  tagsList.addMouseListener(new MouseAdapter() {
125  @Override
126  public void mousePressed(MouseEvent evt) {
127  if (!taggedResultsRadioButton.isSelected()) {
128  return;
129  }
130  int index = tagsList.locationToIndex(evt.getPoint());
131  if (index < tagsModel.getSize() && index >= 0) {
132  String value = tagsModel.getElementAt(index);
133  tagStates.put(value, !tagStates.get(value));
134  tagsList.repaint();
135  updateFinishButton();
136  }
137  }
138  });
139  }
140 
141  // Initialize the list of Artifacts
142  @SuppressWarnings("deprecation")
143  private void initArtifactTypes() {
144 
145  try {
146  Case openCase = Case.getCurrentCaseThrows();
147  ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>();
148  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
149  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
150  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
151  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
152  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
153  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
154 
155  artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
156 
157  artifacts.removeAll(doNotReport);
158 
159  artifactStates = new HashMap<>();
160  for (BlackboardArtifact.Type type : artifacts) {
161  artifactStates.put(type, Boolean.TRUE);
162  }
163  } catch (TskCoreException | NoCurrentCaseException ex) {
164  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex); //NON-NLS
165  }
166  }
167 
168  @Override
169  public String getName() {
170  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel2.getName.text");
171  }
172 
178  Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
179  return artifactStates;
180  }
181 
185  Map<String, Boolean> getTagStates() {
186  return tagStates;
187  }
188 
194  private boolean areTagsSelected() {
195  boolean result = false;
196  for (Entry<String, Boolean> entry : tagStates.entrySet()) {
197  if (entry.getValue()) {
198  result = true;
199  break;
200  }
201  }
202  return result;
203  }
204 
209  private void updateFinishButton() {
210  if (taggedResultsRadioButton.isSelected()) {
211  wizPanel.setFinish(areTagsSelected());
212  } else {
213  wizPanel.setFinish(true);
214  }
215  }
216 
220  boolean isTaggedResultsRadioButtonSelected() {
221  return taggedResultsRadioButton.isSelected();
222  }
223 
229  void setAllTaggedResultsSelected(boolean selected) {
230  for (String tag : tags) {
231  tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
232  }
233  tagsList.repaint();
234  wizPanel.setFinish(selected);
235  }
236 
242  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
243  private void initComponents() {
244 
245  optionsButtonGroup = new javax.swing.ButtonGroup();
246  taggedResultsRadioButton = new javax.swing.JRadioButton();
247  allResultsRadioButton = new javax.swing.JRadioButton();
248  dataLabel = new javax.swing.JLabel();
249  selectAllButton = new javax.swing.JButton();
250  deselectAllButton = new javax.swing.JButton();
251  tagsScrollPane = new javax.swing.JScrollPane();
252  tagsList = new javax.swing.JList<>();
253  advancedButton = new javax.swing.JButton();
254 
255  setPreferredSize(new java.awt.Dimension(650, 250));
256 
257  optionsButtonGroup.add(taggedResultsRadioButton);
258  org.openide.awt.Mnemonics.setLocalizedText(taggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.taggedResultsRadioButton.text")); // NOI18N
259 
260  optionsButtonGroup.add(allResultsRadioButton);
261  org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allResultsRadioButton.text")); // NOI18N
262  allResultsRadioButton.addActionListener(new java.awt.event.ActionListener() {
263  public void actionPerformed(java.awt.event.ActionEvent evt) {
264  allResultsRadioButtonActionPerformed(evt);
265  }
266  });
267 
268  org.openide.awt.Mnemonics.setLocalizedText(dataLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.dataLabel.text")); // NOI18N
269 
270  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.selectAllButton.text")); // NOI18N
271  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
272  public void actionPerformed(java.awt.event.ActionEvent evt) {
273  selectAllButtonActionPerformed(evt);
274  }
275  });
276 
277  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.deselectAllButton.text")); // NOI18N
278  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
279  public void actionPerformed(java.awt.event.ActionEvent evt) {
280  deselectAllButtonActionPerformed(evt);
281  }
282  });
283 
284  tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
285  tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
286  tagsScrollPane.setViewportView(tagsList);
287 
288  org.openide.awt.Mnemonics.setLocalizedText(advancedButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.advancedButton.text")); // NOI18N
289  advancedButton.addActionListener(new java.awt.event.ActionListener() {
290  public void actionPerformed(java.awt.event.ActionEvent evt) {
291  advancedButtonActionPerformed(evt);
292  }
293  });
294 
295  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
296  this.setLayout(layout);
297  layout.setHorizontalGroup(
298  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299  .addGroup(layout.createSequentialGroup()
300  .addContainerGap()
301  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302  .addGroup(layout.createSequentialGroup()
303  .addGap(21, 21, 21)
304  .addComponent(tagsScrollPane)
305  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
306  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
307  .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
308  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
309  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
310  .addGroup(layout.createSequentialGroup()
311  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
312  .addComponent(taggedResultsRadioButton)
313  .addComponent(dataLabel)
314  .addComponent(allResultsRadioButton))
315  .addGap(0, 0, Short.MAX_VALUE)))
316  .addContainerGap())
317  );
318 
319  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
320 
321  layout.setVerticalGroup(
322  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323  .addGroup(layout.createSequentialGroup()
324  .addContainerGap()
325  .addComponent(dataLabel)
326  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327  .addComponent(allResultsRadioButton)
328  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
329  .addComponent(taggedResultsRadioButton)
330  .addGap(7, 7, 7)
331  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
332  .addGroup(layout.createSequentialGroup()
333  .addComponent(selectAllButton)
334  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
335  .addComponent(deselectAllButton)
336  .addGap(0, 70, Short.MAX_VALUE))
337  .addComponent(tagsScrollPane))
338  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339  .addComponent(advancedButton)
340  .addContainerGap())
341  );
342  }// </editor-fold>//GEN-END:initComponents
343 
344  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
345  setAllTaggedResultsSelected(true);
346  }//GEN-LAST:event_selectAllButtonActionPerformed
347 
348  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
349  setAllTaggedResultsSelected(false);
350  }//GEN-LAST:event_deselectAllButtonActionPerformed
351 
352  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
353  artifactStates = dialog.display();
354  }//GEN-LAST:event_advancedButtonActionPerformed
355 
356  private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allResultsRadioButtonActionPerformed
357  setAllTaggedResultsSelected(false);
358  }//GEN-LAST:event_allResultsRadioButtonActionPerformed
359 
360  // Variables declaration - do not modify//GEN-BEGIN:variables
361  private javax.swing.JButton advancedButton;
362  private javax.swing.JRadioButton allResultsRadioButton;
363  private javax.swing.JLabel dataLabel;
364  private javax.swing.JButton deselectAllButton;
365  private javax.swing.ButtonGroup optionsButtonGroup;
366  private javax.swing.JButton selectAllButton;
367  private javax.swing.JRadioButton taggedResultsRadioButton;
368  private javax.swing.JList<String> tagsList;
369  private javax.swing.JScrollPane tagsScrollPane;
370  // End of variables declaration//GEN-END:variables
371 
372  private class TagsListModel implements ListModel<String> {
373 
374  @Override
375  public int getSize() {
376  return tags.size();
377  }
378 
379  @Override
380  public String getElementAt(int index) {
381  return tags.get(index);
382  }
383 
384  @Override
385  public void addListDataListener(ListDataListener l) {
386  }
387 
388  @Override
389  public void removeListDataListener(ListDataListener l) {
390  }
391  }
392 
393  // Render the Tags as JCheckboxes
394  private class TagsListRenderer extends JCheckBox implements ListCellRenderer<String> {
395 
396  @Override
397  public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
398  if (value != null) {
399  setEnabled(list.isEnabled());
400  setSelected(tagStates.get(value));
401  setFont(list.getFont());
402  setBackground(list.getBackground());
403  setForeground(list.getForeground());
404  setText(value);
405  return this;
406  }
407  return new JLabel();
408  }
409  }
410 }
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2018 Basis Technology. Generated on: Tue Dec 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.