Autopsy  3.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 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.Dimension;
23 import java.awt.Toolkit;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.util.ArrayList;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.EnumMap;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.logging.Level;
33 import javax.swing.JCheckBox;
34 import javax.swing.JLabel;
35 import javax.swing.JList;
36 import javax.swing.ListCellRenderer;
37 import javax.swing.ListModel;
38 import javax.swing.event.ListDataListener;
39 import org.openide.util.NbBundle;
45 
46 public class ArtifactSelectionDialog extends javax.swing.JDialog {
47 
52 
56  public ArtifactSelectionDialog(java.awt.Frame parent, boolean modal) {
57  super(parent, modal);
59  populateList();
60  customInit();
61  }
62 
66  @SuppressWarnings("deprecation")
67  private void populateList() {
68  try {
69  ArrayList<BlackboardArtifact.ARTIFACT_TYPE> doNotReport = new ArrayList<>();
71  doNotReport.add(BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT); // output is too unstructured for table review.
72 
74  artifacts.removeAll(doNotReport);
75  Collections.sort(artifacts, new Comparator<BlackboardArtifact.ARTIFACT_TYPE>() {
76  @Override
77  public int compare(ARTIFACT_TYPE o1, ARTIFACT_TYPE o2) {
78  return o1.getDisplayName().compareTo(o2.getDisplayName());
79  }
80  });
81 
82  artifactStates = new EnumMap<>(BlackboardArtifact.ARTIFACT_TYPE.class);
84  artifactStates.put(type, Boolean.TRUE);
85  }
86  } catch (TskCoreException ex) {
87  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage()); //NON-NLS
88  }
89  }
90 
91  private void customInit() {
92  model = new ArtifactModel();
93  renderer = new ArtifactRenderer();
94  artifactList.setModel(model);
95  artifactList.setCellRenderer(renderer);
96  artifactList.setVisibleRowCount(-1);
97 
98  artifactList.addMouseListener(new MouseAdapter() {
99  @Override
100  public void mousePressed(MouseEvent evt) {
101  int index = artifactList.locationToIndex(evt.getPoint());
102  BlackboardArtifact.ARTIFACT_TYPE type = model.getElementAt(index);
103  artifactStates.put(type, !artifactStates.get(type));
104  artifactList.repaint();
105  }
106  });
107  }
108 
112  Map<BlackboardArtifact.ARTIFACT_TYPE, Boolean> display() {
113  this.setTitle(NbBundle.getMessage(this.getClass(), "ArtifactSelectionDialog.dlgTitle.text"));
114  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
115  // set the popUp window / JFrame
116  int w = this.getSize().width;
117  int h = this.getSize().height;
118 
119  // set the location of the popUp Window on the center of the screen
120  setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
121 
122  this.setVisible(true);
123  return artifactStates;
124  }
125 
131  @SuppressWarnings("unchecked")
132  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
133  private void initComponents() {
134 
135  artifactScrollPane = new javax.swing.JScrollPane();
136  artifactList = new javax.swing.JList<>();
137  okButton = new javax.swing.JButton();
138  titleLabel = new javax.swing.JLabel();
139  selectAllButton = new javax.swing.JButton();
140  deselectAllButton = new javax.swing.JButton();
141 
142  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
143 
144  artifactList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
145  artifactList.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
146  artifactScrollPane.setViewportView(artifactList);
147 
148  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.okButton.text")); // NOI18N
149  okButton.addActionListener(new java.awt.event.ActionListener() {
150  public void actionPerformed(java.awt.event.ActionEvent evt) {
152  }
153  });
154 
155  org.openide.awt.Mnemonics.setLocalizedText(titleLabel, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.titleLabel.text")); // NOI18N
156 
157  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.selectAllButton.text")); // NOI18N
158  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
161  }
162  });
163 
164  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class, "ArtifactSelectionDialog.deselectAllButton.text")); // NOI18N
165  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
166  public void actionPerformed(java.awt.event.ActionEvent evt) {
168  }
169  });
170 
171  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
172  getContentPane().setLayout(layout);
173  layout.setHorizontalGroup(
174  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175  .addGroup(layout.createSequentialGroup()
176  .addContainerGap()
177  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addGroup(layout.createSequentialGroup()
179  .addComponent(artifactScrollPane)
180  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
181  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
182  .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
183  .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
184  .addGroup(layout.createSequentialGroup()
185  .addComponent(titleLabel)
186  .addGap(0, 221, Short.MAX_VALUE))
187  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
188  .addGap(0, 0, Short.MAX_VALUE)
189  .addComponent(okButton)))
190  .addContainerGap())
191  );
192  layout.setVerticalGroup(
193  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194  .addGroup(layout.createSequentialGroup()
195  .addContainerGap()
196  .addComponent(titleLabel)
197  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199  .addComponent(artifactScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
200  .addGroup(layout.createSequentialGroup()
201  .addComponent(selectAllButton)
202  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203  .addComponent(deselectAllButton)
204  .addGap(0, 0, Short.MAX_VALUE)))
205  .addGap(11, 11, 11)
206  .addComponent(okButton)
207  .addContainerGap())
208  );
209 
210  pack();
211  }// </editor-fold>//GEN-END:initComponents
212 
213  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
214  dispose();
215  }//GEN-LAST:event_okButtonActionPerformed
216 
217  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
218  for (ARTIFACT_TYPE type : artifacts) {
219  artifactStates.put(type, Boolean.TRUE);
220  }
221  artifactList.repaint();
222  }//GEN-LAST:event_selectAllButtonActionPerformed
223 
224  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
225  for (ARTIFACT_TYPE type : artifacts) {
226  artifactStates.put(type, Boolean.FALSE);
227  }
228  artifactList.repaint();
229  }//GEN-LAST:event_deselectAllButtonActionPerformed
230  // Variables declaration - do not modify//GEN-BEGIN:variables
231  private javax.swing.JList<ARTIFACT_TYPE> artifactList;
232  private javax.swing.JScrollPane artifactScrollPane;
233  private javax.swing.JButton deselectAllButton;
234  private javax.swing.JButton okButton;
235  private javax.swing.JButton selectAllButton;
236  private javax.swing.JLabel titleLabel;
237  // End of variables declaration//GEN-END:variables
238 
239  private class ArtifactModel implements ListModel<ARTIFACT_TYPE> {
240 
241  @Override
242  public int getSize() {
243  return artifacts.size();
244  }
245 
246  @Override
247  public ARTIFACT_TYPE getElementAt(int index) {
248  return artifacts.get(index);
249  }
250 
251  @Override
252  public void addListDataListener(ListDataListener l) {
253  }
254 
255  @Override
256  public void removeListDataListener(ListDataListener l) {
257  }
258  }
259 
260  private class ArtifactRenderer extends JCheckBox implements ListCellRenderer<BlackboardArtifact.ARTIFACT_TYPE> {
261 
262  @Override
263  public Component getListCellRendererComponent(JList<? extends ARTIFACT_TYPE> list, ARTIFACT_TYPE value, int index, boolean isSelected, boolean cellHasFocus) {
264  if (value != null) {
265  setEnabled(list.isEnabled());
266  setSelected(artifactStates.get(value));
267  setFont(list.getFont());
268  setBackground(list.getBackground());
269  setForeground(list.getForeground());
270  setText(value.getDisplayName());
271  return this;
272  }
273  return new JLabel();
274  }
275  }
276 }
ArtifactSelectionDialog(java.awt.Frame parent, boolean modal)
void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt)
Component getListCellRendererComponent(JList<?extends ARTIFACT_TYPE > list, ARTIFACT_TYPE value, int index, boolean isSelected, boolean cellHasFocus)
Map< BlackboardArtifact.ARTIFACT_TYPE, Boolean > artifactStates
void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt)
ArrayList< BlackboardArtifact.ARTIFACT_TYPE > getBlackboardArtifactTypesInUse()
static Logger getLogger(String name)
Definition: Logger.java:131

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.