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 EditFullPathsRulePanel editFullPathsRulePanel = null;
42 private EditNonFullPathsRulePanel editNonFullPathsRulePanel = null;
47 EditRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule) {
48 if (rule.getFullPaths() != null && rule.getFullPaths().size() > 0) {
49 editFullPathsRulePanel =
new EditFullPathsRulePanel(okButton, cancelButton, ruleName, rule,
true);
51 editNonFullPathsRulePanel =
new EditNonFullPathsRulePanel(okButton, cancelButton, ruleName, rule,
true);
56 if (editFullPathsRulePanel != null) {
57 return editFullPathsRulePanel;
59 return editNonFullPathsRulePanel;
63 ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
64 ImmutablePair<String, LogicalImagerRule> ruleMap;
65 if (editFullPathsRulePanel != null) {
66 ruleMap = editFullPathsRulePanel.toRule();
68 ruleMap = editNonFullPathsRulePanel.toRule();
73 static void setTextFieldPrompts(JTextComponent textField, String text) {
77 TextPrompt textPrompt;
78 if (textField instanceof JTextArea) {
79 textPrompt =
new TextPrompt(text, textField, BorderLayout.NORTH);
81 textPrompt =
new TextPrompt(text, textField);
87 textPrompt.setForeground(Color.LIGHT_GRAY);
88 textPrompt.changeAlpha(0.9f);
92 "EditRulePanel.validateRuleNameExceptionMsg=Rule name cannot be empty"
94 static String validRuleName(String name)
throws IOException {
96 throw new IOException(Bundle.EditRulePanel_validateRuleNameExceptionMsg());
103 "EditRulePanel.blankLineException={0} cannot have a blank line",
105 static List<String> validateTextList(JTextArea textArea, String fieldName)
throws IOException {
106 if (isBlank(textArea.getText())) {
109 List<String> list =
new ArrayList<>();
110 for (String line : textArea.getText().split(
"\\n")) {
112 if (line.isEmpty()) {
113 throw new IOException(Bundle.EditRulePanel_blankLineException(fieldName));
117 if (list.isEmpty()) {