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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.