19 package org.sleuthkit.autopsy.filesearch;
21 import java.awt.event.MouseEvent;
22 import java.awt.event.MouseMotionListener;
24 import java.util.ArrayList;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
31 import java.util.logging.Level;
32 import javax.swing.JList;
33 import javax.swing.event.ListSelectionEvent;
44 @SuppressWarnings(
"PMD.SingularField")
48 private static final long serialVersionUID = 1L;
49 private final Map<Long, String> dataSourceMap =
new HashMap<>();
50 private final List<String> toolTipList =
new ArrayList<>();
57 this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
58 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
60 this.dataSourceList.addMouseMotionListener(
new MouseMotionListener() {
63 public void mouseDragged(MouseEvent evt) {
68 public void mouseMoved(MouseEvent evt) {
69 if (evt.getSource() instanceof JList<?>) {
70 JList<?> dsList = (JList<?>) evt.getSource();
71 int index = dsList.locationToIndex(evt.getPoint());
73 dsList.setToolTipText(toolTipList.get(index));
86 List<String> dsList =
new ArrayList<>();
90 List<DataSource> dataSources = tskDb.getDataSources();
91 Collections.sort(dataSources, (DataSource ds1, DataSource ds2) -> ds1.getName().compareTo(ds2.getName()));
92 for (DataSource ds : dataSources) {
93 String dsName = ds.getName();
94 File dataSourceFullName =
new File(dsName);
95 String displayName = dataSourceFullName.getName();
96 dataSourceMap.put(ds.getId(), displayName);
97 toolTipList.add(dsName);
98 dsList.add(displayName);
101 logger.log(Level.SEVERE,
"Unable to get current open case.", ex);
102 }
catch (TskCoreException ex) {
103 logger.log(Level.SEVERE,
"Failed to get data source info from database.", ex);
112 Set<Long> getDataSourcesSelected() {
113 Set<Long> dataSourceObjIdSet =
new HashSet<>();
114 for (Long key : dataSourceMap.keySet()) {
115 String value = dataSourceMap.get(key);
116 for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
117 if (value.equals(dataSource)) {
118 dataSourceObjIdSet.add(key);
122 return dataSourceObjIdSet;
129 boolean isSelected() {
130 return this.dataSourceCheckBox.isSelected();
136 final void setComponentsEnabled() {
137 boolean enabled = this.isSelected();
138 this.dataSourceList.setEnabled(enabled);
139 this.dataSourceNoteLabel.setEnabled(enabled);
147 @SuppressWarnings(
"unchecked")
149 private
void initComponents() {
151 jScrollPane1 =
new javax.swing.JScrollPane();
152 dataSourceList =
new javax.swing.JList<>();
153 dataSourceCheckBox =
new javax.swing.JCheckBox();
154 dataSourceNoteLabel =
new javax.swing.JLabel();
156 setMinimumSize(
new java.awt.Dimension(150, 150));
157 setPreferredSize(
new java.awt.Dimension(150, 150));
159 dataSourceList.setModel(
new javax.swing.AbstractListModel<String>() {
160 List<String> strings = getDataSourceArray();
161 public int getSize() { return strings.size(); }
162 public String getElementAt(
int idx) {
return strings.get(idx); }
164 dataSourceList.setEnabled(
false);
165 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
166 jScrollPane1.setViewportView(dataSourceList);
168 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox,
org.openide.util.NbBundle.getMessage(
DataSourcePanel.class,
"DataSourcePanel.dataSourceCheckBox.text"));
169 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
170 public void actionPerformed(java.awt.event.ActionEvent evt) {
171 dataSourceCheckBoxActionPerformed(evt);
175 dataSourceNoteLabel.setFont(
new java.awt.Font(
"Tahoma", 0, 10));
176 org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel,
org.openide.util.NbBundle.getMessage(DataSourcePanel.class,
"DataSourcePanel.dataSourceNoteLabel.text"));
177 dataSourceNoteLabel.setEnabled(
false);
179 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
180 this.setLayout(layout);
181 layout.setHorizontalGroup(
182 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
183 .addGroup(layout.createSequentialGroup()
184 .addComponent(dataSourceCheckBox)
185 .addGap(0, 0, Short.MAX_VALUE))
186 .addGroup(layout.createSequentialGroup()
188 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
190 .addGroup(layout.createSequentialGroup()
191 .addComponent(dataSourceNoteLabel)
192 .addGap(0, 0, Short.MAX_VALUE)))
195 layout.setVerticalGroup(
196 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
198 .addComponent(dataSourceCheckBox)
199 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
200 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
201 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
202 .addComponent(dataSourceNoteLabel)
206 dataSourceCheckBox.getAccessibleContext().setAccessibleName(
"");
210 setComponentsEnabled();
211 firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
212 this.dataSourceList.setSelectedIndices(
new int[0]);
javax.swing.JList< String > dataSourceList
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
List< String > getDataSourceArray()
javax.swing.JCheckBox dataSourceCheckBox
javax.swing.JScrollPane jScrollPane1
SleuthkitCase getSleuthkitCase()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
javax.swing.JLabel dataSourceNoteLabel