Autopsy  4.7.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.awt.event.MouseEvent;
22 import java.awt.event.MouseMotionListener;
23 import java.io.File;
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;
29 import java.util.Map;
30 import java.util.Set;
31 import java.util.logging.Level;
32 import javax.swing.JList;
33 import javax.swing.event.ListSelectionEvent;
37 import org.sleuthkit.datamodel.DataSource;
38 import org.sleuthkit.datamodel.SleuthkitCase;
39 import org.sleuthkit.datamodel.TskCoreException;
40 
44 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
45 public class DataSourcePanel extends javax.swing.JPanel {
46 
47  private static final Logger logger = Logger.getLogger(DataSourcePanel.class.getName());
48  private static final long serialVersionUID = 1L;
49  private final Map<Long, String> dataSourceMap = new HashMap<>();
50  private final List<String> toolTipList = new ArrayList<>();
51 
55  public DataSourcePanel() {
56  initComponents();
57  this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
58  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
59  });
60  this.dataSourceList.addMouseMotionListener(new MouseMotionListener() {
61 
62  @Override
63  public void mouseDragged(MouseEvent evt) {
64  //Unused by now
65  }
66 
67  @Override
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());
72  if (index > -1) {
73  dsList.setToolTipText(toolTipList.get(index));
74  }
75  }
76  }
77  });
78  }
79 
85  private List<String> getDataSourceArray() {
86  List<String> dsList = new ArrayList<>();
87  try {
88  Case currentCase = Case.getCurrentCaseThrows();
89  SleuthkitCase tskDb = currentCase.getSleuthkitCase();
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);
99  }
100  } catch (NoCurrentCaseException ex) {
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);
104  }
105  return dsList;
106  }
107 
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);
119  }
120  }
121  }
122  return dataSourceObjIdSet;
123  }
124 
129  boolean isSelected() {
130  return this.dataSourceCheckBox.isSelected();
131  }
132 
136  final void setComponentsEnabled() {
137  boolean enabled = this.isSelected();
138  this.dataSourceList.setEnabled(enabled);
139  this.dataSourceNoteLabel.setEnabled(enabled);
140  }
141 
147  @SuppressWarnings("unchecked")
148  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
149  private void initComponents() {
150 
151  jScrollPane1 = new javax.swing.JScrollPane();
152  dataSourceList = new javax.swing.JList<>();
153  dataSourceCheckBox = new javax.swing.JCheckBox();
154  dataSourceNoteLabel = new javax.swing.JLabel();
155 
156  setMinimumSize(new java.awt.Dimension(150, 150));
157  setPreferredSize(new java.awt.Dimension(150, 150));
158 
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); }
163  });
164  dataSourceList.setEnabled(false);
165  dataSourceList.setMinimumSize(new java.awt.Dimension(0, 200));
166  jScrollPane1.setViewportView(dataSourceList);
167 
168  org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceCheckBox.text")); // NOI18N
169  dataSourceCheckBox.addActionListener(new java.awt.event.ActionListener() {
170  public void actionPerformed(java.awt.event.ActionEvent evt) {
171  dataSourceCheckBoxActionPerformed(evt);
172  }
173  });
174 
175  dataSourceNoteLabel.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
176  org.openide.awt.Mnemonics.setLocalizedText(dataSourceNoteLabel, org.openide.util.NbBundle.getMessage(DataSourcePanel.class, "DataSourcePanel.dataSourceNoteLabel.text")); // NOI18N
177  dataSourceNoteLabel.setEnabled(false);
178 
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()
187  .addContainerGap()
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)))
193  .addContainerGap())
194  );
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)
203  .addContainerGap())
204  );
205 
206  dataSourceCheckBox.getAccessibleContext().setAccessibleName("");
207  }// </editor-fold>//GEN-END:initComponents
208 
209  private void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataSourceCheckBoxActionPerformed
210  setComponentsEnabled();
211  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
212  this.dataSourceList.setSelectedIndices(new int[0]);
213  }//GEN-LAST:event_dataSourceCheckBoxActionPerformed
214 
215  // Variables declaration - do not modify//GEN-BEGIN:variables
216  private javax.swing.JCheckBox dataSourceCheckBox;
217  private javax.swing.JList<String> dataSourceList;
218  private javax.swing.JLabel dataSourceNoteLabel;
219  private javax.swing.JScrollPane jScrollPane1;
220  // End of variables declaration//GEN-END:variables
221 }
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.