19 package org.sleuthkit.autopsy.report.infrastructure;
21 import java.awt.Component;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.LinkedHashMap;
29 import java.util.List;
31 import java.util.Map.Entry;
32 import java.util.logging.Level;
33 import javax.swing.JCheckBox;
34 import javax.swing.JFrame;
35 import javax.swing.JLabel;
36 import javax.swing.JList;
37 import javax.swing.JPanel;
38 import javax.swing.ListCellRenderer;
39 import javax.swing.ListModel;
40 import javax.swing.event.ListDataListener;
41 import org.openide.util.NbBundle;
42 import org.openide.windows.WindowManager;
55 @SuppressWarnings(
"PMD.SingularField")
56 final class ReportVisualPanel2 extends JPanel {
58 private final ReportWizardPanel2 wizPanel;
59 private final Map<String, Boolean> tagStates =
new LinkedHashMap<>();
60 private final List<String> tags =
new ArrayList<>();
61 final ArtifactSelectionDialog dialog =
new ArtifactSelectionDialog((JFrame) WindowManager.getDefault().getMainWindow(),
true);
62 private Map<BlackboardArtifact.Type, Boolean> artifactStates =
new HashMap<>();
63 private List<BlackboardArtifact.Type> artifacts =
new ArrayList<>();
64 private final boolean useCaseSpecificData;
65 private TagsListModel tagsModel;
66 private TagsListRenderer tagsRenderer;
71 public ReportVisualPanel2(ReportWizardPanel2 wizPanel,
boolean useCaseSpecificData, TableReportSettings settings) {
72 this.useCaseSpecificData = useCaseSpecificData;
76 this.wizPanel = wizPanel;
78 this.allResultsRadioButton.addItemListener(
new ItemListener() {
80 public void itemStateChanged(ItemEvent e) {
81 tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
82 selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
83 deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
84 advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
88 this.allTaggedResultsRadioButton.addItemListener(
new ItemListener() {
90 public void itemStateChanged(ItemEvent e) {
91 tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
92 selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
93 deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
94 advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
98 this.specificTaggedResultsRadioButton.addItemListener(
new ItemListener() {
100 public void itemStateChanged(ItemEvent e) {
101 tagsList.setEnabled(specificTaggedResultsRadioButton.isSelected());
102 selectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
103 deselectAllButton.setEnabled(specificTaggedResultsRadioButton.isSelected());
104 advancedButton.setEnabled(allResultsRadioButton.isSelected() && useCaseSpecificData);
105 updateFinishButton();
110 advancedButton.setEnabled(useCaseSpecificData);
111 specificTaggedResultsRadioButton.setEnabled(useCaseSpecificData);
112 TableReportSettings.TableReportOption type = TableReportSettings.TableReportOption.ALL_RESULTS;
113 if (settings != null) {
114 type = settings.getSelectedReportOption();
117 case ALL_TAGGED_RESULTS:
118 allTaggedResultsRadioButton.setSelected(
true);
119 tagsList.setEnabled(
false);
120 selectAllButton.setEnabled(
false);
121 deselectAllButton.setEnabled(
false);
123 case SPECIFIC_TAGGED_RESULTS:
124 specificTaggedResultsRadioButton.setSelected(useCaseSpecificData);
125 tagsList.setEnabled(useCaseSpecificData);
126 selectAllButton.setEnabled(useCaseSpecificData);
127 deselectAllButton.setEnabled(useCaseSpecificData);
131 allResultsRadioButton.setSelected(
true);
132 tagsList.setEnabled(
false);
133 selectAllButton.setEnabled(
false);
134 deselectAllButton.setEnabled(
false);
137 updateFinishButton();
141 private void initTags() {
143 List<TagName> tagNamesInUse =
new ArrayList<>();
151 if (useCaseSpecificData) {
153 tagNamesInUse = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
155 }
catch (TskCoreException | NoCurrentCaseException ex) {
156 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
160 for (TagName tagName : tagNamesInUse) {
161 String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
162 tagStates.put(tagName.getDisplayName() + notableString, Boolean.FALSE);
164 tags.addAll(tagStates.keySet());
166 tagsModel =
new TagsListModel();
167 tagsRenderer =
new TagsListRenderer();
168 tagsList.setModel(tagsModel);
169 tagsList.setCellRenderer(tagsRenderer);
170 tagsList.setVisibleRowCount(-1);
173 tagsList.addMouseListener(
new MouseAdapter() {
175 public void mousePressed(MouseEvent evt) {
176 if (!specificTaggedResultsRadioButton.isSelected()) {
179 int index = tagsList.locationToIndex(evt.getPoint());
180 if (index < tagsModel.getSize() && index >= 0) {
181 String value = tagsModel.getElementAt(index);
182 tagStates.put(value, !tagStates.get(value));
184 updateFinishButton();
191 @SuppressWarnings(
"deprecation")
192 private
void initArtifactTypes() {
196 if (!useCaseSpecificData) {
201 Case openCase = Case.getCurrentCaseThrows();
202 ArrayList<BlackboardArtifact.Type> doNotReport =
new ArrayList<>();
203 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
204 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
205 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
206 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
207 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
208 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName()));
209 doNotReport.add(
new BlackboardArtifact.Type(
210 BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID(),
211 BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getLabel(),
212 BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getDisplayName()));
213 doNotReport.add(
new BlackboardArtifact.Type(
214 BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getTypeID(),
215 BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getLabel(),
216 BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getDisplayName()));
218 artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
220 artifacts.removeAll(doNotReport);
222 artifactStates =
new HashMap<>();
223 for (BlackboardArtifact.Type type : artifacts) {
224 artifactStates.put(type, Boolean.TRUE);
226 }
catch (TskCoreException | NoCurrentCaseException ex) {
227 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex);
232 public String getName() {
233 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel2.getName.text");
241 Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
242 return artifactStates;
248 Map<String, Boolean> getTagStates() {
257 private boolean areTagsSelected() {
258 boolean result =
false;
259 for (Entry<String, Boolean> entry : tagStates.entrySet()) {
260 if (entry.getValue()) {
272 private void updateFinishButton() {
273 if (specificTaggedResultsRadioButton.isSelected()) {
274 wizPanel.setFinish(areTagsSelected());
276 wizPanel.setFinish(
true);
284 TableReportSettings.TableReportOption getSelectedReportType() {
285 if (allTaggedResultsRadioButton.isSelected()) {
286 return TableReportSettings.TableReportOption.ALL_TAGGED_RESULTS;
287 }
else if (specificTaggedResultsRadioButton.isSelected()) {
288 return TableReportSettings.TableReportOption.SPECIFIC_TAGGED_RESULTS;
290 return TableReportSettings.TableReportOption.ALL_RESULTS;
298 void setAllTaggedResultsSelected(
boolean selected) {
299 for (String tag : tags) {
300 tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
311 private void initComponents() {
313 optionsButtonGroup =
new javax.swing.ButtonGroup();
314 specificTaggedResultsRadioButton =
new javax.swing.JRadioButton();
315 allResultsRadioButton =
new javax.swing.JRadioButton();
316 dataLabel =
new javax.swing.JLabel();
317 selectAllButton =
new javax.swing.JButton();
318 deselectAllButton =
new javax.swing.JButton();
319 tagsScrollPane =
new javax.swing.JScrollPane();
320 tagsList =
new javax.swing.JList<>();
321 advancedButton =
new javax.swing.JButton();
322 allTaggedResultsRadioButton =
new javax.swing.JRadioButton();
324 setPreferredSize(
new java.awt.Dimension(650, 250));
326 optionsButtonGroup.add(specificTaggedResultsRadioButton);
327 org.openide.awt.Mnemonics.setLocalizedText(specificTaggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.specificTaggedResultsRadioButton.text"));
329 optionsButtonGroup.add(allResultsRadioButton);
330 org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allResultsRadioButton.text"));
331 allResultsRadioButton.addActionListener(
new java.awt.event.ActionListener() {
332 public void actionPerformed(java.awt.event.ActionEvent evt) {
333 allResultsRadioButtonActionPerformed(evt);
337 org.openide.awt.Mnemonics.setLocalizedText(dataLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.dataLabel.text"));
339 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.selectAllButton.text"));
340 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
341 public void actionPerformed(java.awt.event.ActionEvent evt) {
342 selectAllButtonActionPerformed(evt);
346 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.deselectAllButton.text"));
347 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
348 public void actionPerformed(java.awt.event.ActionEvent evt) {
349 deselectAllButtonActionPerformed(evt);
353 tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
354 tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
355 tagsScrollPane.setViewportView(tagsList);
357 org.openide.awt.Mnemonics.setLocalizedText(advancedButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.advancedButton.text"));
358 advancedButton.addActionListener(
new java.awt.event.ActionListener() {
359 public void actionPerformed(java.awt.event.ActionEvent evt) {
360 advancedButtonActionPerformed(evt);
364 optionsButtonGroup.add(allTaggedResultsRadioButton);
365 org.openide.awt.Mnemonics.setLocalizedText(allTaggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allTaggedResultsRadioButton.text"));
366 allTaggedResultsRadioButton.addActionListener(
new java.awt.event.ActionListener() {
367 public void actionPerformed(java.awt.event.ActionEvent evt) {
368 allTaggedResultsRadioButtonActionPerformed(evt);
372 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
373 this.setLayout(layout);
374 layout.setHorizontalGroup(
375 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
376 .addGroup(layout.createSequentialGroup()
378 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
379 .addGroup(layout.createSequentialGroup()
381 .addComponent(tagsScrollPane)
382 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
383 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
384 .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
385 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
386 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
387 .addGroup(layout.createSequentialGroup()
388 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
389 .addComponent(allTaggedResultsRadioButton)
390 .addComponent(dataLabel)
391 .addComponent(allResultsRadioButton)
392 .addComponent(specificTaggedResultsRadioButton))
393 .addGap(0, 402, Short.MAX_VALUE)))
397 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
399 layout.setVerticalGroup(
400 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401 .addGroup(layout.createSequentialGroup()
403 .addComponent(dataLabel)
404 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
405 .addComponent(allResultsRadioButton)
406 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
407 .addComponent(allTaggedResultsRadioButton)
408 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
409 .addComponent(specificTaggedResultsRadioButton)
410 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
411 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
412 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
413 .addComponent(selectAllButton)
414 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
415 .addComponent(deselectAllButton)
416 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
417 .addComponent(advancedButton))
418 .addComponent(tagsScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
423 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
424 setAllTaggedResultsSelected(
true);
425 wizPanel.setFinish(
true);
428 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
429 setAllTaggedResultsSelected(
false);
430 wizPanel.setFinish(
false);
433 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
434 artifactStates = dialog.display();
437 private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
438 setAllTaggedResultsSelected(
false);
441 private void allTaggedResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
442 setAllTaggedResultsSelected(
true);
446 private javax.swing.JButton advancedButton;
447 private javax.swing.JRadioButton allResultsRadioButton;
448 private javax.swing.JRadioButton allTaggedResultsRadioButton;
449 private javax.swing.JLabel dataLabel;
450 private javax.swing.JButton deselectAllButton;
451 private javax.swing.ButtonGroup optionsButtonGroup;
452 private javax.swing.JButton selectAllButton;
453 private javax.swing.JRadioButton specificTaggedResultsRadioButton;
454 private javax.swing.JList<String> tagsList;
455 private javax.swing.JScrollPane tagsScrollPane;
467 return tags.get(index);
485 setEnabled(list.isEnabled());
486 setSelected(tagStates.get(value));
487 setFont(list.getFont());
488 setBackground(list.getBackground());
489 setForeground(list.getForeground());