19 package org.sleuthkit.autopsy.logicalimager.configuration;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.KeyAdapter;
23 import java.awt.event.KeyEvent;
24 import java.io.IOException;
25 import java.util.List;
26 import javax.swing.JButton;
27 import javax.swing.JComponent;
28 import javax.swing.JOptionPane;
29 import javax.swing.JScrollPane;
30 import javax.swing.JTextArea;
31 import javax.swing.SwingUtilities;
32 import javax.swing.event.DocumentEvent;
33 import javax.swing.event.DocumentListener;
34 import org.apache.commons.lang.StringUtils;
35 import org.apache.commons.lang3.tuple.ImmutablePair;
36 import org.openide.util.NbBundle;
41 @SuppressWarnings(
"PMD.SingularField")
42 final class EditFullPathsRulePanel extends javax.swing.JPanel {
44 private JButton okButton;
45 private JButton cancelButton;
46 private final JTextArea fullPathsTextArea;
52 "EditFullPathsRulePanel.example=Example: "
54 EditFullPathsRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule,
boolean editing) {
57 this.setRule(ruleName, rule);
58 this.setButtons(okButton, cancelButton);
60 fullPathsTextArea =
new JTextArea();
61 initTextArea(fullPathsScrollPane, fullPathsTextArea);
62 setTextArea(fullPathsTextArea, rule.getFullPaths());
64 EditRulePanel.setTextFieldPrompts(fullPathsTextArea,
65 "<html>" + Bundle.EditFullPathsRulePanel_example() +
"<br>/Program Files/Common Files/system/wab32.dll<br>/Windows/System32/1033/VsGraphicsResources.dll</html>");
66 ruleNameTextField.requestFocus();
67 addDocumentListeners();
75 private void addDocumentListeners() {
76 SwingUtilities.invokeLater(() -> {
79 DocumentListener docListener;
80 docListener =
new DocumentListener() {
82 public void changedUpdate(DocumentEvent e) {
87 public void insertUpdate(DocumentEvent e) {
92 public void removeUpdate(DocumentEvent e) {
96 ruleNameTextField.getDocument().addDocumentListener(docListener);
97 fullPathsTextArea.getDocument().addDocumentListener(docListener);
106 private void initTextArea(JScrollPane pane, JTextArea textArea) {
107 textArea.setColumns(20);
109 pane.setViewportView(textArea);
110 textArea.addKeyListener(
new KeyAdapter() {
112 public void keyPressed(KeyEvent e) {
113 if (e.getKeyCode() == KeyEvent.VK_TAB) {
114 if (e.getModifiers() > 0) {
115 textArea.transferFocusBackward();
117 textArea.transferFocus();
130 @SuppressWarnings(
"unchecked")
132 private
void initComponents() {
134 shouldSaveCheckBox =
new javax.swing.JCheckBox();
135 shouldAlertCheckBox =
new javax.swing.JCheckBox();
136 fullPathsLabel =
new javax.swing.JLabel();
137 descriptionTextField =
new javax.swing.JTextField();
138 ruleNameLabel =
new javax.swing.JLabel();
139 ruleNameTextField =
new javax.swing.JTextField();
140 fullPathsScrollPane =
new javax.swing.JScrollPane();
141 jSeparator1 =
new javax.swing.JSeparator();
142 jSeparator2 =
new javax.swing.JSeparator();
143 jLabel1 =
new javax.swing.JLabel();
144 jLabel2 =
new javax.swing.JLabel();
146 shouldSaveCheckBox.setSelected(
true);
147 org.openide.awt.Mnemonics.setLocalizedText(shouldSaveCheckBox,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.shouldSaveCheckBox.text"));
148 shouldSaveCheckBox.addActionListener(
new java.awt.event.ActionListener() {
149 public void actionPerformed(java.awt.event.ActionEvent evt) {
150 shouldSaveCheckBoxActionPerformed(evt);
154 org.openide.awt.Mnemonics.setLocalizedText(shouldAlertCheckBox,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.shouldAlertCheckBox.text"));
155 shouldAlertCheckBox.setActionCommand(
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.shouldAlertCheckBox.actionCommand"));
156 shouldAlertCheckBox.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 shouldAlertCheckBoxActionPerformed(evt);
162 org.openide.awt.Mnemonics.setLocalizedText(fullPathsLabel,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.fullPathsLabel.text"));
163 fullPathsLabel.setToolTipText(
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.fullPathsLabel.toolTipText"));
164 fullPathsLabel.setPreferredSize(
new java.awt.Dimension(112, 14));
166 org.openide.awt.Mnemonics.setLocalizedText(ruleNameLabel,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.ruleNameLabel.text"));
167 ruleNameLabel.setPreferredSize(
new java.awt.Dimension(112, 14));
169 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.jLabel1.text"));
170 jLabel1.setPreferredSize(
new java.awt.Dimension(112, 14));
172 org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class,
"EditFullPathsRulePanel.jLabel2.text"));
174 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
175 this.setLayout(layout);
176 layout.setHorizontalGroup(
177 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
178 .addGroup(layout.createSequentialGroup()
180 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
181 .addComponent(jSeparator2)
182 .addComponent(jSeparator1)
183 .addGroup(layout.createSequentialGroup()
184 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
185 .addGroup(layout.createSequentialGroup()
186 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
187 .addComponent(ruleNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
188 .addComponent(fullPathsLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
189 .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
191 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192 .addComponent(ruleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 648, javax.swing.GroupLayout.PREFERRED_SIZE)
193 .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 648, javax.swing.GroupLayout.PREFERRED_SIZE)
194 .addComponent(fullPathsScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 648, javax.swing.GroupLayout.PREFERRED_SIZE)))
195 .addComponent(shouldSaveCheckBox)
196 .addComponent(shouldAlertCheckBox)
197 .addComponent(jLabel2))
198 .addGap(0, 0, Short.MAX_VALUE)))
202 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {fullPathsLabel, jLabel1, ruleNameLabel});
204 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {descriptionTextField, fullPathsScrollPane, ruleNameTextField});
206 layout.setVerticalGroup(
207 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(layout.createSequentialGroup()
210 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
211 .addComponent(ruleNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
212 .addComponent(ruleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
213 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
214 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
215 .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
216 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
217 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
218 .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
219 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
220 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221 .addGroup(layout.createSequentialGroup()
222 .addComponent(fullPathsLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
223 .addGap(0, 115, Short.MAX_VALUE))
224 .addComponent(fullPathsScrollPane))
225 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
226 .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
227 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
228 .addComponent(jLabel2)
229 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
230 .addComponent(shouldSaveCheckBox)
232 .addComponent(shouldAlertCheckBox)
237 private void shouldSaveCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
241 private void shouldAlertCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {
247 private javax.swing.JTextField descriptionTextField;
248 private javax.swing.JLabel fullPathsLabel;
249 private javax.swing.JScrollPane fullPathsScrollPane;
250 private javax.swing.JLabel jLabel1;
251 private javax.swing.JLabel jLabel2;
252 private javax.swing.JSeparator jSeparator1;
253 private javax.swing.JSeparator jSeparator2;
254 private javax.swing.JLabel ruleNameLabel;
255 private javax.swing.JTextField ruleNameTextField;
256 private javax.swing.JCheckBox shouldAlertCheckBox;
257 private javax.swing.JCheckBox shouldSaveCheckBox;
265 if (this.okButton != null) {
266 this.okButton.setEnabled(!StringUtils.isBlank(ruleNameTextField.getText()) && !StringUtils.isBlank(fullPathsTextArea.getText()) && (shouldAlertCheckBox.isSelected() || shouldSaveCheckBox.isSelected()));
277 private JOptionPane getOptionPane(JComponent parent) {
279 if (!(parent instanceof JOptionPane)) {
280 pane = getOptionPane((JComponent) parent.getParent());
282 pane = (JOptionPane) parent;
293 private void setButtons(JButton ok, JButton cancel) {
295 this.cancelButton = cancel;
296 okButton.addActionListener((ActionEvent e) -> {
297 JOptionPane pane = getOptionPane(okButton);
298 pane.setValue(okButton);
300 cancelButton.addActionListener((ActionEvent e) -> {
301 JOptionPane pane = getOptionPane(cancelButton);
302 pane.setValue(cancelButton);
312 private void setRule(String ruleName, LogicalImagerRule rule) {
313 ruleNameTextField.setText(ruleName);
314 descriptionTextField.setText(rule.getDescription());
315 shouldAlertCheckBox.setSelected(rule.isShouldAlert());
316 shouldSaveCheckBox.setSelected(rule.isShouldSave());
326 private void setTextArea(JTextArea textArea, List<String> list) {
328 for (String s : list) {
329 text += s + System.getProperty(
"line.separator");
331 textArea.setText(text);
343 "EditFullPathsRulePanel.fullPaths=Full paths",})
344 ImmutablePair<String, LogicalImagerRule> toRule()
throws IOException {
345 List<String> fullPaths = EditRulePanel.validateTextList(fullPathsTextArea, Bundle.EditFullPathsRulePanel_fullPaths());
346 String ruleName = EditRulePanel.validRuleName(ruleNameTextField.getText());
347 LogicalImagerRule.Builder builder =
new LogicalImagerRule.Builder();
348 builder.getShouldAlert(shouldAlertCheckBox.isSelected())
349 .getShouldSave(shouldSaveCheckBox.isSelected())
351 .getDescription(descriptionTextField.getText())
352 .getFullPaths(fullPaths);
353 LogicalImagerRule rule = builder.build();
354 return new ImmutablePair<>(ruleName, rule);