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));
204 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT));
205 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT));
206 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT));
208 artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
210 artifacts.removeAll(doNotReport);
212 artifactStates =
new HashMap<>();
213 for (BlackboardArtifact.Type type : artifacts) {
214 artifactStates.put(type, Boolean.TRUE);
216 }
catch (TskCoreException | NoCurrentCaseException ex) {
217 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex);
222 public String getName() {
223 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel2.getName.text");
231 Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
232 return artifactStates;
238 Map<String, Boolean> getTagStates() {
247 private boolean areTagsSelected() {
248 boolean result =
false;
249 for (Entry<String, Boolean> entry : tagStates.entrySet()) {
250 if (entry.getValue()) {
262 private void updateFinishButton() {
263 if (specificTaggedResultsRadioButton.isSelected()) {
264 wizPanel.setFinish(areTagsSelected());
266 wizPanel.setFinish(
true);
274 TableReportSettings.TableReportOption getSelectedReportType() {
275 if (allTaggedResultsRadioButton.isSelected()) {
276 return TableReportSettings.TableReportOption.ALL_TAGGED_RESULTS;
277 }
else if (specificTaggedResultsRadioButton.isSelected()) {
278 return TableReportSettings.TableReportOption.SPECIFIC_TAGGED_RESULTS;
280 return TableReportSettings.TableReportOption.ALL_RESULTS;
288 void setAllTaggedResultsSelected(
boolean selected) {
289 for (String tag : tags) {
290 tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
301 private void initComponents() {
303 optionsButtonGroup =
new javax.swing.ButtonGroup();
304 specificTaggedResultsRadioButton =
new javax.swing.JRadioButton();
305 allResultsRadioButton =
new javax.swing.JRadioButton();
306 dataLabel =
new javax.swing.JLabel();
307 selectAllButton =
new javax.swing.JButton();
308 deselectAllButton =
new javax.swing.JButton();
309 tagsScrollPane =
new javax.swing.JScrollPane();
310 tagsList =
new javax.swing.JList<>();
311 advancedButton =
new javax.swing.JButton();
312 allTaggedResultsRadioButton =
new javax.swing.JRadioButton();
314 setPreferredSize(
new java.awt.Dimension(834, 374));
316 optionsButtonGroup.add(specificTaggedResultsRadioButton);
317 org.openide.awt.Mnemonics.setLocalizedText(specificTaggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.specificTaggedResultsRadioButton.text"));
319 optionsButtonGroup.add(allResultsRadioButton);
320 org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allResultsRadioButton.text"));
321 allResultsRadioButton.addActionListener(
new java.awt.event.ActionListener() {
322 public void actionPerformed(java.awt.event.ActionEvent evt) {
323 allResultsRadioButtonActionPerformed(evt);
327 org.openide.awt.Mnemonics.setLocalizedText(dataLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.dataLabel.text"));
329 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.selectAllButton.text"));
330 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
331 public void actionPerformed(java.awt.event.ActionEvent evt) {
332 selectAllButtonActionPerformed(evt);
336 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.deselectAllButton.text"));
337 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
338 public void actionPerformed(java.awt.event.ActionEvent evt) {
339 deselectAllButtonActionPerformed(evt);
343 tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
344 tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
345 tagsScrollPane.setViewportView(tagsList);
347 org.openide.awt.Mnemonics.setLocalizedText(advancedButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.advancedButton.text"));
348 advancedButton.addActionListener(
new java.awt.event.ActionListener() {
349 public void actionPerformed(java.awt.event.ActionEvent evt) {
350 advancedButtonActionPerformed(evt);
354 optionsButtonGroup.add(allTaggedResultsRadioButton);
355 org.openide.awt.Mnemonics.setLocalizedText(allTaggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allTaggedResultsRadioButton.text"));
356 allTaggedResultsRadioButton.addActionListener(
new java.awt.event.ActionListener() {
357 public void actionPerformed(java.awt.event.ActionEvent evt) {
358 allTaggedResultsRadioButtonActionPerformed(evt);
362 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
363 this.setLayout(layout);
364 layout.setHorizontalGroup(
365 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
366 .addGroup(layout.createSequentialGroup()
368 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
369 .addComponent(allTaggedResultsRadioButton)
370 .addComponent(dataLabel)
371 .addComponent(allResultsRadioButton)
372 .addComponent(specificTaggedResultsRadioButton)
373 .addGroup(layout.createSequentialGroup()
375 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
376 .addComponent(advancedButton)
377 .addGroup(layout.createSequentialGroup()
378 .addComponent(tagsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 699, Short.MAX_VALUE)
379 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
380 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
381 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
382 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
386 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deselectAllButton, selectAllButton});
388 layout.setVerticalGroup(
389 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
390 .addGroup(layout.createSequentialGroup()
392 .addComponent(dataLabel)
393 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
394 .addComponent(allResultsRadioButton)
395 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
396 .addComponent(allTaggedResultsRadioButton)
397 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
398 .addComponent(specificTaggedResultsRadioButton)
400 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
401 .addGroup(layout.createSequentialGroup()
402 .addComponent(selectAllButton)
403 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
404 .addComponent(deselectAllButton)
405 .addGap(136, 136, 136))
406 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
408 .addComponent(tagsScrollPane)
410 .addComponent(advancedButton)))
415 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
416 setAllTaggedResultsSelected(
true);
417 wizPanel.setFinish(
true);
420 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
421 setAllTaggedResultsSelected(
false);
422 wizPanel.setFinish(
false);
425 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
426 artifactStates = dialog.display();
429 private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
430 setAllTaggedResultsSelected(
false);
433 private void allTaggedResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
434 setAllTaggedResultsSelected(
true);
438 private javax.swing.JButton advancedButton;
439 private javax.swing.JRadioButton allResultsRadioButton;
440 private javax.swing.JRadioButton allTaggedResultsRadioButton;
441 private javax.swing.JLabel dataLabel;
442 private javax.swing.JButton deselectAllButton;
443 private javax.swing.ButtonGroup optionsButtonGroup;
444 private javax.swing.JButton selectAllButton;
445 private javax.swing.JRadioButton specificTaggedResultsRadioButton;
446 private javax.swing.JList<String> tagsList;
447 private javax.swing.JScrollPane tagsScrollPane;
459 return tags.get(index);
477 setEnabled(list.isEnabled());
478 setSelected(tagStates.get(value));
479 setFont(list.getFont());
480 setBackground(list.getBackground());
481 setForeground(list.getForeground());