19 package org.sleuthkit.autopsy.modules.hashdatabase;
21 import java.awt.Component;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.JLabel;
28 import javax.swing.JScrollPane;
29 import javax.swing.JTable;
30 import javax.swing.table.AbstractTableModel;
31 import javax.swing.table.DefaultTableCellRenderer;
32 import javax.swing.table.TableColumn;
33 import org.apache.commons.lang.StringUtils;
43 @SuppressWarnings(
"PMD.SingularField")
46 private static final long serialVersionUID = 1L;
48 private final List<HashSetModel> hashSetModels =
new ArrayList<>();
52 initializeHashSetModels(settings);
54 customizeComponents(settings);
58 List<HashDb> hashDbs = validSetsOnly(hashDbManager.
getAllHashSets());
59 hashSetModels.clear();
60 for (
HashDb db : hashDbs) {
61 hashSetModels.add(
new HashSetModel(db, settings.isHashSetEnabled(db), isHashDbValid(db)));
66 customizeHashSetsTable(hashDbsScrollPane, hashTable, hashSetsTableModel);
67 alwaysCalcHashesCheckbox.setSelected(settings.shouldCalculateHashes());
69 alwaysCalcHashesCheckbox.setText(
"<html>" +
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text") +
"</html>");
73 table.setModel(tableModel);
74 table.setTableHeader(null);
75 table.setRowSelectionAllowed(
false);
76 final int width1 = scrollPane.getPreferredSize().width;
77 hashTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
79 for (
int i = 0; i < table.getColumnCount(); i++) {
80 column = table.getColumnModel().getColumn(i);
82 column.setPreferredWidth(((
int) (width1 * 0.07)));
85 column.setPreferredWidth(((
int) (width1 * 0.92)));
101 List<HashDb> enabledHashSets =
new ArrayList<>();
102 List<HashDb> disabledHashSets =
new ArrayList<>();
103 addHashSets(hashSetModels, enabledHashSets, disabledHashSets);
104 return new HashLookupModuleSettings(alwaysCalcHashesCheckbox.isSelected(),
105 enabledHashSets, disabledHashSets);
108 private void addHashSets(List<HashSetModel> hashSetModels, List<HashDb> enabledHashSets, List<HashDb> disabledHashSets) {
110 if (model.isEnabled() && model.isValid()) {
111 enabledHashSets.add(model.getDatabase());
113 disabledHashSets.add(model.getDatabase());
119 updateHashSetModels();
120 hashSetsTableModel.fireTableDataChanged();
124 List<HashDb> validDbs =
new ArrayList<>();
125 for (
HashDb db : hashDbs) {
130 }
catch (TskCoreException ex) {
137 void updateHashSetModels() {
138 List<HashDb> hashDbs = validSetsOnly(hashDbManager.
getAllHashSets());
140 List<HashDb> hashDatabases =
new ArrayList<>(hashDbs);
143 List<HashSetModel> deletedHashSetModels =
new ArrayList<>();
144 for (HashSetModel model : hashSetModels) {
145 boolean foundDatabase =
false;
146 for (
HashDb db : hashDatabases) {
147 if (model.getDatabase().equals(db)) {
148 model.setValid(isHashDbValid(db));
149 hashDatabases.remove(db);
150 foundDatabase =
true;
154 if (!foundDatabase) {
155 deletedHashSetModels.add(model);
160 for (HashSetModel model : deletedHashSetModels) {
161 hashSetModels.remove(model);
165 for (HashDb db : hashDatabases) {
166 hashSetModels.add(
new HashSetModel(db,
true, isHashDbValid(db)));
170 void reset(HashLookupModuleSettings newSettings) {
171 initializeHashSetModels(newSettings);
172 alwaysCalcHashesCheckbox.setSelected(newSettings.shouldCalculateHashes());
173 hashSetsTableModel.fireTableDataChanged();
177 boolean isValid =
false;
179 isValid = hashDb.isValid();
180 }
catch (TskCoreException ex) {
194 this.enabled = enabled;
203 return db.getDisplayName();
206 String getFormattedName() {
208 if (!StringUtils.isBlank(knownTypeName)) {
209 knownTypeName = String.format(
" (%s)", knownTypeName);
212 String displayName = db != null ? db.getDisplayName() :
"";
213 return displayName + knownTypeName;
216 void setEnabled(
boolean enabled) {
217 this.enabled = enabled;
220 boolean isEnabled() {
224 void setValid(
boolean valid) {
238 private static final long serialVersionUID = 1L;
241 JTable table, Object value,
242 boolean isSelected,
boolean hasFocus,
243 int row,
int column) {
244 JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
245 label.setToolTipText(label.getText());
253 private static final long serialVersionUID = 1L;
257 this.hashSets = hashSets;
262 return hashSets.size();
272 if (columnIndex == 0) {
273 return hashSets.get(rowIndex).isEnabled();
275 return hashSets.get(rowIndex).getFormattedName();
281 return (columnIndex == 0 && hashSets.get(rowIndex).isValid());
285 public void setValueAt(Object aValue,
int rowIndex,
int columnIndex) {
286 if (columnIndex == 0) {
287 hashSets.get(rowIndex).setEnabled((Boolean) aValue);
293 return getValueAt(0, c).getClass();
302 @SuppressWarnings(
"unchecked")
304 private
void initComponents() {
306 hashDbsLabel =
new javax.swing.JLabel();
307 hashDbsScrollPane =
new javax.swing.JScrollPane();
308 hashTable =
new javax.swing.JTable();
309 alwaysCalcHashesCheckbox =
new javax.swing.JCheckBox();
311 setPreferredSize(
new java.awt.Dimension(292, 150));
315 hashDbsScrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());
317 hashTable.setBackground(
new java.awt.Color(240, 240, 240));
318 hashTable.setShowHorizontalLines(
false);
319 hashTable.setShowVerticalLines(
false);
320 hashDbsScrollPane.setViewportView(hashTable);
322 alwaysCalcHashesCheckbox.setText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.text"));
323 alwaysCalcHashesCheckbox.setToolTipText(
org.openide.util.NbBundle.getMessage(
HashLookupModuleSettingsPanel.class,
"HashLookupModuleSettingsPanel.alwaysCalcHashesCheckbox.toolTipText"));
324 alwaysCalcHashesCheckbox.setMaximumSize(
new java.awt.Dimension(290, 35));
325 alwaysCalcHashesCheckbox.setMinimumSize(
new java.awt.Dimension(290, 35));
326 alwaysCalcHashesCheckbox.setPreferredSize(
new java.awt.Dimension(271, 35));
327 alwaysCalcHashesCheckbox.setVerticalAlignment(javax.swing.SwingConstants.TOP);
328 alwaysCalcHashesCheckbox.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
330 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
331 this.setLayout(layout);
332 layout.setHorizontalGroup(
333 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
334 .addGroup(layout.createSequentialGroup()
336 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
337 .addGroup(layout.createSequentialGroup()
338 .addComponent(hashDbsLabel)
339 .addGap(0, 0, Short.MAX_VALUE))
340 .addGroup(layout.createSequentialGroup()
342 .addComponent(hashDbsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))
343 .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
346 layout.setVerticalGroup(
347 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
348 .addGroup(layout.createSequentialGroup()
350 .addComponent(hashDbsLabel)
351 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
352 .addComponent(hashDbsScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
353 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
354 .addComponent(alwaysCalcHashesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
void setValueAt(Object aValue, int rowIndex, int columnIndex)
javax.swing.JScrollPane hashDbsScrollPane
List< HashDb > validSetsOnly(List< HashDb > hashDbs)
IngestModuleIngestJobSettings getSettings()
javax.swing.JLabel hashDbsLabel
void propertyChange(PropertyChangeEvent event)
synchronized void addPropertyChangeListener(PropertyChangeListener listener)
void addHashSets(List< HashSetModel > hashSetModels, List< HashDb > enabledHashSets, List< HashDb > disabledHashSets)
abstract String getHashSetName()
void customizeHashSetsTable(JScrollPane scrollPane, JTable table, HashSetsTableModel tableModel)
boolean isCellEditable(int rowIndex, int columnIndex)
void initializeHashSetModels(HashLookupModuleSettings settings)
static synchronized HashDbManager getInstance()
abstract HashDb.KnownFilesType getKnownFilesType()
boolean isHashDbValid(HashDb hashDb)
synchronized List< HashDb > getAllHashSets()
javax.swing.JTable hashTable
void customizeComponents(HashLookupModuleSettings settings)
Object getValueAt(int rowIndex, int columnIndex)
javax.swing.JCheckBox alwaysCalcHashesCheckbox
synchronized static Logger getLogger(String name)
final List< HashSetModel > hashSets
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
Class<?> getColumnClass(int c)