Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataSourcePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 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.filesearch;
20 
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29 import java.util.logging.Level;
30 import javax.swing.event.ListSelectionEvent;
34 import org.sleuthkit.datamodel.DataSource;
35 import org.sleuthkit.datamodel.SleuthkitCase;
36 import org.sleuthkit.datamodel.TskCoreException;
37 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 public class DataSourcePanel extends javax.swing.JPanel {
43 
44  private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName());
45  private static final long serialVersionUID = 1L;
46  private final Map<Long, String> dataSourceMap = new HashMap<>();
47 
51  public DataSourcePanel() {
52  initComponents();
53  if (this.dataSourceList.getModel().getSize() > 1) {
54  this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
55  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
56  });
57  } else {
58  /*
59  * Disable data source filtering since there aren't multiple data
60  * sources to choose from.
61  */
62  this.dataSourceCheckBox.setEnabled(false);
63  this.dataSourceList.setEnabled(false);
64  }
65  }
66 
72  private List<String> getDataSourceArray() {
73  List<String> dsList = new ArrayList<>();
74  try {
75  Case currentCase = Case.getCurrentCaseThrows();
76  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
77  List<DataSource> dataSources = tskDb.getDataSources();
78  Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
79  for (DataSource ds : dataSources) {
80  String dsName = ds.getName();
81  File dataSourceFullName = new File(dsName);
82  String displayName = dataSourceFullName.getName();
83  dataSourceMap.put(ds.getId(), displayName);
84  dsList.add(displayName);
85  }
86  } catch (NoCurrentCaseException ex) {
87  logger.log(Level.SEVERE, "Unable to get current open case.", ex);
88  } catch (TskCoreException ex) {
89  logger.log(Level.SEVERE, "Failed to get data source info from database.", ex);
90  }
91  return dsList;
92  }
93 
99  Set<Long> getDataSourcesSelected() {
100  Set<Long> dataSourceObjIdSet = new HashSet<>();
101  for (Long key : dataSourceMap.keySet()) {
102  String value = dataSourceMap.get(key);
103  for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
104  if (value.equals(dataSource)) {
105  dataSourceObjIdSet.add(key);
106  }
107  }
108  }
109  return dataSourceObjIdSet;
110  }
111 
117  boolean isSelected() {
118  return this.dataSourceCheckBox.isSelected();
119  }
120 
125  final void setComponentsEnabled() {
126  boolean enabled = this.isSelected();
127  this.dataSourceList.setEnabled(enabled);
128  this.dataSourceNoteLabel.setEnabled(enabled);
129  }
130 
136  @SuppressWarnings("unchecked")
137  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
138  private void initComponents() {
139 
140  jScrollPane1 = new javax.swing.JScrollPane();
141  dataSourceList = new javax.swing.JList<>();
142  dataSourceCheckBox = new javax.swing.JCheckBox();
143  dataSourceNoteLabel = new javax.swing.JLabel();
144 
145  setMinimumSize(new java.awt.Dimension(150, 150));
146  setPreferredSize(new java.awt.Dimension(150, 150));
147 
148  dataSourceList.setModel(new javax.swing.AbstractListModel<String>() {
149  List<String> strings = getDataSourceArray();
150  public int getSize() { return strings.size(); }
151  public String getElementAt(int idx) { return strings.get(idx); }
152  });
153  dataSourceList.setEnabled(false);
154  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
155  jScrollPane1.setViewportView(dataSourceList);
156 
157  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceCheckBox.text")); // NOI18N
158  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  dataSourceCheckBoxActionPerformed(evt);
161  }
162  });
163 
164  dataSourceNoteLabel.setFont(dataSourceNoteLabel.getFont().deriveFont(dataSourceNoteLabel.getFont().getSize()-1f));
165  org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLabel.text")); // NOI18N
166  dataSourceNoteLabel.setEnabled(false);
167 
168  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
169  this.setLayout(layout);
170  layout.setHorizontalGroup(
171  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
172  .addGroup(layout.createSequentialGroup()
173  .addComponent(dataSourceCheckBox)
174  .addGap(0, 0, Short.MAX_VALUE))
175  .addGroup(layout.createSequentialGroup()
176  .addContainerGap()
177  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
179  .addGroup(layout.createSequentialGroup()
180  .addComponent(dataSourceNoteLabel)
181  .addGap(0, 0, Short.MAX_VALUE)))
182  .addContainerGap())
183  );
184  layout.setVerticalGroup(
185  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
186  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
187  .addComponent(dataSourceCheckBox)
188  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
190  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
191  .addComponent(dataSourceNoteLabel)
192  .addContainerGap())
193  );
194 
195  dataSourceCheckBox.getAccessibleContext().setAccessibleName("");
196  }// </editor-fold>//GEN-END:initComponents
197 
198  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
199  setComponentsEnabled();
200  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
201  this.dataSourceList.setSelectedIndices(new int[0]);
202  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
203 
204  // Variables declaration - do not modify//GEN-BEGIN:variables
205  private javax.swing.JCheckBox dataSourceCheckBox;
206  private javax.swing.JList<String> dataSourceList;
207  private javax.swing.JLabel dataSourceNoteLabel;
208  private javax.swing.JScrollPane jScrollPane1;
209  // End of variables declaration//GEN-END:variables
210 }
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.