19 package org.sleuthkit.autopsy.report.infrastructure;
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;
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;
47 @SuppressWarnings(
"PMD.SingularField")
48 class ArtifactSelectionDialog
extends javax.swing.JDialog {
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<>();
61 ArtifactSelectionDialog(java.awt.Frame parent,
boolean modal) {
71 @SuppressWarnings(
"deprecation")
72 private void populateList() {
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()));
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()));
91 artifactTypes.removeAll(doNotReport);
92 Collections.sort(artifactTypes,
new Comparator<BlackboardArtifact.Type>() {
94 public int compare(BlackboardArtifact.Type o1, BlackboardArtifact.Type o2) {
95 return o1.getDisplayName().compareTo(o2.getDisplayName());
99 artifactTypeSelections =
new HashMap<>();
100 for (BlackboardArtifact.Type type : artifactTypes) {
101 artifactTypeSelections.put(type, Boolean.TRUE);
103 }
catch (TskCoreException ex) {
104 Logger.
getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE,
"Error getting list of artifacts in use: {0}", ex.getLocalizedMessage());
108 Logger.
getLogger(ArtifactSelectionDialog.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex.getLocalizedMessage());
113 private void customInit() {
114 model =
new ArtifactModel();
115 renderer =
new ArtifactRenderer();
116 artifactList.setModel(model);
117 artifactList.setCellRenderer(renderer);
118 artifactList.setVisibleRowCount(-1);
120 artifactList.addMouseListener(
new MouseAdapter() {
122 public void mousePressed(MouseEvent evt) {
123 int index = artifactList.locationToIndex(evt.getPoint());
125 BlackboardArtifact.Type type = model.getElementAt(index);
126 artifactTypeSelections.put(type, !artifactTypeSelections.get(type));
127 artifactList.repaint();
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;
150 @SuppressWarnings(
"unchecked")
152 private void initComponents() {
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();
161 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
163 artifactList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
164 artifactList.setLayoutOrientation(javax.swing.JList.HORIZONTAL_WRAP);
165 artifactScrollPane.setViewportView(artifactList);
167 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class,
"ArtifactSelectionDialog.okButton.text"));
168 okButton.addActionListener(
new java.awt.event.ActionListener() {
169 public void actionPerformed(java.awt.event.ActionEvent evt) {
170 okButtonActionPerformed(evt);
174 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class,
"ArtifactSelectionDialog.titleLabel.text"));
175 titleLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class,
"ArtifactSelectionDialog.titleLabel.toolTipText"));
177 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class,
"ArtifactSelectionDialog.selectAllButton.text"));
178 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
179 public void actionPerformed(java.awt.event.ActionEvent evt) {
180 selectAllButtonActionPerformed(evt);
184 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ArtifactSelectionDialog.class,
"ArtifactSelectionDialog.deselectAllButton.text"));
185 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
186 public void actionPerformed(java.awt.event.ActionEvent evt) {
187 deselectAllButtonActionPerformed(evt);
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()
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)))
212 layout.setVerticalGroup(
213 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214 .addGroup(layout.createSequentialGroup()
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)))
226 .addComponent(okButton)
233 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
237 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
238 for (BlackboardArtifact.Type type : artifactTypes) {
239 artifactTypeSelections.put(type, Boolean.TRUE);
241 artifactList.repaint();
244 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
245 for (BlackboardArtifact.Type type : artifactTypes) {
246 artifactTypeSelections.put(type, Boolean.FALSE);
248 artifactList.repaint();
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;
263 return artifactTypes.size();
268 return artifactTypes.get(index);
280 private class ArtifactRenderer extends JCheckBox implements ListCellRenderer<BlackboardArtifact.Type> {
283 public Component
getListCellRendererComponent(JList<? extends BlackboardArtifact.Type> list, BlackboardArtifact.Type value,
int index,
boolean isSelected,
boolean cellHasFocus) {
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());
void addListDataListener(ListDataListener l)
BlackboardArtifact.Type getElementAt(int index)
SleuthkitCase getSleuthkitCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
void removeListDataListener(ListDataListener l)
Component getListCellRendererComponent(JList<?extends BlackboardArtifact.Type > list, BlackboardArtifact.Type value, int index, boolean isSelected, boolean cellHasFocus)
static boolean isCaseOpen()