19 package org.sleuthkit.autopsy.keywordsearch;
21 import java.awt.EventQueue;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.awt.event.FocusEvent;
25 import java.awt.event.FocusListener;
26 import java.awt.event.MouseEvent;
27 import java.awt.event.MouseMotionListener;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
34 import java.util.logging.Level;
35 import javax.swing.JList;
36 import javax.swing.JMenuItem;
37 import javax.swing.event.ListSelectionEvent;
38 import org.openide.util.NbBundle;
56 @SuppressWarnings(
"PMD.SingularField")
59 private static final long serialVersionUID = 1L;
73 if (null == defaultInstance) {
76 return defaultInstance;
83 @NbBundle.Messages({
"DropdownSingleTermSearchPanel.selected=Ad Hoc Search data source filter is selected"})
86 customizeComponents();
87 dataSourceList.setModel(getDataSourceListModel());
88 this.dataSourceList.addListSelectionListener((ListSelectionEvent evt) -> {
89 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
91 this.dataSourceList.addMouseMotionListener(
new MouseMotionListener() {
94 public void mouseDragged(MouseEvent evt) {
99 public void mouseMoved(MouseEvent evt) {
100 JList<String> DsList = (JList<String>) evt.getSource();
101 int index = DsList.locationToIndex(evt.getPoint());
103 DsList.setToolTipText(getDataSourceToolTipList().
get(index));
114 keywordTextField.addFocusListener(
new FocusListener() {
116 public void focusGained(FocusEvent e) {
120 public void focusLost(FocusEvent e) {
121 if (keywordTextField.getText().isEmpty()) {
127 keywordTextField.setComponentPopupMenu(rightClickMenu);
128 ActionListener actList = (ActionEvent e) -> {
129 JMenuItem jmi = (JMenuItem) e.getSource();
130 if (jmi.equals(cutMenuItem)) {
131 keywordTextField.cut();
132 }
else if (jmi.equals(copyMenuItem)) {
133 keywordTextField.copy();
134 }
else if (jmi.equals(pasteMenuItem)) {
135 keywordTextField.paste();
136 }
else if (jmi.equals(selectAllMenuItem)) {
137 keywordTextField.selectAll();
141 updateIngestIndexLabel();
145 public void propertyChange(PropertyChangeEvent evt) {
146 Object source = evt.getSource();
147 if (source instanceof String && ((String) source).equals(
"LOCAL")) {
148 EventQueue.invokeLater(() -> {
150 updateIngestIndexLabel();
156 cutMenuItem.addActionListener(actList);
157 copyMenuItem.addActionListener(actList);
158 pasteMenuItem.addActionListener(actList);
159 selectAllMenuItem.addActionListener(actList);
167 void addSearchButtonActionListener(ActionListener actionListener) {
168 searchButton.addActionListener(actionListener);
175 void clearSearchBox() {
176 keywordTextField.setText(
"");
179 void setRegexSearchEnabled(
boolean enabled) {
180 exactRadioButton.setSelected(
true);
181 regexRadioButton.setEnabled(enabled);
190 @NbBundle.Messages({
"DropdownSingleTermSearchPanel.warning.title=Warning",
191 "DropdownSingleTermSearchPanel.warning.text=Boundary characters ^ and $ do not match word boundaries. Consider\nreplacing with an explicit list of boundary characters, such as [ \\.,]"})
193 List<KeywordList> getKeywordLists() {
194 if (regexRadioButton.isSelected()) {
195 if((keywordTextField.getText() != null) &&
196 (keywordTextField.getText().startsWith(
"^") ||
197 (keywordTextField.getText().endsWith(
"$") && ! keywordTextField.getText().endsWith(
"\\$")))) {
199 KeywordSearchUtil.displayDialog(NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.title"),
200 NbBundle.getMessage(
this.getClass(),
"DropdownSingleTermSearchPanel.warning.text"),
201 KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);
204 List<Keyword> keywords =
new ArrayList<>();
205 keywords.add(
new Keyword(keywordTextField.getText(), !regexRadioButton.isSelected(), exactRadioButton.isSelected()));
206 List<KeywordList> keywordLists =
new ArrayList<>();
207 keywordLists.add(
new KeywordList(keywords));
216 updateIngestIndexLabel();
224 @SuppressWarnings(
"unchecked")
226 private
void initComponents() {
228 queryTypeButtonGroup =
new javax.swing.ButtonGroup();
229 rightClickMenu =
new javax.swing.JPopupMenu();
230 cutMenuItem =
new javax.swing.JMenuItem();
231 copyMenuItem =
new javax.swing.JMenuItem();
232 pasteMenuItem =
new javax.swing.JMenuItem();
233 selectAllMenuItem =
new javax.swing.JMenuItem();
234 keywordTextField =
new javax.swing.JTextField();
235 searchButton =
new javax.swing.JButton();
236 exactRadioButton =
new javax.swing.JRadioButton();
237 substringRadioButton =
new javax.swing.JRadioButton();
238 regexRadioButton =
new javax.swing.JRadioButton();
239 dataSourceCheckBox =
new javax.swing.JCheckBox();
240 jScrollPane1 =
new javax.swing.JScrollPane();
241 dataSourceList =
new javax.swing.JList<>();
242 ingestIndexLabel =
new javax.swing.JLabel();
244 org.openide.awt.Mnemonics.setLocalizedText(cutMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.cutMenuItem.text"));
245 rightClickMenu.add(cutMenuItem);
247 org.openide.awt.Mnemonics.setLocalizedText(copyMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.copyMenuItem.text"));
248 rightClickMenu.add(copyMenuItem);
250 org.openide.awt.Mnemonics.setLocalizedText(pasteMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.pasteMenuItem.text"));
251 rightClickMenu.add(pasteMenuItem);
253 org.openide.awt.Mnemonics.setLocalizedText(selectAllMenuItem,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.selectAllMenuItem.text"));
254 rightClickMenu.add(selectAllMenuItem);
256 keywordTextField.setFont(
new java.awt.Font(
"Monospaced", 0, 14));
258 keywordTextField.setBorder(
new javax.swing.border.LineBorder(
new java.awt.Color(192, 192, 192), 1,
true));
259 keywordTextField.setMinimumSize(
new java.awt.Dimension(2, 25));
260 keywordTextField.setPreferredSize(
new java.awt.Dimension(2, 25));
261 keywordTextField.addMouseListener(
new java.awt.event.MouseAdapter() {
262 public void mouseClicked(java.awt.event.MouseEvent evt) {
263 keywordTextFieldMouseClicked(evt);
266 keywordTextField.addActionListener(
new java.awt.event.ActionListener() {
267 public void actionPerformed(java.awt.event.ActionEvent evt) {
268 keywordTextFieldActionPerformed(evt);
272 searchButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/keywordsearch/search-icon.png")));
273 org.openide.awt.Mnemonics.setLocalizedText(searchButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.searchButton.text"));
274 searchButton.addActionListener(
new java.awt.event.ActionListener() {
275 public void actionPerformed(java.awt.event.ActionEvent evt) {
276 searchButtonActionPerformed(evt);
280 queryTypeButtonGroup.add(exactRadioButton);
281 org.openide.awt.Mnemonics.setLocalizedText(exactRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.exactRadioButton.text"));
283 queryTypeButtonGroup.add(substringRadioButton);
284 org.openide.awt.Mnemonics.setLocalizedText(substringRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.substringRadioButton.text"));
286 queryTypeButtonGroup.add(regexRadioButton);
287 org.openide.awt.Mnemonics.setLocalizedText(regexRadioButton,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSearchPanel.regexRadioButton.text"));
289 org.openide.awt.Mnemonics.setLocalizedText(dataSourceCheckBox,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.dataSourceCheckBox.text"));
290 dataSourceCheckBox.addActionListener(
new java.awt.event.ActionListener() {
291 public void actionPerformed(java.awt.event.ActionEvent evt) {
292 dataSourceCheckBoxActionPerformed(evt);
296 dataSourceList.setMinimumSize(
new java.awt.Dimension(0, 200));
297 jScrollPane1.setViewportView(dataSourceList);
299 ingestIndexLabel.setFont(ingestIndexLabel.getFont().deriveFont(ingestIndexLabel.getFont().getStyle() & ~java.awt.Font.BOLD, 10));
300 org.openide.awt.Mnemonics.setLocalizedText(ingestIndexLabel,
org.openide.util.NbBundle.getMessage(
DropdownSingleTermSearchPanel.class,
"DropdownSingleTermSearchPanel.ingestIndexLabel.text"));
302 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
303 this.setLayout(layout);
304 layout.setHorizontalGroup(
305 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addGroup(layout.createSequentialGroup()
308 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
309 .addGroup(layout.createSequentialGroup()
310 .addComponent(exactRadioButton)
311 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
312 .addComponent(substringRadioButton)
313 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
314 .addComponent(regexRadioButton))
315 .addComponent(dataSourceCheckBox)
316 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
317 .addGroup(layout.createSequentialGroup()
318 .addComponent(searchButton)
319 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
320 .addComponent(ingestIndexLabel))
321 .addComponent(keywordTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
322 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
324 layout.setVerticalGroup(
325 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
326 .addGroup(layout.createSequentialGroup()
328 .addComponent(keywordTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
329 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
330 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
331 .addComponent(exactRadioButton)
332 .addComponent(substringRadioButton)
333 .addComponent(regexRadioButton))
334 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
335 .addComponent(dataSourceCheckBox)
336 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
338 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
340 .addComponent(searchButton)
341 .addComponent(ingestIndexLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
352 keywordTextFieldActionPerformed(evt);
363 }
catch (Exception e) {
364 LOGGER.log(Level.SEVERE,
"Error performing ad hoc single keyword search", e);
374 if (evt.isPopupTrigger()) {
375 rightClickMenu.show(evt.getComponent(), evt.getX(), evt.getY());
380 updateDataSourceListModel();
386 void updateDataSourceListModel() {
387 getDataSourceListModel().removeAllElements();
388 for (String dsName : getDataSourceArray()) {
389 getDataSourceListModel().addElement(dsName);
391 setComponentsEnabled();
392 firePropertyChange(Bundle.DropdownSingleTermSearchPanel_selected(), null, null);
400 boolean enabled = this.dataSourceCheckBox.isSelected();
401 this.dataSourceList.setEnabled(enabled);
403 this.dataSourceList.setSelectionInterval(0, this.dataSourceList.getModel().getSize()-1);
405 this.dataSourceList.setSelectedIndices(
new int[0]);
414 Set<Long> getDataSourcesSelected() {
415 Set<Long> dataSourceObjIdSet =
new HashSet<>();
416 for (Long key : getDataSourceMap().keySet()) {
417 String value = getDataSourceMap().get(key);
418 for (String dataSource : this.dataSourceList.getSelectedValuesList()) {
419 if (value.equals(dataSource)) {
420 dataSourceObjIdSet.add(key);
424 return dataSourceObjIdSet;
432 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.ongoingIngestMsg", filesIndexed));
434 ingestIndexLabel.setText(NbBundle.getMessage(
this.getClass(),
"KeywordSearchListsViewerPanel.initIngest.fileIndexCtMsg", filesIndexed));
javax.swing.JMenuItem copyMenuItem
static synchronized IngestManager getInstance()
javax.swing.JMenuItem pasteMenuItem
void keywordTextFieldMouseClicked(java.awt.event.MouseEvent evt)
javax.swing.JMenuItem cutMenuItem
javax.swing.JButton searchButton
boolean isIngestRunning()
void postFilesIndexedChange()
void setComponentsEnabled()
javax.swing.JList< String > dataSourceList
static synchronized DropdownSingleTermSearchPanel getDefault()
javax.swing.JRadioButton substringRadioButton
javax.swing.JPopupMenu rightClickMenu
DropdownSingleTermSearchPanel()
void updateIngestIndexLabel()
void addIngestJobEventListener(final PropertyChangeListener listener)
javax.swing.JRadioButton exactRadioButton
javax.swing.JLabel ingestIndexLabel
void customizeComponents()
void dataSourceCheckBoxActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JRadioButton regexRadioButton
javax.swing.JMenuItem selectAllMenuItem
javax.swing.ButtonGroup queryTypeButtonGroup
javax.swing.JCheckBox dataSourceCheckBox
synchronized static Logger getLogger(String name)
javax.swing.JTextField keywordTextField
void keywordTextFieldActionPerformed(java.awt.event.ActionEvent evt)
javax.swing.JScrollPane jScrollPane1
void searchButtonActionPerformed(java.awt.event.ActionEvent evt)