Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ArtifactSelectionDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.report.infrastructure;
20 
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.Collections;
26 import java.util.Comparator;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.logging.Level;
31 import javax.swing.JCheckBox;
32 import javax.swing.JLabel;
33 import javax.swing.JList;
34 import javax.swing.ListCellRenderer;
35 import javax.swing.ListModel;
36 import javax.swing.event.ListDataListener;
37 import org.openide.util.NbBundle;
41 import org.sleuthkit.datamodel.BlackboardArtifact;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
47 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
48 class ArtifactSelectionDialog extends javax.swing.JDialog {
49 
50  private ArtifactModel model;
51  private ArtifactRenderer renderer;
52  private Map<BlackboardArtifact.Type, Boolean> artifactTypeSelections = new HashMap<>();
53  private List<BlackboardArtifact.Type> artifactTypes = new ArrayList<>();
54 
61  ArtifactSelectionDialog(java.awt.Frame parent, boolean modal) {
62  super(parent, modal);
63  initComponents();
64  populateList();
65  customInit();
66  }
67 
71  @SuppressWarnings("deprecation")
72  private void populateList() {
73  try {
74  ArrayList<BlackboardArtifact.Type> doNotReport = new ArrayList<>();
75  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO));
76  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT)); // output is too unstructured for table review
77  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT));
78  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT));
79 
80  artifactTypes = Case.getCurrentCaseThrows().getSleuthkitCase().getArtifactTypesInUse();
81  artifactTypes.removeAll(doNotReport);
82  Collections.sort(artifactTypes, new Comparator<BlackboardArtifact.Type>() {
83  @Override
84  public int compare(BlackboardArtifact.Type o1, BlackboardArtifact.Type o2) {
85  return o1.getDisplayName().compareTo(o2.getDisplayName());
86  }
87  });
88 
89  artifactTypeSelections = new HashMap<>();
90  for (BlackboardArtifact.Type type : artifactTypes) {
91  artifactTypeSelections.put(type, Boolean.TRUE);
92  }
93  } catch (TskCoreException ex) {
94  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: {0}", ex.getLocalizedMessage()); //NON-NLS
95  } catch (NoCurrentCaseException ex) {
96  // There may not be a case open, for example when configuring Command Line reports
97  if (Case.isCaseOpen()) {
98  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex.getLocalizedMessage()); //NON-NLS
99  }
100  }
101  }
102 
103  private void customInit() {
104  model = new ArtifactModel();
105  renderer = new ArtifactRenderer();
106  artifactList.setModel(model);
107  artifactList.setCellRenderer(renderer);
108  artifactList.setVisibleRowCount(-1);
109 
110  artifactList.addMouseListener(new MouseAdapter() {
111  @Override
112  public void mousePressed(MouseEvent evt) {
113  int index = artifactList.locationToIndex(evt.getPoint());
114  if (index >= 0) {
115  BlackboardArtifact.Type type = model.getElementAt(index);
116  artifactTypeSelections.put(type, !artifactTypeSelections.get(type));
117  artifactList.repaint();
118  }
119  }
120  });
121  }
122 
128  Map<BlackboardArtifact.Type, Boolean> display() {
129  this.setTitle(NbBundle.getMessage(this.getClass(), "ArtifactSelectionDialog.dlgTitle.text"));
130  this.setLocationRelativeTo(getOwner());
131  this.setVisible(true);
132  return artifactTypeSelections;
133  }
134 
140  @SuppressWarnings("unchecked")
141  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
142  private void initComponents() {
143 
144  artifactScrollPane = new javax.swing.JScrollPane();
145  artifactList = new javax.swing.JList<>();
146  okButton = new javax.swing.JButton();
147  titleLabel = new javax.swing.JLabel();
148  selectAllButton = new javax.swing.JButton();
149  deselectAllButton = new javax.swing.JButton();
150 
151  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
152 
153  artifactList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
154  artifactList.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
155  artifactScrollPane.setViewportView(artifactList);
156 
157  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.okButton.text")); // NOI18N
158  okButton.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  okButtonActionPerformed(evt);
161  }
162  });
163 
164  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.titleLabel.text")); // NOI18N
165  titleLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.titleLabel.toolTipText")); // NOI18N
166 
167  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.selectAllButton.text")); // NOI18N
168  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
169  public void actionPerformed(java.awt.event.ActionEvent evt) {
170  selectAllButtonActionPerformed(evt);
171  }
172  });
173 
174  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.deselectAllButton.text")); // NOI18N
175  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
176  public void actionPerformed(java.awt.event.ActionEvent evt) {
177  deselectAllButtonActionPerformed(evt);
178  }
179  });
180 
181  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
182  getContentPane().setLayout(layout);
183  layout.setHorizontalGroup(
184  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
185  .addGroup(layout.createSequentialGroup()
186  .addContainerGap()
187  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188  .addGroup(layout.createSequentialGroup()
189  .addComponent(artifactScrollPane)
190  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
191  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
192  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
194  .addGroup(layout.createSequentialGroup()
195  .addComponent(titleLabel)
196  .addGap(0, 195, Short.MAX_VALUE))
197  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
198  .addGap(0, 0, Short.MAX_VALUE)
199  .addComponent(okButton)))
200  .addContainerGap())
201  );
202  layout.setVerticalGroup(
203  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addGroup(layout.createSequentialGroup()
205  .addContainerGap()
206  .addComponent(titleLabel)
207  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
208  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209  .addComponent(artifactScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
210  .addGroup(layout.createSequentialGroup()
211  .addComponent(selectAllButton)
212  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
213  .addComponent(deselectAllButton)
214  .addGap(0, 0, Short.MAX_VALUE)))
215  .addGap(11, 11, 11)
216  .addComponent(okButton)
217  .addContainerGap())
218  );
219 
220  pack();
221  }// </editor-fold>//GEN-END:initComponents
222 
223  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
224  dispose();
225  }//GEN-LAST:event_okButtonActionPerformed
226 
227  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
228  for (BlackboardArtifact.Type type : artifactTypes) {
229  artifactTypeSelections.put(type, Boolean.TRUE);
230  }
231  artifactList.repaint();
232  }//GEN-LAST:event_selectAllButtonActionPerformed
233 
234  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
235  for (BlackboardArtifact.Type type : artifactTypes) {
236  artifactTypeSelections.put(type, Boolean.FALSE);
237  }
238  artifactList.repaint();
239  }//GEN-LAST:event_deselectAllButtonActionPerformed
240  // Variables declaration - do not modify//GEN-BEGIN:variables
241  private javax.swing.JList<BlackboardArtifact.Type> artifactList;
242  private javax.swing.JScrollPane artifactScrollPane;
243  private javax.swing.JButton deselectAllButton;
244  private javax.swing.JButton okButton;
245  private javax.swing.JButton selectAllButton;
246  private javax.swing.JLabel titleLabel;
247  // End of variables declaration//GEN-END:variables
248 
249  private class ArtifactModel implements ListModel<BlackboardArtifact.Type> {
250 
251  @Override
252  public int getSize() {
253  return artifactTypes.size();
254  }
255 
256  @Override
257  public BlackboardArtifact.Type getElementAt(int index) {
258  return artifactTypes.get(index);
259  }
260 
261  @Override
262  public void addListDataListener(ListDataListener l) {
263  }
264 
265  @Override
266  public void removeListDataListener(ListDataListener l) {
267  }
268  }
269 
270  private class ArtifactRenderer extends JCheckBox implements ListCellRenderer<BlackboardArtifact.Type> {
271 
272  @Override
273  public Component getListCellRendererComponent(JList<? extends BlackboardArtifact.Type> list, BlackboardArtifact.Type value, int index, boolean isSelected, boolean cellHasFocus) {
274  if (value != null) {
275  setEnabled(list.isEnabled());
276  setSelected(artifactTypeSelections.get(value));
277  setFont(list.getFont());
278  setBackground(list.getBackground());
279  setForeground(list.getForeground());
280  setText(value.getDisplayName());
281  return this;
282  }
283  return new JLabel();
284  }
285  }
286 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
Component getListCellRendererComponent(JList<?extends BlackboardArtifact.Type > list, BlackboardArtifact.Type value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.