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;
52 final class ReportVisualPanel2
extends JPanel {
54 private ReportWizardPanel2 wizPanel;
55 private Map<String, Boolean> tagStates =
new LinkedHashMap<>();
56 private List<String> tags =
new ArrayList<>();
57 ArtifactSelectionDialog dialog =
new ArtifactSelectionDialog((JFrame) WindowManager.getDefault().getMainWindow(),
true);
58 private Map<BlackboardArtifact.Type, Boolean> artifactStates =
new HashMap<>();
59 private List<BlackboardArtifact.Type> artifacts =
new ArrayList<>();
60 private TagsListModel tagsModel;
61 private TagsListRenderer tagsRenderer;
66 public ReportVisualPanel2(ReportWizardPanel2 wizPanel) {
70 tagsList.setEnabled(
false);
71 selectAllButton.setEnabled(
false);
72 deselectAllButton.setEnabled(
false);
73 allResultsRadioButton.setSelected(
true);
74 this.wizPanel = wizPanel;
75 this.allResultsRadioButton.addChangeListener(
new ChangeListener() {
77 public void stateChanged(ChangeEvent e) {
78 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
79 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
80 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
81 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
85 this.taggedResultsRadioButton.addChangeListener(
new ChangeListener() {
87 public void stateChanged(ChangeEvent e) {
88 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
89 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
90 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
91 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
98 private void initTags() {
99 List<TagName> tagNamesInUse;
101 tagNamesInUse = Case.getOpenCase().getServices().getTagsManager().getTagNamesInUse();
102 }
catch (TskCoreException | NoCurrentCaseException ex) {
103 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
107 for (TagName tagName : tagNamesInUse) {
108 String notableString = tagName.getKnownStatus() == TskData.FileKnown.BAD ? TagsManager.getNotableTagLabel() :
"";
109 tagStates.put(tagName.getDisplayName() + notableString, Boolean.FALSE);
111 tags.addAll(tagStates.keySet());
113 tagsModel =
new TagsListModel();
114 tagsRenderer =
new TagsListRenderer();
115 tagsList.setModel(tagsModel);
116 tagsList.setCellRenderer(tagsRenderer);
117 tagsList.setVisibleRowCount(-1);
120 tagsList.addMouseListener(
new MouseAdapter() {
122 public void mousePressed(MouseEvent evt) {
124 int index = tagsList.locationToIndex(evt.getPoint());
125 if (index < tagsModel.getSize() && index >= 0) {
126 String value = tagsModel.getElementAt(index);
127 tagStates.put(value, !tagStates.get(value));
129 updateFinishButton();
136 @SuppressWarnings(
"deprecation")
137 private
void initArtifactTypes() {
140 Case openCase = Case.getOpenCase();
141 ArrayList<BlackboardArtifact.Type> doNotReport =
new ArrayList<>();
142 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
143 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
144 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
145 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
146 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
147 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName()));
149 artifacts = openCase.getSleuthkitCase().getArtifactTypesInUse();
151 artifacts.removeAll(doNotReport);
153 artifactStates =
new HashMap<>();
154 for (BlackboardArtifact.Type type : artifacts) {
155 artifactStates.put(type, Boolean.TRUE);
157 }
catch (TskCoreException | NoCurrentCaseException ex) {
158 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex);
163 public String getName() {
164 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel2.getName.text");
172 Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
173 return artifactStates;
179 Map<String, Boolean> getTagStates() {
183 private boolean areTagsSelected() {
184 boolean result =
false;
185 for (Entry<String, Boolean> entry : tagStates.entrySet()) {
186 if (entry.getValue()) {
193 private void updateFinishButton() {
194 if (taggedResultsRadioButton.isSelected()) {
195 wizPanel.setFinish(areTagsSelected());
197 wizPanel.setFinish(
true);
204 boolean isTaggedResultsRadioButtonSelected() {
205 return taggedResultsRadioButton.isSelected();
214 private void initComponents() {
216 optionsButtonGroup =
new javax.swing.ButtonGroup();
217 taggedResultsRadioButton =
new javax.swing.JRadioButton();
218 allResultsRadioButton =
new javax.swing.JRadioButton();
219 dataLabel =
new javax.swing.JLabel();
220 selectAllButton =
new javax.swing.JButton();
221 deselectAllButton =
new javax.swing.JButton();
222 tagsScrollPane =
new javax.swing.JScrollPane();
223 tagsList =
new javax.swing.JList<>();
224 advancedButton =
new javax.swing.JButton();
226 setPreferredSize(
new java.awt.Dimension(650, 250));
228 optionsButtonGroup.add(taggedResultsRadioButton);
229 org.openide.awt.Mnemonics.setLocalizedText(taggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.taggedResultsRadioButton.text"));
231 optionsButtonGroup.add(allResultsRadioButton);
232 org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allResultsRadioButton.text"));
234 org.openide.awt.Mnemonics.setLocalizedText(dataLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.dataLabel.text"));
236 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.selectAllButton.text"));
237 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
238 public void actionPerformed(java.awt.event.ActionEvent evt) {
239 selectAllButtonActionPerformed(evt);
243 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.deselectAllButton.text"));
244 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
245 public void actionPerformed(java.awt.event.ActionEvent evt) {
246 deselectAllButtonActionPerformed(evt);
250 tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
251 tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
252 tagsScrollPane.setViewportView(tagsList);
254 org.openide.awt.Mnemonics.setLocalizedText(advancedButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.advancedButton.text"));
255 advancedButton.addActionListener(
new java.awt.event.ActionListener() {
256 public void actionPerformed(java.awt.event.ActionEvent evt) {
257 advancedButtonActionPerformed(evt);
261 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
262 this.setLayout(layout);
263 layout.setHorizontalGroup(
264 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
265 .addGroup(layout.createSequentialGroup()
267 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addGroup(layout.createSequentialGroup()
270 .addComponent(tagsScrollPane)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
273 .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
274 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
275 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
276 .addGroup(layout.createSequentialGroup()
277 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278 .addComponent(taggedResultsRadioButton)
279 .addComponent(dataLabel)
280 .addComponent(allResultsRadioButton))
281 .addGap(0, 0, Short.MAX_VALUE)))
285 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {advancedButton, deselectAllButton, selectAllButton});
287 layout.setVerticalGroup(
288 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289 .addGroup(layout.createSequentialGroup()
291 .addComponent(dataLabel)
292 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
293 .addComponent(allResultsRadioButton)
294 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
295 .addComponent(taggedResultsRadioButton)
297 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298 .addGroup(layout.createSequentialGroup()
299 .addComponent(selectAllButton)
300 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
301 .addComponent(deselectAllButton)
302 .addGap(0, 70, Short.MAX_VALUE))
303 .addComponent(tagsScrollPane))
304 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
305 .addComponent(advancedButton)
310 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
311 for (String tag : tags) {
312 tagStates.put(tag, Boolean.TRUE);
315 wizPanel.setFinish(
true);
318 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
319 for (String tag : tags) {
320 tagStates.put(tag, Boolean.FALSE);
323 wizPanel.setFinish(
false);
326 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
327 artifactStates = dialog.display();
331 private javax.swing.JButton advancedButton;
332 private javax.swing.JRadioButton allResultsRadioButton;
333 private javax.swing.JLabel dataLabel;
334 private javax.swing.JButton deselectAllButton;
335 private javax.swing.ButtonGroup optionsButtonGroup;
336 private javax.swing.JButton selectAllButton;
337 private javax.swing.JRadioButton taggedResultsRadioButton;
338 private javax.swing.JList<String> tagsList;
339 private javax.swing.JScrollPane tagsScrollPane;
351 return tags.get(index);
369 setEnabled(list.isEnabled());
370 setSelected(tagStates.get(value.toString()));
371 setFont(list.getFont());
372 setBackground(list.getBackground());
373 setForeground(list.getForeground());
374 setText(value.toString());