Autopsy  4.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.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.logging.Level;
34 import javax.swing.JCheckBox;
35 import javax.swing.JLabel;
36 import javax.swing.JList;
37 import javax.swing.ListCellRenderer;
38 import javax.swing.ListModel;
39 import javax.swing.event.ListDataListener;
40 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.Type> doNotReport = new ArrayList<>();
75  BlackboardArtifact.ARTIFACT_TYPE.TSK_TOOL_OUTPUT.getDisplayName())); // output is too unstructured for table review
76 
78  artifactTypes.removeAll(doNotReport);
79  Collections.sort(artifactTypes, new Comparator<BlackboardArtifact.Type>() {
80  @Override
81  public int compare(BlackboardArtifact.Type o1, BlackboardArtifact.Type o2) {
82  return o1.getDisplayName().compareTo(o2.getDisplayName());
83  }
84  });
85 
86  artifactTypeSelections = new HashMap<>();
88  artifactTypeSelections.put(type, Boolean.TRUE);
89  }
90  } catch (TskCoreException ex) {
91  Logger.getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE, "Error getting list of artifacts in use: " + ex.getLocalizedMessage()); //NON-NLS
92  }
93  }
94 
95  private void customInit() {
96  model = new ArtifactModel();
97  renderer = new ArtifactRenderer();
98  artifactList.setModel(model);
99  artifactList.setCellRenderer(renderer);
100  artifactList.setVisibleRowCount(-1);
101 
102  artifactList.addMouseListener(new MouseAdapter() {
103  @Override
104  public void mousePressed(MouseEvent evt) {
105  int index = artifactList.locationToIndex(evt.getPoint());
106  BlackboardArtifact.Type type = model.getElementAt(index);
107  artifactTypeSelections.put(type, !artifactTypeSelections.get(type));
108  artifactList.repaint();
109  }
110  });
111  }
112 
118  Map<BlackboardArtifact.Type, Boolean> display() {
119  this.setTitle(NbBundle.getMessage(this.getClass(), "ArtifactSelectionDialog.dlgTitle.text"));
120  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
121  // set the popUp window / JFrame
122  int w = this.getSize().width;
123  int h = this.getSize().height;
124 
125  // set the location of the popUp Window on the center of the screen
126  setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
127 
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) {
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) {
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) {
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
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
List< BlackboardArtifact.Type > getArtifactTypesInUse()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161
Component getListCellRendererComponent(JList<?extends BlackboardArtifact.Type > list, BlackboardArtifact.Type value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2016 Basis Technology. Generated on: Mon Apr 24 2017
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.