Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EditFullPathsRulePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.logicalimager.configuration;
20 
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 org.apache.commons.lang3.tuple.ImmutablePair;
32 import org.openide.util.NbBundle;
33 
37 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
38 final class EditFullPathsRulePanel extends javax.swing.JPanel {
39 
40  private JButton okButton;
41  private JButton cancelButton;
42  private final JTextArea fullPathsTextArea;
43 
47  @NbBundle.Messages({
48  "EditFullPathsRulePanel.example=Example: "
49  })
50  EditFullPathsRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule, boolean editing) {
51  initComponents();
52 
53  if (editing) {
54  ruleNameTextField.setEnabled(!editing);
55  }
56 
57  this.setRule(ruleName, rule);
58  this.setButtons(okButton, cancelButton);
59 
60  fullPathsTextArea = new JTextArea();
61  initTextArea(fullPathsScrollPane, fullPathsTextArea);
62  setTextArea(fullPathsTextArea, rule.getFullPaths());
63 
64  EditRulePanel.setTextFieldPrompts(fullPathsTextArea,
65  "<html>" + Bundle.EditFullPathsRulePanel_example() + "<br>/Program Files/Common Files/system/wab32.dll<br>/Windows/System32/1033/VsGraphicsResources.dll</html>"); // NON-NLS
66  ruleNameTextField.requestFocus();
67  validate();
68  repaint();
69  }
70 
71  private void initTextArea(JScrollPane pane, JTextArea textArea) {
72  textArea.setColumns(20);
73  textArea.setRows(5);
74  pane.setViewportView(textArea);
75  textArea.addKeyListener(new KeyAdapter() {
76  @Override
77  public void keyPressed(KeyEvent e) {
78  if (e.getKeyCode() == KeyEvent.VK_TAB) {
79  if (e.getModifiers() > 0) {
80  textArea.transferFocusBackward();
81  } else {
82  textArea.transferFocus();
83  }
84  e.consume();
85  }
86  }
87  });
88  }
89 
95  @SuppressWarnings("unchecked")
96  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
97  private void initComponents() {
98 
99  shouldSaveCheckBox = new javax.swing.JCheckBox();
100  shouldAlertCheckBox = new javax.swing.JCheckBox();
101  fullPathsLabel = new javax.swing.JLabel();
102  descriptionTextField = new javax.swing.JTextField();
103  descriptionLabel = new javax.swing.JLabel();
104  ruleNameLabel = new javax.swing.JLabel();
105  ruleNameTextField = new javax.swing.JTextField();
106  fullPathsScrollPane = new javax.swing.JScrollPane();
107 
108  shouldSaveCheckBox.setSelected(true);
109  org.openide.awt.Mnemonics.setLocalizedText(shouldSaveCheckBox, org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.shouldSaveCheckBox.text")); // NOI18N
110 
111  org.openide.awt.Mnemonics.setLocalizedText(shouldAlertCheckBox, org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.shouldAlertCheckBox.text")); // NOI18N
112  shouldAlertCheckBox.setActionCommand(org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.shouldAlertCheckBox.actionCommand")); // NOI18N
113 
114  org.openide.awt.Mnemonics.setLocalizedText(fullPathsLabel, org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.fullPathsLabel.text")); // NOI18N
115  fullPathsLabel.setToolTipText(org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.fullPathsLabel.toolTipText")); // NOI18N
116 
117  descriptionTextField.setText(org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.descriptionTextField.text")); // NOI18N
118 
119  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.descriptionLabel.text")); // NOI18N
120 
121  org.openide.awt.Mnemonics.setLocalizedText(ruleNameLabel, org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.ruleNameLabel.text")); // NOI18N
122 
123  ruleNameTextField.setText(org.openide.util.NbBundle.getMessage(EditFullPathsRulePanel.class, "EditFullPathsRulePanel.ruleNameTextField.text")); // NOI18N
124 
125  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
126  this.setLayout(layout);
127  layout.setHorizontalGroup(
128  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129  .addGroup(layout.createSequentialGroup()
130  .addContainerGap()
131  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132  .addComponent(shouldSaveCheckBox)
133  .addComponent(shouldAlertCheckBox)
134  .addGroup(layout.createSequentialGroup()
135  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136  .addComponent(ruleNameLabel)
137  .addComponent(descriptionLabel)
138  .addComponent(fullPathsLabel))
139  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
140  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141  .addComponent(ruleNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
142  .addComponent(descriptionTextField)
143  .addComponent(fullPathsScrollPane))))
144  .addContainerGap())
145  );
146  layout.setVerticalGroup(
147  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148  .addGroup(layout.createSequentialGroup()
149  .addContainerGap()
150  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
151  .addComponent(ruleNameLabel)
152  .addComponent(ruleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
153  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
155  .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
156  .addComponent(descriptionLabel))
157  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
158  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
159  .addGroup(layout.createSequentialGroup()
160  .addComponent(fullPathsLabel)
161  .addGap(0, 167, Short.MAX_VALUE))
162  .addComponent(fullPathsScrollPane))
163  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
164  .addComponent(shouldAlertCheckBox)
165  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
166  .addComponent(shouldSaveCheckBox)
167  .addContainerGap())
168  );
169  }// </editor-fold>//GEN-END:initComponents
170 
171 
172  // Variables declaration - do not modify//GEN-BEGIN:variables
173  private javax.swing.JLabel descriptionLabel;
174  private javax.swing.JTextField descriptionTextField;
175  private javax.swing.JLabel fullPathsLabel;
176  private javax.swing.JScrollPane fullPathsScrollPane;
177  private javax.swing.JLabel ruleNameLabel;
178  private javax.swing.JTextField ruleNameTextField;
179  private javax.swing.JCheckBox shouldAlertCheckBox;
180  private javax.swing.JCheckBox shouldSaveCheckBox;
181  // End of variables declaration//GEN-END:variables
182 
187  private void setOkButton() {
188  if (this.okButton != null) {
189  this.okButton.setEnabled(true);
190  }
191  }
192 
200  private JOptionPane getOptionPane(JComponent parent) {
201  JOptionPane pane;
202  if (!(parent instanceof JOptionPane)) {
203  pane = getOptionPane((JComponent) parent.getParent());
204  } else {
205  pane = (JOptionPane) parent;
206  }
207  return pane;
208  }
209 
216  private void setButtons(JButton ok, JButton cancel) {
217  this.okButton = ok;
218  this.cancelButton = cancel;
219  okButton.addActionListener((ActionEvent e) -> {
220  JOptionPane pane = getOptionPane(okButton);
221  pane.setValue(okButton);
222  });
223  cancelButton.addActionListener((ActionEvent e) -> {
224  JOptionPane pane = getOptionPane(cancelButton);
225  pane.setValue(cancelButton);
226  });
227  this.setOkButton();
228  }
229 
230  private void setRule(String ruleName, LogicalImagerRule rule) {
231  ruleNameTextField.setText(ruleName);
232  descriptionTextField.setText(rule.getDescription());
233  shouldAlertCheckBox.setSelected(rule.isShouldAlert());
234  shouldSaveCheckBox.setSelected(rule.isShouldSave());
235  }
236 
237  private void setTextArea(JTextArea textArea, List<String> set) {
238  String text = "";
239  for (String s : set) {
240  text += s + System.getProperty("line.separator"); // NON-NLS
241  }
242  textArea.setText(text);
243  }
244 
245  @NbBundle.Messages({
246  "EditFullPathsRulePanel.fullPaths=Full paths",
247  })
248  ImmutablePair<String, LogicalImagerRule> toRule() throws IOException {
249  List<String> fullPaths = EditRulePanel.validateTextList(fullPathsTextArea, Bundle.EditFullPathsRulePanel_fullPaths());
250  String ruleName = EditRulePanel.validRuleName(ruleNameTextField.getText());
251  LogicalImagerRule.Builder builder = new LogicalImagerRule.Builder();
252  builder.getShouldAlert(shouldAlertCheckBox.isSelected())
253  .getShouldSave(shouldSaveCheckBox.isSelected())
254  .getName(ruleName)
255  .getDescription(descriptionTextField.getText())
256  .getFullPaths(fullPaths);
257  LogicalImagerRule rule = builder.build();
258  return new ImmutablePair<>(ruleName, rule);
259  }
260 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.