19 package org.sleuthkit.autopsy.report.taggedhashes;
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.LinkedHashMap;
26 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.JCheckBox;
30 import javax.swing.JLabel;
31 import javax.swing.JList;
32 import javax.swing.JOptionPane;
33 import javax.swing.ListCellRenderer;
34 import javax.swing.ListModel;
35 import javax.swing.event.ListDataListener;
49 @SuppressWarnings(
"PMD.SingularField")
50 class AddTaggedHashesToHashDbConfigPanel extends javax.swing.JPanel {
52 private static final long serialVersionUID = 1L;
53 private List<TagName> tagNames;
54 private final Map<String, Boolean> tagNameSelections =
new LinkedHashMap<>();
55 private final TagNamesListModel tagsNamesListModel =
new TagNamesListModel();
56 private final TagsNamesListCellRenderer tagsNamesRenderer =
new TagsNamesListCellRenderer();
57 private HashDb selectedHashSet = null;
59 AddTaggedHashesToHashDbConfigPanel() {
61 customizeComponents();
64 private void customizeComponents() {
65 populateTagNameComponents();
66 populateHashSetComponents();
69 private void populateTagNameComponents() {
72 tagNames = Case.getCurrentCaseThrows().getServices().getTagsManager().getTagNamesInUse();
73 }
catch (TskCoreException ex) {
74 Logger.getLogger(AddTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
75 JOptionPane.showMessageDialog(
this,
"Error getting tag names for case.",
"Tag Names Not Found", JOptionPane.ERROR_MESSAGE);
76 }
catch (NoCurrentCaseException ex) {
77 Logger.getLogger(AddTaggedHashesToHashDbConfigPanel.class.getName()).log(Level.SEVERE,
"Exception while getting open case.", ex);
78 JOptionPane.showMessageDialog(
this,
"Error getting tag names for case.",
"Exception while getting open case.", JOptionPane.ERROR_MESSAGE);
84 for (TagName tagName : tagNames) {
85 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
91 tagNamesListBox.setModel(tagsNamesListModel);
92 tagNamesListBox.setCellRenderer(tagsNamesRenderer);
93 tagNamesListBox.setVisibleRowCount(-1);
94 tagNamesListBox.addMouseListener(
new MouseAdapter() {
96 public void mousePressed(MouseEvent evt) {
97 JList<?> list = (JList) evt.getSource();
98 int index = list.locationToIndex(evt.getPoint());
100 String value = tagsNamesListModel.getElementAt(index);
101 tagNameSelections.put(value, !tagNameSelections.get(value));
108 private void populateHashSetComponents() {
111 hashSetsComboBox.removeAllItems();
115 List<HashDb> updateableHashSets = HashDbManager.getInstance().getUpdateableHashSets();
116 if (!updateableHashSets.isEmpty()) {
117 for (HashDb hashDb : updateableHashSets) {
118 hashSetsComboBox.addItem(hashDb);
120 hashSetsComboBox.setEnabled(
true);
122 hashSetsComboBox.setEnabled(
false);
131 List<TagName> getSelectedTagNames() {
132 List<TagName> selectedTagNames =
new ArrayList<>();
133 for (TagName tagName : tagNames) {
134 if (tagNameSelections.get(tagName.getDisplayName())) {
135 selectedTagNames.add(tagName);
138 return selectedTagNames;
146 HashDb getSelectedHashDatabase() {
147 return selectedHashSet;
155 return tagNames.size();
160 return tagNames.get(index).getDisplayName();
174 private static final long serialVersionUID = 1L;
179 setEnabled(list.isEnabled());
180 setSelected(tagNameSelections.get(value));
181 setFont(list.getFont());
182 setBackground(list.getBackground());
183 setForeground(list.getForeground());
196 @SuppressWarnings(
"unchecked")
198 private
void initComponents() {
200 jScrollPane1 =
new javax.swing.JScrollPane();
201 tagNamesListBox =
new javax.swing.JList<>();
202 selectAllButton =
new javax.swing.JButton();
203 deselectAllButton =
new javax.swing.JButton();
204 jLabel1 =
new javax.swing.JLabel();
205 hashSetsComboBox =
new javax.swing.JComboBox<>();
206 configureHashDatabasesButton =
new javax.swing.JButton();
207 jLabel2 =
new javax.swing.JLabel();
209 jScrollPane1.setViewportView(tagNamesListBox);
211 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.selectAllButton.text"));
212 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
213 public void actionPerformed(java.awt.event.ActionEvent evt) {
214 selectAllButtonActionPerformed(evt);
218 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.deselectAllButton.text"));
219 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
220 public void actionPerformed(java.awt.event.ActionEvent evt) {
221 deselectAllButtonActionPerformed(evt);
225 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.jLabel1.text"));
227 hashSetsComboBox.addActionListener(
new java.awt.event.ActionListener() {
228 public void actionPerformed(java.awt.event.ActionEvent evt) {
229 hashSetsComboBoxActionPerformed(evt);
233 org.openide.awt.Mnemonics.setLocalizedText(configureHashDatabasesButton,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.configureHashDatabasesButton.text"));
234 configureHashDatabasesButton.addActionListener(
new java.awt.event.ActionListener() {
235 public void actionPerformed(java.awt.event.ActionEvent evt) {
236 configureHashDatabasesButtonActionPerformed(evt);
240 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(AddTaggedHashesToHashDbConfigPanel.class,
"AddTaggedHashesToHashDbConfigPanel.jLabel2.text"));
242 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
243 this.setLayout(layout);
244 layout.setHorizontalGroup(
245 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGroup(layout.createSequentialGroup()
248 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 .addComponent(jLabel2)
250 .addComponent(jLabel1)
251 .addGroup(layout.createSequentialGroup()
252 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addComponent(jScrollPane1)
254 .addGroup(layout.createSequentialGroup()
255 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
256 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
257 .addComponent(configureHashDatabasesButton)))
258 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
260 .addComponent(deselectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
261 .addComponent(selectAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
265 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {deselectAllButton, selectAllButton});
267 layout.setVerticalGroup(
268 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269 .addGroup(layout.createSequentialGroup()
271 .addComponent(jLabel1)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
273 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274 .addGroup(layout.createSequentialGroup()
275 .addComponent(selectAllButton)
276 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
277 .addComponent(deselectAllButton))
278 .addComponent(jScrollPane1))
279 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
280 .addComponent(jLabel2)
282 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
283 .addComponent(hashSetsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
284 .addComponent(configureHashDatabasesButton))
289 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
290 for (TagName tagName : tagNames) {
291 tagNameSelections.put(tagName.getDisplayName(), Boolean.TRUE);
293 tagNamesListBox.repaint();
296 private void hashSetsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
297 selectedHashSet = (HashDb)hashSetsComboBox.getSelectedItem();
300 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
301 for (TagName tagName : tagNames) {
302 tagNameSelections.put(tagName.getDisplayName(), Boolean.FALSE);
304 tagNamesListBox.repaint();
307 private void configureHashDatabasesButtonActionPerformed(java.awt.event.ActionEvent evt) {
308 HashLookupSettingsPanel configPanel =
new HashLookupSettingsPanel();
310 if (JOptionPane.showConfirmDialog(
this, configPanel,
"Hash Set Configuration", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
312 populateHashSetComponents();
314 configPanel.cancel();
315 populateHashSetComponents();
320 private javax.swing.JButton configureHashDatabasesButton;
321 private javax.swing.JButton deselectAllButton;
322 private javax.swing.JComboBox<HashDb> hashSetsComboBox;
323 private javax.swing.JLabel jLabel1;
324 private javax.swing.JLabel jLabel2;
325 private javax.swing.JScrollPane jScrollPane1;
326 private javax.swing.JButton selectAllButton;
327 private javax.swing.JList<String> tagNamesListBox;
String getElementAt(int index)
Component getListCellRendererComponent(JList<?extends String > list, String value, int index, boolean isSelected, boolean cellHasFocus)
void removeListDataListener(ListDataListener l)
void addListDataListener(ListDataListener l)