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

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