19 package org.sleuthkit.autopsy.report;
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;
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;
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 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 TagsListModel tagsModel;
65 private TagsListRenderer tagsRenderer;
70 public ReportVisualPanel2(ReportWizardPanel2 wizPanel) {
74 tagsList.setEnabled(
false);
75 selectAllButton.setEnabled(
false);
76 deselectAllButton.setEnabled(
false);
77 allResultsRadioButton.setSelected(
true);
78 this.wizPanel = wizPanel;
79 this.allResultsRadioButton.addChangeListener(
new ChangeListener() {
81 public void stateChanged(ChangeEvent e) {
82 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
83 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
84 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
85 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
89 this.taggedResultsRadioButton.addChangeListener(
new ChangeListener() {
91 public void stateChanged(ChangeEvent e) {
92 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
93 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
94 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
95 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
102 private void initTags() {
103 List<TagName> tagNamesInUse;
105 tagNamesInUse = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
106 }
catch (TskCoreException | NoCurrentCaseException ex) {
107 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
111 for (TagName tagName : tagNamesInUse) {
112 String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
113 tagStates.put(tagName.getDisplayName() + notableString, Boolean.FALSE);
115 tags.addAll(tagStates.keySet());
117 tagsModel =
new TagsListModel();
118 tagsRenderer =
new TagsListRenderer();
119 tagsList.setModel(tagsModel);
120 tagsList.setCellRenderer(tagsRenderer);
121 tagsList.setVisibleRowCount(-1);
124 tagsList.addMouseListener(
new MouseAdapter() {
126 public void mousePressed(MouseEvent evt) {
127 if (!taggedResultsRadioButton.isSelected()) {
130 int index = tagsList.locationToIndex(evt.getPoint());
131 if (index < tagsModel.getSize() && index >= 0) {
132 String value = tagsModel.getElementAt(index);
133 tagStates.put(value, !tagStates.get(value));
135 updateFinishButton();
142 @SuppressWarnings(
"deprecation")
143 private
void initArtifactTypes() {
146 Case openCase = Case.getCurrentCaseThrows();
147 ArrayList<BlackboardArtifact.Type> doNotReport =
new ArrayList<>();
148 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
149 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
150 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
151 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
152 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
153 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName()));
155 artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
157 artifacts.removeAll(doNotReport);
159 artifactStates =
new HashMap<>();
160 for (BlackboardArtifact.Type type : artifacts) {
161 artifactStates.put(type, Boolean.TRUE);
163 }
catch (TskCoreException | NoCurrentCaseException ex) {
164 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex);
169 public String getName() {
170 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel2.getName.text");
178 Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
179 return artifactStates;
185 Map<String, Boolean> getTagStates() {
194 private boolean areTagsSelected() {
195 boolean result =
false;
196 for (Entry<String, Boolean> entry : tagStates.entrySet()) {
197 if (entry.getValue()) {
209 private void updateFinishButton() {
210 if (taggedResultsRadioButton.isSelected()) {
211 wizPanel.setFinish(areTagsSelected());
213 wizPanel.setFinish(
true);
220 boolean isTaggedResultsRadioButtonSelected() {
221 return taggedResultsRadioButton.isSelected();
229 void setAllTaggedResultsSelected(
boolean selected) {
230 for (String tag : tags) {
231 tagStates.put(tag, (selected ? Boolean.TRUE : Boolean.FALSE));
234 wizPanel.setFinish(selected);
243 private void initComponents() {
245 optionsButtonGroup =
new javax.swing.ButtonGroup();
246 taggedResultsRadioButton =
new javax.swing.JRadioButton();
247 allResultsRadioButton =
new javax.swing.JRadioButton();
248 dataLabel =
new javax.swing.JLabel();
249 selectAllButton =
new javax.swing.JButton();
250 deselectAllButton =
new javax.swing.JButton();
251 tagsScrollPane =
new javax.swing.JScrollPane();
252 tagsList =
new javax.swing.JList<>();
253 advancedButton =
new javax.swing.JButton();
255 setPreferredSize(
new java.awt.Dimension(650, 250));
257 optionsButtonGroup.add(taggedResultsRadioButton);
258 org.openide.awt.Mnemonics.setLocalizedText(taggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.taggedResultsRadioButton.text"));
260 optionsButtonGroup.add(allResultsRadioButton);
261 org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allResultsRadioButton.text"));
262 allResultsRadioButton.addActionListener(
new java.awt.event.ActionListener() {
263 public void actionPerformed(java.awt.event.ActionEvent evt) {
264 allResultsRadioButtonActionPerformed(evt);
268 org.openide.awt.Mnemonics.setLocalizedText(dataLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.dataLabel.text"));
270 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.selectAllButton.text"));
271 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
272 public void actionPerformed(java.awt.event.ActionEvent evt) {
273 selectAllButtonActionPerformed(evt);
277 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.deselectAllButton.text"));
278 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
279 public void actionPerformed(java.awt.event.ActionEvent evt) {
280 deselectAllButtonActionPerformed(evt);
284 tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
285 tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
286 tagsScrollPane.setViewportView(tagsList);
288 org.openide.awt.Mnemonics.setLocalizedText(advancedButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.advancedButton.text"));
289 advancedButton.addActionListener(
new java.awt.event.ActionListener() {
290 public void actionPerformed(java.awt.event.ActionEvent evt) {
291 advancedButtonActionPerformed(evt);
295 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
296 this.setLayout(layout);
297 layout.setHorizontalGroup(
298 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
299 .addGroup(layout.createSequentialGroup()
301 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(layout.createSequentialGroup()
304 .addComponent(tagsScrollPane)
305 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
306 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
307 .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
308 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
309 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
310 .addGroup(layout.createSequentialGroup()
311 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
312 .addComponent(taggedResultsRadioButton)
313 .addComponent(dataLabel)
314 .addComponent(allResultsRadioButton))
315 .addGap(0, 0, Short.MAX_VALUE)))
319 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
321 layout.setVerticalGroup(
322 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
323 .addGroup(layout.createSequentialGroup()
325 .addComponent(dataLabel)
326 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
327 .addComponent(allResultsRadioButton)
328 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
329 .addComponent(taggedResultsRadioButton)
331 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
332 .addGroup(layout.createSequentialGroup()
333 .addComponent(selectAllButton)
334 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
335 .addComponent(deselectAllButton)
336 .addGap(0, 70, Short.MAX_VALUE))
337 .addComponent(tagsScrollPane))
338 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339 .addComponent(advancedButton)
344 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
345 setAllTaggedResultsSelected(
true);
348 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
349 setAllTaggedResultsSelected(
false);
352 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
353 artifactStates = dialog.display();
356 private void allResultsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
357 setAllTaggedResultsSelected(
false);
361 private javax.swing.JButton advancedButton;
362 private javax.swing.JRadioButton allResultsRadioButton;
363 private javax.swing.JLabel dataLabel;
364 private javax.swing.JButton deselectAllButton;
365 private javax.swing.ButtonGroup optionsButtonGroup;
366 private javax.swing.JButton selectAllButton;
367 private javax.swing.JRadioButton taggedResultsRadioButton;
368 private javax.swing.JList<String> tagsList;
369 private javax.swing.JScrollPane tagsScrollPane;
381 return tags.get(index);
399 setEnabled(list.isEnabled());
400 setSelected(tagStates.get(value));
401 setFont(list.getFont());
402 setBackground(list.getBackground());
403 setForeground(list.getForeground());