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

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.