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