Autopsy  4.16.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.getTypeID(),
76  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getLabel(),
77  BlackboardArtifact.ARTIFACT_TYPE.TSK_GEN_INFO.getDisplayName()));
78  doNotReport.add(new BlackboardArtifact.Type(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getTypeID(),
79  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getLabel(),
80  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
81  doNotReport.add(new BlackboardArtifact.Type(
82  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getTypeID(),
83  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getLabel(),
84  BlackboardArtifact.ARTIFACT_TYPE.TSK_ASSOCIATED_OBJECT.getDisplayName()));
85  doNotReport.add(new BlackboardArtifact.Type(
86  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getTypeID(),
87  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getLabel(),
88  BlackboardArtifact.ARTIFACT_TYPE.TSK_TL_EVENT.getDisplayName()));
89 
90  artifactTypes = Case.getCurrentCaseThrows().getSleuthkitCase().getArtifactTypesInUse();
91  artifactTypes.removeAll(doNotReport);
92  Collections.sort(artifactTypes, new Comparator<BlackboardArtifact.Type>() {
93  @Override
94  public int compare(BlackboardArtifact.Type o1, BlackboardArtifact.Type o2) {
95  return o1.getDisplayName().compareTo(o2.getDisplayName());
96  }
97  });
98 
99  artifactTypeSelections = new HashMap<>();
100  for (BlackboardArtifact.Type type : artifactTypes) {
101  artifactTypeSelections.put(type, Boolean.TRUE);
102  }
103  } catch (TskCoreException ex) {
104  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: {0}", ex.getLocalizedMessage()); //NON-NLS
105  } catch (NoCurrentCaseException ex) {
106  // There may not be a case open, for example when configuring Command Line reports
107  if (Case.isCaseOpen()) {
108  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Exception while getting open case.", ex.getLocalizedMessage()); //NON-NLS
109  }
110  }
111  }
112 
113  private void customInit() {
114  model = new ArtifactModel();
115  renderer = new ArtifactRenderer();
116  artifactList.setModel(model);
117  artifactList.setCellRenderer(renderer);
118  artifactList.setVisibleRowCount(-1);
119 
120  artifactList.addMouseListener(new MouseAdapter() {
121  @Override
122  public void mousePressed(MouseEvent evt) {
123  int index = artifactList.locationToIndex(evt.getPoint());
124  if (index >= 0) {
125  BlackboardArtifact.Type type = model.getElementAt(index);
126  artifactTypeSelections.put(type, !artifactTypeSelections.get(type));
127  artifactList.repaint();
128  }
129  }
130  });
131  }
132 
138  Map<BlackboardArtifact.Type, Boolean> display() {
139  this.setTitle(NbBundle.getMessage(this.getClass(), "ArtifactSelectionDialog.dlgTitle.text"));
140  this.setLocationRelativeTo(getOwner());
141  this.setVisible(true);
142  return artifactTypeSelections;
143  }
144 
150  @SuppressWarnings("unchecked")
151  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
152  private void initComponents() {
153 
154  artifactScrollPane = new javax.swing.JScrollPane();
155  artifactList = new javax.swing.JList<>();
156  okButton = new javax.swing.JButton();
157  titleLabel = new javax.swing.JLabel();
158  selectAllButton = new javax.swing.JButton();
159  deselectAllButton = new javax.swing.JButton();
160 
161  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
162 
163  artifactList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
164  artifactList.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
165  artifactScrollPane.setViewportView(artifactList);
166 
167  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.okButton.text")); // NOI18N
168  okButton.addActionListener(new java.awt.event.ActionListener() {
169  public void actionPerformed(java.awt.event.ActionEvent evt) {
170  okButtonActionPerformed(evt);
171  }
172  });
173 
174  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.titleLabel.text")); // NOI18N
175  titleLabel.setToolTipText(org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.titleLabel.toolTipText")); // NOI18N
176 
177  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.selectAllButton.text")); // NOI18N
178  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
179  public void actionPerformed(java.awt.event.ActionEvent evt) {
180  selectAllButtonActionPerformed(evt);
181  }
182  });
183 
184  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.deselectAllButton.text")); // NOI18N
185  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
186  public void actionPerformed(java.awt.event.ActionEvent evt) {
187  deselectAllButtonActionPerformed(evt);
188  }
189  });
190 
191  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
192  getContentPane().setLayout(layout);
193  layout.setHorizontalGroup(
194  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addGroup(layout.createSequentialGroup()
196  .addContainerGap()
197  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198  .addGroup(layout.createSequentialGroup()
199  .addComponent(artifactScrollPane)
200  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
201  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
202  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
203  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
204  .addGroup(layout.createSequentialGroup()
205  .addComponent(titleLabel)
206  .addGap(0, 195, Short.MAX_VALUE))
207  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
208  .addGap(0, 0, Short.MAX_VALUE)
209  .addComponent(okButton)))
210  .addContainerGap())
211  );
212  layout.setVerticalGroup(
213  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214  .addGroup(layout.createSequentialGroup()
215  .addContainerGap()
216  .addComponent(titleLabel)
217  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
218  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
219  .addComponent(artifactScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
220  .addGroup(layout.createSequentialGroup()
221  .addComponent(selectAllButton)
222  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
223  .addComponent(deselectAllButton)
224  .addGap(0, 0, Short.MAX_VALUE)))
225  .addGap(11, 11, 11)
226  .addComponent(okButton)
227  .addContainerGap())
228  );
229 
230  pack();
231  }// </editor-fold>//GEN-END:initComponents
232 
233  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
234  dispose();
235  }//GEN-LAST:event_okButtonActionPerformed
236 
237  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
238  for (BlackboardArtifact.Type type : artifactTypes) {
239  artifactTypeSelections.put(type, Boolean.TRUE);
240  }
241  artifactList.repaint();
242  }//GEN-LAST:event_selectAllButtonActionPerformed
243 
244  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
245  for (BlackboardArtifact.Type type : artifactTypes) {
246  artifactTypeSelections.put(type, Boolean.FALSE);
247  }
248  artifactList.repaint();
249  }//GEN-LAST:event_deselectAllButtonActionPerformed
250  // Variables declaration - do not modify//GEN-BEGIN:variables
251  private javax.swing.JList<BlackboardArtifact.Type> artifactList;
252  private javax.swing.JScrollPane artifactScrollPane;
253  private javax.swing.JButton deselectAllButton;
254  private javax.swing.JButton okButton;
255  private javax.swing.JButton selectAllButton;
256  private javax.swing.JLabel titleLabel;
257  // End of variables declaration//GEN-END:variables
258 
259  private class ArtifactModel implements ListModel<BlackboardArtifact.Type> {
260 
261  @Override
262  public int getSize() {
263  return artifactTypes.size();
264  }
265 
266  @Override
267  public BlackboardArtifact.Type getElementAt(int index) {
268  return artifactTypes.get(index);
269  }
270 
271  @Override
272  public void addListDataListener(ListDataListener l) {
273  }
274 
275  @Override
276  public void removeListDataListener(ListDataListener l) {
277  }
278  }
279 
280  private class ArtifactRenderer extends JCheckBox implements ListCellRenderer<BlackboardArtifact.Type> {
281 
282  @Override
283  public Component getListCellRendererComponent(JList<? extends BlackboardArtifact.Type> list, BlackboardArtifact.Type value, int index, boolean isSelected, boolean cellHasFocus) {
284  if (value != null) {
285  setEnabled(list.isEnabled());
286  setSelected(artifactTypeSelections.get(value));
287  setFont(list.getFont());
288  setBackground(list.getBackground());
289  setForeground(list.getForeground());
290  setText(value.getDisplayName());
291  return this;
292  }
293  return new JLabel();
294  }
295  }
296 }
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-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.