19 package org.sleuthkit.autopsy.report.modules.taggedhashes;
21 import java.awt.Component;
22 import java.awt.event.ItemEvent;
23 import java.awt.event.ItemListener;
24 import java.awt.event.MouseAdapter;
25 import java.awt.event.MouseEvent;
26 import java.util.ArrayList;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 import java.util.Objects;
31 import java.util.logging.Level;
32 import javax.swing.DefaultListModel;
33 import javax.swing.JCheckBox;
34 import javax.swing.JLabel;
35 import javax.swing.JList;
36 import javax.swing.JOptionPane;
37 import javax.swing.ListCellRenderer;
52 @SuppressWarnings(
"PMD.SingularField")
53 class SaveTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel {
55 private static final long serialVersionUID = 1L;
56 private List<TagName> tagNames;
57 private Map<TagName, Boolean> tagNameSelections =
new LinkedHashMap<>();
58 private DefaultListModel<TagName> tagsNamesListModel =
new DefaultListModel<>();
59 private TagsNamesListCellRenderer tagsNamesRenderer =
new TagsNamesListCellRenderer();
60 private String selectedHashSetName;
61 private List<HashDb> updateableHashSets =
new ArrayList<>();
63 SaveTaggedHashesToHashDbConfigPanel() {
65 customizeComponents();
70 tagNamesListBox.addMouseListener(
new MouseAdapter() {
72 public void mousePressed(MouseEvent evt) {
73 if (jAllTagsCheckBox.isSelected()) {
76 JList<?> list = (JList) evt.getSource();
77 int index = list.locationToIndex(evt.getPoint());
79 TagName tagName = tagsNamesListModel.getElementAt(index);
80 tagNameSelections.put(tagName, !tagNameSelections.get(tagName));
86 this.jAllTagsCheckBox.addItemListener(
new ItemListener() {
88 public void itemStateChanged(ItemEvent e) {
89 tagNamesListBox.setEnabled(!jAllTagsCheckBox.isSelected());
90 selectAllButton.setEnabled(!jAllTagsCheckBox.isSelected());
91 deselectAllButton.setEnabled(!jAllTagsCheckBox.isSelected());
92 selectAllTags(jAllTagsCheckBox.isSelected());
97 HashesReportModuleSettings getConfiguration() {
98 return new HashesReportModuleSettings(jAllTagsCheckBox.isSelected(), selectedHashSetName);
101 void setConfiguration(HashesReportModuleSettings settings) {
104 customizeComponents();
107 jAllTagsCheckBox.setSelected(settings.isExportAllTags());
108 if (settings.isExportAllTags()) {
113 if (settings.getHashDbName() != null) {
114 populateHashSetComponents();
115 hashSetsComboBox.setSelectedItem(settings.getHashDbName());
119 private void customizeComponents() {
120 tagsNamesListModel =
new DefaultListModel<>();
121 tagsNamesRenderer =
new TagsNamesListCellRenderer();
122 populateTagNameComponents();
124 tagNamesListBox.setModel(tagsNamesListModel);
125 tagNamesListBox.setCellRenderer(tagsNamesRenderer);
126 tagNamesListBox.setVisibleRowCount(-1);
128 populateHashSetComponents();
131 private void populateTagNameComponents() {
133 tagNames =
new ArrayList<>();
134 Map<TagName, Boolean> updatedTagNameSelections =
new LinkedHashMap<>();
137 tagNames = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
138 for (TagName tagName : tagNames) {
139 tagsNamesListModel.addElement(tagName);
141 }
catch (TskCoreException ex) {
142 Logger.getLogger(SaveTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
143 }
catch (NoCurrentCaseException ex) {
145 if (Case.isCaseOpen()) {
146 Logger.getLogger(SaveTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
153 for (TagName tagName : tagNames) {
154 if (tagNameSelections.get(tagName) != null && Objects.equals(tagNameSelections.get(tagName), Boolean.TRUE)) {
155 updatedTagNameSelections.put(tagName, Boolean.TRUE);
157 updatedTagNameSelections.put(tagName, Boolean.FALSE);
160 tagNameSelections = updatedTagNameSelections;
163 private void populateHashSetComponents() {
166 hashSetsComboBox.removeAllItems();
167 selectedHashSetName =
"";
171 updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets();
172 if (!updateableHashSets.isEmpty()) {
173 for (HashDb hashDb : updateableHashSets) {
174 hashSetsComboBox.addItem(hashDb.getHashSetName());
176 hashSetsComboBox.setEnabled(
true);
178 hashSetsComboBox.setEnabled(
false);
187 List<TagName> getSelectedTagNames() {
188 List<TagName> selectedTagNames =
new ArrayList<>();
189 for (TagName tagName : tagNames) {
190 if (tagNameSelections.get(tagName)) {
191 selectedTagNames.add(tagName);
194 return selectedTagNames;
202 HashDb getSelectedHashDatabase() {
203 for (HashDb hashDb : updateableHashSets) {
204 if (hashDb.getHashSetName().equals(selectedHashSetName)) {
214 private static final long serialVersionUID = 1L;
219 setEnabled(list.isEnabled());
220 setSelected(tagNameSelections.get(value));
221 setFont(list.getFont());
222 setBackground(list.getBackground());
223 setForeground(list.getForeground());
236 @SuppressWarnings(
"unchecked")
238 private
void initComponents() {
240 jScrollPane1 =
new javax.swing.JScrollPane();
241 tagNamesListBox =
new javax.swing.JList<>();
242 selectAllButton =
new javax.swing.JButton();
243 deselectAllButton =
new javax.swing.JButton();
244 jLabel1 =
new javax.swing.JLabel();
245 hashSetsComboBox =
new javax.swing.JComboBox<>();
246 configureHashDatabasesButton =
new javax.swing.JButton();
247 jLabel2 =
new javax.swing.JLabel();
248 jAllTagsCheckBox =
new javax.swing.JCheckBox();
250 jScrollPane1.setViewportView(tagNamesListBox);
252 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.selectAllButton.text"));
253 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
254 public void actionPerformed(java.awt.event.ActionEvent evt) {
255 selectAllButtonActionPerformed(evt);
259 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.deselectAllButton.text"));
260 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
261 public void actionPerformed(java.awt.event.ActionEvent evt) {
262 deselectAllButtonActionPerformed(evt);
266 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jLabel1.text"));
268 hashSetsComboBox.addActionListener(
new java.awt.event.ActionListener() {
269 public void actionPerformed(java.awt.event.ActionEvent evt) {
270 hashSetsComboBoxActionPerformed(evt);
274 org.openide.awt.Mnemonics.setLocalizedText(configureHashDatabasesButton,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.configureHashDatabasesButton.text"));
275 configureHashDatabasesButton.addActionListener(
new java.awt.event.ActionListener() {
276 public void actionPerformed(java.awt.event.ActionEvent evt) {
277 configureHashDatabasesButtonActionPerformed(evt);
281 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jLabel2.text"));
283 org.openide.awt.Mnemonics.setLocalizedText(jAllTagsCheckBox,
org.openide.util.NbBundle.getMessage(SaveTaggedHashesToHashDbConfigPanel.class,
"SaveTaggedHashesToHashDbConfigPanel.jAllTagsCheckBox.text"));
284 jAllTagsCheckBox.addActionListener(
new java.awt.event.ActionListener() {
285 public void actionPerformed(java.awt.event.ActionEvent evt) {
286 jAllTagsCheckBoxActionPerformed(evt);
290 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
291 this.setLayout(layout);
292 layout.setHorizontalGroup(
293 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
294 .addGroup(layout.createSequentialGroup()
296 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297 .addGroup(layout.createSequentialGroup()
298 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
299 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
300 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
301 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
302 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
303 .addGroup(layout.createSequentialGroup()
304 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305 .addComponent(jAllTagsCheckBox)
306 .addComponent(jLabel1)
307 .addGroup(layout.createSequentialGroup()
308 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
309 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
310 .addComponent(configureHashDatabasesButton))
311 .addComponent(jLabel2))
312 .addGap(0, 0, Short.MAX_VALUE)))
316 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deselectAllButton, selectAllButton});
318 layout.setVerticalGroup(
319 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
320 .addGroup(layout.createSequentialGroup()
321 .addComponent(jLabel1)
322 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
323 .addComponent(jAllTagsCheckBox)
324 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
325 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addGroup(layout.createSequentialGroup()
327 .addComponent(selectAllButton)
328 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
329 .addComponent(deselectAllButton))
330 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
331 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
332 .addComponent(jLabel2)
334 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
335 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
336 .addComponent(configureHashDatabasesButton))
341 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
345 private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
346 selectedHashSetName = (String) hashSetsComboBox.getSelectedItem();
349 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
350 selectAllTags(
false);
353 private void configureHashDatabasesButtonActionPerformed(java.awt.event.ActionEvent evt) {
354 HashLookupSettingsPanel configPanel =
new HashLookupSettingsPanel();
356 if (JOptionPane.showConfirmDialog(
this, configPanel,
"Hash Set Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
358 populateHashSetComponents();
360 configPanel.cancel();
361 populateHashSetComponents();
365 private void selectAllTags(
boolean select) {
366 Boolean state = Boolean.TRUE;
368 state = Boolean.FALSE;
370 for (TagName tagName : tagNames) {
371 tagNameSelections.put(tagName, state);
373 tagNamesListBox.repaint();
375 private void jAllTagsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
380 private javax.swing.JButton configureHashDatabasesButton;
381 private javax.swing.JButton deselectAllButton;
382 private javax.swing.JComboBox<String> hashSetsComboBox;
383 private javax.swing.JCheckBox jAllTagsCheckBox;
384 private javax.swing.JLabel jLabel1;
385 private javax.swing.JLabel jLabel2;
386 private javax.swing.JScrollPane jScrollPane1;
387 private javax.swing.JButton selectAllButton;
388 private javax.swing.JList<TagName> tagNamesListBox;
Component getListCellRendererComponent(JList<?extends TagName > list, TagName value, int index, boolean isSelected, boolean cellHasFocus)