Autopsy  4.7.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;
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 
128  int index = tagsList.locationToIndex(evt.getPoint());
129  if (index < tagsModel.getSize() && index >= 0) {
130  String value = tagsModel.getElementAt(index);
131  tagStates.put(value, !tagStates.get(value));
132  tagsList.repaint();
133  updateFinishButton();
134  }
135  }
136  });
137  }
138 
139  // Initialize the list of Artifacts
140  @SuppressWarnings("deprecation")
141  private void initArtifactTypes() {
142 
143  try {
144  Case openCase = Case.getCurrentCaseThrows();
145  ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>();
146  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
147  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
148  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
149  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
150  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
151  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
152 
153  artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
154 
155  artifacts.removeAll(doNotReport);
156 
157  artifactStates = new HashMap<>();
158  for (BlackboardArtifact.Type type : artifacts) {
159  artifactStates.put(type, Boolean.TRUE);
160  }
161  } catch (TskCoreException | NoCurrentCaseException ex) {
162  Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex); //NON-NLS
163  }
164  }
165 
166  @Override
167  public String getName() {
168  return NbBundle.getMessage(this.getClass(), "ReportVisualPanel2.getName.text");
169  }
170 
176  Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
177  return artifactStates;
178  }
179 
183  Map<String, Boolean> getTagStates() {
184  return tagStates;
185  }
186 
187  private boolean areTagsSelected() {
188  boolean result = false;
189  for (Entry<String, Boolean> entry : tagStates.entrySet()) {
190  if (entry.getValue()) {
191  result = true;
192  }
193  }
194  return result;
195  }
196 
197  private void updateFinishButton() {
198  if (taggedResultsRadioButton.isSelected()) {
199  wizPanel.setFinish(areTagsSelected());
200  } else {
201  wizPanel.setFinish(true);
202  }
203  }
204 
208  boolean isTaggedResultsRadioButtonSelected() {
209  return taggedResultsRadioButton.isSelected();
210  }
211 
217  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
218  private void initComponents() {
219 
220  optionsButtonGroup = new javax.swing.ButtonGroup();
221  taggedResultsRadioButton = new javax.swing.JRadioButton();
222  allResultsRadioButton = new javax.swing.JRadioButton();
223  dataLabel = new javax.swing.JLabel();
224  selectAllButton = new javax.swing.JButton();
225  deselectAllButton = new javax.swing.JButton();
226  tagsScrollPane = new javax.swing.JScrollPane();
227  tagsList = new javax.swing.JList<>();
228  advancedButton = new javax.swing.JButton();
229 
230  setPreferredSize(new java.awt.Dimension(650, 250));
231 
232  optionsButtonGroup.add(taggedResultsRadioButton);
233  org.openide.awt.Mnemonics.setLocalizedText(taggedResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.taggedResultsRadioButton.text")); // NOI18N
234 
235  optionsButtonGroup.add(allResultsRadioButton);
236  org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.allResultsRadioButton.text")); // NOI18N
237 
238  org.openide.awt.Mnemonics.setLocalizedText(dataLabel, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.dataLabel.text")); // NOI18N
239 
240  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.selectAllButton.text")); // NOI18N
241  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
242  public void actionPerformed(java.awt.event.ActionEvent evt) {
243  selectAllButtonActionPerformed(evt);
244  }
245  });
246 
247  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.deselectAllButton.text")); // NOI18N
248  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
249  public void actionPerformed(java.awt.event.ActionEvent evt) {
250  deselectAllButtonActionPerformed(evt);
251  }
252  });
253 
254  tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
255  tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
256  tagsScrollPane.setViewportView(tagsList);
257 
258  org.openide.awt.Mnemonics.setLocalizedText(advancedButton, org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class, "ReportVisualPanel2.advancedButton.text")); // NOI18N
259  advancedButton.addActionListener(new java.awt.event.ActionListener() {
260  public void actionPerformed(java.awt.event.ActionEvent evt) {
261  advancedButtonActionPerformed(evt);
262  }
263  });
264 
265  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
266  this.setLayout(layout);
267  layout.setHorizontalGroup(
268  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269  .addGroup(layout.createSequentialGroup()
270  .addContainerGap()
271  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272  .addGroup(layout.createSequentialGroup()
273  .addGap(21, 21, 21)
274  .addComponent(tagsScrollPane)
275  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
276  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
277  .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
278  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
279  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
280  .addGroup(layout.createSequentialGroup()
281  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
282  .addComponent(taggedResultsRadioButton)
283  .addComponent(dataLabel)
284  .addComponent(allResultsRadioButton))
285  .addGap(0, 0, Short.MAX_VALUE)))
286  .addContainerGap())
287  );
288 
289  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
290 
291  layout.setVerticalGroup(
292  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293  .addGroup(layout.createSequentialGroup()
294  .addContainerGap()
295  .addComponent(dataLabel)
296  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
297  .addComponent(allResultsRadioButton)
298  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
299  .addComponent(taggedResultsRadioButton)
300  .addGap(7, 7, 7)
301  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302  .addGroup(layout.createSequentialGroup()
303  .addComponent(selectAllButton)
304  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
305  .addComponent(deselectAllButton)
306  .addGap(0, 70, Short.MAX_VALUE))
307  .addComponent(tagsScrollPane))
308  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
309  .addComponent(advancedButton)
310  .addContainerGap())
311  );
312  }// </editor-fold>//GEN-END:initComponents
313 
314  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
315  for (String tag : tags) {
316  tagStates.put(tag, Boolean.TRUE);
317  }
318  tagsList.repaint();
319  wizPanel.setFinish(true);
320  }//GEN-LAST:event_selectAllButtonActionPerformed
321 
322  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
323  for (String tag : tags) {
324  tagStates.put(tag, Boolean.FALSE);
325  }
326  tagsList.repaint();
327  wizPanel.setFinish(false);
328  }//GEN-LAST:event_deselectAllButtonActionPerformed
329 
330  private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
331  artifactStates = dialog.display();
332  }//GEN-LAST:event_advancedButtonActionPerformed
333 
334  // Variables declaration - do not modify//GEN-BEGIN:variables
335  private javax.swing.JButton advancedButton;
336  private javax.swing.JRadioButton allResultsRadioButton;
337  private javax.swing.JLabel dataLabel;
338  private javax.swing.JButton deselectAllButton;
339  private javax.swing.ButtonGroup optionsButtonGroup;
340  private javax.swing.JButton selectAllButton;
341  private javax.swing.JRadioButton taggedResultsRadioButton;
342  private javax.swing.JList<String> tagsList;
343  private javax.swing.JScrollPane tagsScrollPane;
344  // End of variables declaration//GEN-END:variables
345 
346  private class TagsListModel implements ListModel<String> {
347 
348  @Override
349  public int getSize() {
350  return tags.size();
351  }
352 
353  @Override
354  public String getElementAt(int index) {
355  return tags.get(index);
356  }
357 
358  @Override
359  public void addListDataListener(ListDataListener l) {
360  }
361 
362  @Override
363  public void removeListDataListener(ListDataListener l) {
364  }
365  }
366 
367  // Render the Tags as JCheckboxes
368  private class TagsListRenderer extends JCheckBox implements ListCellRenderer<String> {
369 
370  @Override
371  public Component getListCellRendererComponent(JList<? extends String> list, String value, int index, boolean isSelected, boolean cellHasFocus) {
372  if (value != null) {
373  setEnabled(list.isEnabled());
374  setSelected(tagStates.get(value));
375  setFont(list.getFont());
376  setBackground(list.getBackground());
377  setForeground(list.getForeground());
378  setText(value);
379  return this;
380  }
381  return new JLabel();
382  }
383  }
384 }
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)

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