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