19 package org.sleuthkit.autopsy.logicalimager.configuration;
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JButton;
27 import javax.swing.JPanel;
28 import javax.swing.JTextArea;
29 import javax.swing.text.JTextComponent;
30 import static org.apache.commons.lang.StringUtils.isBlank;
31 import static org.apache.commons.lang3.StringUtils.strip;
32 import org.apache.commons.lang3.tuple.ImmutablePair;
33 import org.openide.util.NbBundle;
39 final class EditRulePanel
extends JPanel {
41 private static final long serialVersionUID = 1L;
42 private final EditFullPathsRulePanel editFullPathsRulePanel;
43 private final EditNonFullPathsRulePanel editNonFullPathsRulePanel;
48 EditRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule) {
49 if (rule.getFullPaths() != null && rule.getFullPaths().size() > 0) {
50 editFullPathsRulePanel =
new EditFullPathsRulePanel(okButton, cancelButton, ruleName, rule,
true);
51 editNonFullPathsRulePanel = null;
53 editNonFullPathsRulePanel =
new EditNonFullPathsRulePanel(okButton, cancelButton, ruleName, rule,
true);
54 editFullPathsRulePanel = null;
59 if (editFullPathsRulePanel != null) {
60 return editFullPathsRulePanel;
62 return editNonFullPathsRulePanel;
66 ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
67 ImmutablePair<String, LogicalImagerRule> ruleMap;
68 if (editFullPathsRulePanel != null) {
69 ruleMap = editFullPathsRulePanel.toRule();
71 ruleMap = editNonFullPathsRulePanel.toRule();
76 static void setTextFieldPrompts(JTextComponent textField, String text) {
80 TextPrompt textPrompt;
81 if (textField instanceof JTextArea) {
82 textPrompt =
new TextPrompt(text, textField, BorderLayout.NORTH);
84 textPrompt =
new TextPrompt(text, textField);
90 textPrompt.setForeground(Color.LIGHT_GRAY);
91 textPrompt.changeAlpha(0.9f);
95 "EditRulePanel.emptyRuleName.message=Rule name cannot be empty",
97 "EditRulePanel.reservedRuleName.message=Rule name \"{0}\" is reserved for use with a predefined rule"})
98 static String validRuleName(String name)
throws IOException {
100 throw new IOException(Bundle.EditRulePanel_emptyRuleName_message());
102 if (name.equals(EncryptionProgramsRule.getName())) {
103 throw new IOException(Bundle.EditRulePanel_reservedRuleName_message(name));
111 "EditRulePanel.blankLineException={0} cannot have a blank line",})
112 static List<String> validateTextList(JTextArea textArea, String fieldName)
throws IOException {
113 if (isBlank(textArea.getText())) {
116 List<String> list =
new ArrayList<>();
117 for (String line : textArea.getText().split(
"\\n")) {
118 String strippedLine = strip(line);
119 if (strippedLine.isEmpty()) {
120 throw new IOException(Bundle.EditRulePanel_blankLineException(fieldName));
122 list.add(strippedLine);
124 if (list.isEmpty()) {