Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
MimeTypePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2021 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.util.ArrayList;
22 import java.util.List;
23 import java.util.logging.Level;
24 import javax.swing.DefaultListModel;
25 import javax.swing.event.ListSelectionEvent;
26 import javax.swing.event.ListSelectionListener;
29 
33 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
34 public final class MimeTypePanel extends javax.swing.JPanel {
35 
36  private static final Logger logger = Logger.getLogger(MimeTypePanel.class.getName());
37  private static final long serialVersionUID = 1L;
38 
42  public MimeTypePanel() {
43  initComponents();
44  resetMimeTypePanel();
45  }
46 
47  private String[] getMimeTypeArray() {
48  List<String> mimeTypesList = new ArrayList<>();
49  try {
50  mimeTypesList.addAll(FileTypeDetector.getDetectedTypes());
52  logger.log(Level.SEVERE, "Unable to get detectable file types", ex);
53  }
54  String[] mimeTypeArray = new String[mimeTypesList.size()];
55  return mimeTypesList.toArray(mimeTypeArray);
56  }
57 
58  List<String> getMimeTypesSelected() {
59  return this.mimeTypeList.getSelectedValuesList();
60  }
61 
62  boolean isSelected() {
63  return this.mimeTypeCheckBox.isSelected();
64  }
65 
66  void setComponentsEnabled() {
67  boolean enabled = isSelected();
68  this.mimeTypeList.setEnabled(enabled);
69  this.noteLabel.setEnabled(enabled);
70  }
71 
77  @SuppressWarnings("unchecked")
78  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
79  private void initComponents() {
80 
81  jScrollPane1 = new javax.swing.JScrollPane();
82  mimeTypeList = new javax.swing.JList<>();
83  mimeTypeCheckBox = new javax.swing.JCheckBox();
84  noteLabel = new javax.swing.JLabel();
85 
86  setMinimumSize(new java.awt.Dimension(150, 150));
87  setPreferredSize(new java.awt.Dimension(150, 150));
88 
89  mimeTypeList.setModel(new DefaultListModel<String>());
90  mimeTypeList.setMinimumSize(new java.awt.Dimension(0, 200));
91  jScrollPane1.setViewportView(mimeTypeList);
92 
93  org.openide.awt.Mnemonics.setLocalizedText(mimeTypeCheckBox, org.openide.util.NbBundle.getMessage(MimeTypePanel.class, "MimeTypePanel.mimeTypeCheckBox.text")); // NOI18N
94  mimeTypeCheckBox.addActionListener(new java.awt.event.ActionListener() {
95  public void actionPerformed(java.awt.event.ActionEvent evt) {
96  mimeTypeCheckBoxActionPerformed(evt);
97  }
98  });
99 
100  noteLabel.setFont(noteLabel.getFont().deriveFont(noteLabel.getFont().getSize()-1f));
101  org.openide.awt.Mnemonics.setLocalizedText(noteLabel, org.openide.util.NbBundle.getMessage(MimeTypePanel.class, "MimeTypePanel.noteLabel.text")); // NOI18N
102 
103  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
104  this.setLayout(layout);
105  layout.setHorizontalGroup(
106  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107  .addGroup(layout.createSequentialGroup()
108  .addComponent(mimeTypeCheckBox)
109  .addGap(0, 0, Short.MAX_VALUE))
110  .addGroup(layout.createSequentialGroup()
111  .addContainerGap()
112  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
113  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
114  .addGroup(layout.createSequentialGroup()
115  .addComponent(noteLabel)
116  .addGap(0, 0, Short.MAX_VALUE)))
117  .addContainerGap())
118  );
119  layout.setVerticalGroup(
120  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
121  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
122  .addComponent(mimeTypeCheckBox)
123  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
124  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
125  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
126  .addComponent(noteLabel)
127  .addGap(40, 40, 40))
128  );
129  }// </editor-fold>//GEN-END:initComponents
130 
131  private void mimeTypeCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mimeTypeCheckBoxActionPerformed
132  setComponentsEnabled();
133  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
134  this.mimeTypeList.setSelectedIndices(new int[0]);
135  }//GEN-LAST:event_mimeTypeCheckBoxActionPerformed
136 
137 
138  // Variables declaration - do not modify//GEN-BEGIN:variables
139  private javax.swing.JScrollPane jScrollPane1;
140  private javax.swing.JCheckBox mimeTypeCheckBox;
141  private javax.swing.JList<String> mimeTypeList;
142  private javax.swing.JLabel noteLabel;
143  // End of variables declaration//GEN-END:variables
144 
148  void resetMimeTypePanel() {
149  //remove all list selection listeners
150  for (ListSelectionListener listener : mimeTypeList.getListSelectionListeners()) {
151  mimeTypeList.removeListSelectionListener(listener);
152  }
153  mimeTypeList.clearSelection();
154  ((DefaultListModel<String>) mimeTypeList.getModel()).clear();
155  for (String dataSource : getMimeTypeArray()) {
156  ((DefaultListModel<String>) mimeTypeList.getModel()).addElement(dataSource);
157  }
158  mimeTypeList.addListSelectionListener((ListSelectionEvent e) -> {
159  firePropertyChange(FileSearchPanel.EVENT.CHECKED.toString(), null, null);
160  });
161  mimeTypeList.setEnabled(false);
162  mimeTypeCheckBox.setSelected(false);
163  noteLabel.setEnabled(false);
164  }
165 }
void mimeTypeCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static synchronized SortedSet< String > getDetectedTypes()

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