Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
RuleSetDetailsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2020 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.modules.yara.ui;
20 
21 import java.awt.Component;
22 import java.awt.Desktop;
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.List;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import javax.swing.DefaultListCellRenderer;
29 import javax.swing.DefaultListModel;
30 import javax.swing.JList;
31 import javax.swing.JOptionPane;
32 import org.openide.util.NbBundle.Messages;
34 
38 public class RuleSetDetailsPanel extends javax.swing.JPanel {
39 
40  private static final long serialVersionUID = 1L;
41 
42  private static final Logger logger = Logger.getLogger(RuleSetDetailsPanel.class.getName());
43 
45  private final DefaultListModel<File> fileListModel;
46  private final JList<File> fileList;
47 
53 
54  fileListModel = new DefaultListModel<>();
55  fileList = new JList<>();
56  fileList.setModel(fileListModel);
57  fileList.setCellRenderer(new FileRenderer());
58  openFolderButton.setEnabled(false);
59  scrollPane.setViewportView(fileList);
60  refreshButton.setEnabled(false);
61  }
62 
68  void setRuleSet(RuleSet ruleSet) {
69  currentRuleSet = ruleSet;
70 
71  fileListModel.clear();
72 
73  if (ruleSet != null) {
74  List<File> files = currentRuleSet.getRuleFiles();
75 
76  if(files != null) {
77  for (File file : files) {
78  fileListModel.addElement(file);
79  }
80  }
81  }
82 
83  openFolderButton.setEnabled(ruleSet != null);
84  refreshButton.setEnabled(ruleSet != null);
85  }
86 
90  private final class FileRenderer extends DefaultListCellRenderer {
91 
92  private static final long serialVersionUID = 1L;
93 
94  @Override
95  public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
96  super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
97 
98  if (value instanceof File) {
99  File file = (File) value;
100  setText(file.getName());
101  setToolTipText(file.getAbsolutePath());
102  }
103 
104  return this;
105  }
106  }
107 
113  @SuppressWarnings("unchecked")
114  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
115  private void initComponents() {
116  java.awt.GridBagConstraints gridBagConstraints;
117 
118  javax.swing.JLabel ruleSetListLabel = new javax.swing.JLabel();
119  javax.swing.JLabel setDetailsLabel = new javax.swing.JLabel();
120  openFolderButton = new javax.swing.JButton();
121  openLabel = new javax.swing.JLabel();
122  scrollPane = new javax.swing.JScrollPane();
123  refreshButton = new javax.swing.JButton();
124 
125  setLayout(new java.awt.GridBagLayout());
126 
127  org.openide.awt.Mnemonics.setLocalizedText(ruleSetListLabel, org.openide.util.NbBundle.getMessage(RuleSetDetailsPanel.class, "RuleSetDetailsPanel.ruleSetListLabel.text")); // NOI18N
128  gridBagConstraints = new java.awt.GridBagConstraints();
129  gridBagConstraints.gridx = 0;
130  gridBagConstraints.gridy = 3;
131  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132  gridBagConstraints.insets = new java.awt.Insets(16, 0, 3, 0);
133  add(ruleSetListLabel, gridBagConstraints);
134 
135  org.openide.awt.Mnemonics.setLocalizedText(setDetailsLabel, org.openide.util.NbBundle.getMessage(RuleSetDetailsPanel.class, "RuleSetDetailsPanel.setDetailsLabel.text")); // NOI18N
136  gridBagConstraints = new java.awt.GridBagConstraints();
137  gridBagConstraints.gridx = 0;
138  gridBagConstraints.gridy = 0;
139  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140  gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
141  add(setDetailsLabel, gridBagConstraints);
142 
143  openFolderButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/folder-icon-16.png"))); // NOI18N
144  org.openide.awt.Mnemonics.setLocalizedText(openFolderButton, org.openide.util.NbBundle.getMessage(RuleSetDetailsPanel.class, "RuleSetDetailsPanel.openFolderButton.text")); // NOI18N
145  openFolderButton.addActionListener(new java.awt.event.ActionListener() {
146  public void actionPerformed(java.awt.event.ActionEvent evt) {
148  }
149  });
150  gridBagConstraints = new java.awt.GridBagConstraints();
151  gridBagConstraints.gridx = 1;
152  gridBagConstraints.gridy = 5;
153  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
154  gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
155  add(openFolderButton, gridBagConstraints);
156 
157  org.openide.awt.Mnemonics.setLocalizedText(openLabel, org.openide.util.NbBundle.getMessage(RuleSetDetailsPanel.class, "RuleSetDetailsPanel.openLabel.text")); // NOI18N
158  gridBagConstraints = new java.awt.GridBagConstraints();
159  gridBagConstraints.gridx = 0;
160  gridBagConstraints.gridy = 5;
161  gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
162  gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
163  add(openLabel, gridBagConstraints);
164  gridBagConstraints = new java.awt.GridBagConstraints();
165  gridBagConstraints.gridx = 0;
166  gridBagConstraints.gridy = 4;
167  gridBagConstraints.gridwidth = 3;
168  gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
169  gridBagConstraints.weightx = 1.0;
170  gridBagConstraints.weighty = 1.0;
171  gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
172  add(scrollPane, gridBagConstraints);
173 
174  refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/arrow-circle-double-135.png"))); // NOI18N
175  org.openide.awt.Mnemonics.setLocalizedText(refreshButton, org.openide.util.NbBundle.getMessage(RuleSetDetailsPanel.class, "RuleSetDetailsPanel.refreshButton.text")); // NOI18N
176  refreshButton.addActionListener(new java.awt.event.ActionListener() {
177  public void actionPerformed(java.awt.event.ActionEvent evt) {
179  }
180  });
181  gridBagConstraints = new java.awt.GridBagConstraints();
182  gridBagConstraints.gridx = 2;
183  gridBagConstraints.gridy = 5;
184  gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
185  add(refreshButton, gridBagConstraints);
186  }// </editor-fold>//GEN-END:initComponents
187 
188  @Messages({
189  "RuleSetDetailsPanel_failed_to_open_folder_msg=Failed to open new window for rule set file.",
190  "RuleSetDetailsPanel_failed_to_open_folder_title=Open Error"
191  })
192  private void openFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFolderButtonActionPerformed
193  if (currentRuleSet != null) {
194  File file = currentRuleSet.getPath().toFile();
195  if (file.exists()) {
196  try {
197  Desktop.getDesktop().open(file);
198  } catch (IOException ex) {
199  JOptionPane.showMessageDialog(this,
200  Bundle.RuleSetDetailsPanel_failed_to_open_folder_msg(),
201  Bundle.RuleSetDetailsPanel_failed_to_open_folder_title(),
202  JOptionPane.ERROR_MESSAGE);
203  logger.log(Level.WARNING, String.format("Failed to open external file explorer for: %s", currentRuleSet.getPath().toString()), ex);
204  }
205  }
206  }
207  }//GEN-LAST:event_openFolderButtonActionPerformed
208 
209  private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
210  if (currentRuleSet != null) {
211  fileListModel.clear();
212  List<File> files = currentRuleSet.getRuleFiles();
213 
214  if(files != null) {
215  for (File file : files) {
216  fileListModel.addElement(file);
217  }
218  }
219  }
220  }//GEN-LAST:event_refreshButtonActionPerformed
221 
222 
223  // Variables declaration - do not modify//GEN-BEGIN:variables
224  private javax.swing.JButton openFolderButton;
225  private javax.swing.JLabel openLabel;
226  private javax.swing.JButton refreshButton;
227  private javax.swing.JScrollPane scrollPane;
228  // End of variables declaration//GEN-END:variables
229 }
void openFolderButtonActionPerformed(java.awt.event.ActionEvent evt)
void refreshButtonActionPerformed(java.awt.event.ActionEvent evt)
Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2022 Basis Technology. Generated on: Tue Jun 27 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.