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;
49 final class ReportVisualPanel2
extends JPanel {
51 private ReportWizardPanel2 wizPanel;
52 private Map<String, Boolean> tagStates =
new LinkedHashMap<>();
53 private List<String> tags =
new ArrayList<>();
54 ArtifactSelectionDialog dialog =
new ArtifactSelectionDialog((JFrame) WindowManager.getDefault().getMainWindow(),
true);
55 private Map<BlackboardArtifact.Type, Boolean> artifactStates =
new HashMap<>();
56 private List<BlackboardArtifact.Type> artifacts =
new ArrayList<>();
57 private TagsListModel tagsModel;
58 private TagsListRenderer tagsRenderer;
63 public ReportVisualPanel2(ReportWizardPanel2 wizPanel) {
67 tagsList.setEnabled(
false);
68 selectAllButton.setEnabled(
false);
69 deselectAllButton.setEnabled(
false);
70 allResultsRadioButton.setSelected(
true);
71 this.wizPanel = wizPanel;
72 this.allResultsRadioButton.addChangeListener(
new ChangeListener() {
74 public void stateChanged(ChangeEvent e) {
75 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
76 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
77 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
78 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
82 this.taggedResultsRadioButton.addChangeListener(
new ChangeListener() {
84 public void stateChanged(ChangeEvent e) {
85 tagsList.setEnabled(taggedResultsRadioButton.isSelected());
86 selectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
87 deselectAllButton.setEnabled(taggedResultsRadioButton.isSelected());
88 advancedButton.setEnabled(!taggedResultsRadioButton.isSelected());
95 private void initTags() {
96 List<TagName> tagNamesInUse;
98 tagNamesInUse = Case.getCurrentCase().getServices().getTagsManager().getTagNamesInUse();
99 }
catch (TskCoreException ex) {
100 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
104 for (TagName tagName : tagNamesInUse) {
105 tagStates.put(tagName.getDisplayName(), Boolean.FALSE);
107 tags.addAll(tagStates.keySet());
109 tagsModel =
new TagsListModel();
110 tagsRenderer =
new TagsListRenderer();
111 tagsList.setModel(tagsModel);
112 tagsList.setCellRenderer(tagsRenderer);
113 tagsList.setVisibleRowCount(-1);
116 tagsList.addMouseListener(
new MouseAdapter() {
118 public void mousePressed(MouseEvent evt) {
120 int index = tagsList.locationToIndex(evt.getPoint());
121 if (index < tagsModel.getSize() && index >= 0) {
122 String value = tagsModel.getElementAt(index);
123 tagStates.put(value, !tagStates.get(value));
125 updateFinishButton();
132 @SuppressWarnings(
"deprecation")
133 private
void initArtifactTypes() {
136 ArrayList<BlackboardArtifact.Type> doNotReport =
new ArrayList<>();
137 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getTypeID(),
138 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
139 BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
140 doNotReport.add(
new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
141 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
142 BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName()));
144 artifacts = Case.getCurrentCase().getSleuthkitCase().getArtifactTypesInUse();
146 artifacts.removeAll(doNotReport);
148 artifactStates =
new HashMap<>();
149 for (BlackboardArtifact.Type type : artifacts) {
150 artifactStates.put(type, Boolean.TRUE);
152 }
catch (TskCoreException ex) {
153 Logger.getLogger(ReportVisualPanel2.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: " + ex.getLocalizedMessage(), ex);
158 public String getName() {
159 return NbBundle.getMessage(this.getClass(),
"ReportVisualPanel2.getName.text");
167 Map<BlackboardArtifact.Type, Boolean> getArtifactStates() {
168 return artifactStates;
174 Map<String, Boolean> getTagStates() {
178 private boolean areTagsSelected() {
179 boolean result =
false;
180 for (Entry<String, Boolean> entry : tagStates.entrySet()) {
181 if (entry.getValue()) {
188 private void updateFinishButton() {
189 if (taggedResultsRadioButton.isSelected()) {
190 wizPanel.setFinish(areTagsSelected());
192 wizPanel.setFinish(
true);
199 boolean isTaggedResultsRadioButtonSelected() {
200 return taggedResultsRadioButton.isSelected();
209 private void initComponents() {
211 optionsButtonGroup =
new javax.swing.ButtonGroup();
212 taggedResultsRadioButton =
new javax.swing.JRadioButton();
213 allResultsRadioButton =
new javax.swing.JRadioButton();
214 dataLabel =
new javax.swing.JLabel();
215 selectAllButton =
new javax.swing.JButton();
216 deselectAllButton =
new javax.swing.JButton();
217 tagsScrollPane =
new javax.swing.JScrollPane();
218 tagsList =
new javax.swing.JList<>();
219 advancedButton =
new javax.swing.JButton();
221 setPreferredSize(
new java.awt.Dimension(650, 250));
223 optionsButtonGroup.add(taggedResultsRadioButton);
224 org.openide.awt.Mnemonics.setLocalizedText(taggedResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.taggedResultsRadioButton.text"));
226 optionsButtonGroup.add(allResultsRadioButton);
227 org.openide.awt.Mnemonics.setLocalizedText(allResultsRadioButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.allResultsRadioButton.text"));
229 org.openide.awt.Mnemonics.setLocalizedText(dataLabel,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.dataLabel.text"));
231 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.selectAllButton.text"));
232 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 selectAllButtonActionPerformed(evt);
238 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.deselectAllButton.text"));
239 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
240 public void actionPerformed(java.awt.event.ActionEvent evt) {
241 deselectAllButtonActionPerformed(evt);
245 tagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
246 tagsList.setLayoutOrientation(javax.swing.JList.VERTICAL_WRAP);
247 tagsScrollPane.setViewportView(tagsList);
249 org.openide.awt.Mnemonics.setLocalizedText(advancedButton,
org.openide.util.NbBundle.getMessage(ReportVisualPanel2.class,
"ReportVisualPanel2.advancedButton.text"));
250 advancedButton.addActionListener(
new java.awt.event.ActionListener() {
251 public void actionPerformed(java.awt.event.ActionEvent evt) {
252 advancedButtonActionPerformed(evt);
256 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
257 this.setLayout(layout);
258 layout.setHorizontalGroup(
259 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addGroup(layout.createSequentialGroup()
262 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addGroup(layout.createSequentialGroup()
265 .addComponent(tagsScrollPane)
266 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
267 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
268 .addComponent(advancedButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
269 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
270 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
271 .addGroup(layout.createSequentialGroup()
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addComponent(taggedResultsRadioButton)
274 .addComponent(dataLabel)
275 .addComponent(allResultsRadioButton))
276 .addGap(0, 481, Short.MAX_VALUE)))
279 layout.setVerticalGroup(
280 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281 .addGroup(layout.createSequentialGroup()
283 .addComponent(dataLabel)
284 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
285 .addComponent(allResultsRadioButton)
286 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
287 .addComponent(taggedResultsRadioButton)
289 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
290 .addGroup(layout.createSequentialGroup()
291 .addComponent(selectAllButton)
292 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
293 .addComponent(deselectAllButton)
294 .addGap(0, 70, Short.MAX_VALUE))
295 .addComponent(tagsScrollPane))
296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
297 .addComponent(advancedButton)
302 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
303 for (String tag : tags) {
304 tagStates.put(tag, Boolean.TRUE);
307 wizPanel.setFinish(
true);
310 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
311 for (String tag : tags) {
312 tagStates.put(tag, Boolean.FALSE);
315 wizPanel.setFinish(
false);
318 private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {
319 artifactStates = dialog.display();
323 private javax.swing.JButton advancedButton;
324 private javax.swing.JRadioButton allResultsRadioButton;
325 private javax.swing.JLabel dataLabel;
326 private javax.swing.JButton deselectAllButton;
327 private javax.swing.ButtonGroup optionsButtonGroup;
328 private javax.swing.JButton selectAllButton;
329 private javax.swing.JRadioButton taggedResultsRadioButton;
330 private javax.swing.JList<String> tagsList;
331 private javax.swing.JScrollPane tagsScrollPane;
343 return tags.get(index);
361 setEnabled(list.isEnabled());
362 setSelected(tagStates.get(value.toString()));
363 setFont(list.getFont());
364 setBackground(list.getBackground());
365 setForeground(list.getForeground());
366 setText(value.toString());