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

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