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

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