19 package org.sleuthkit.autopsy.logicalimager.configuration;
21 import java.awt.BorderLayout;
22 import java.io.IOException;
23 import java.util.logging.Level;
24 import javax.swing.JButton;
25 import javax.swing.JPanel;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.openide.util.NbBundle.Messages;
33 @SuppressWarnings(
"PMD.SingularField")
34 class NewRulePanel extends javax.swing.JPanel {
36 private static final Logger logger = Logger.
getLogger(NewRulePanel.class.getName());
37 private final JPanel nonFullPathsJPanel;
38 private final EditNonFullPathsRulePanel editNonFullPathsRulePanel;
39 private final JPanel fullPathsPanel;
40 private final EditFullPathsRulePanel editFullPathsRulePanel;
45 NewRulePanel(JButton okButton, JButton cancelButton) {
48 nonFullPathsJPanel = createPanel();
49 editNonFullPathsRulePanel =
new EditNonFullPathsRulePanel(okButton, cancelButton,
"",
new LogicalImagerRule(),
false);
50 nonFullPathsJPanel.add(editNonFullPathsRulePanel, BorderLayout.NORTH);
52 fullPathsPanel = createPanel();
53 editFullPathsRulePanel =
new EditFullPathsRulePanel(okButton, cancelButton,
"",
new LogicalImagerRule(),
false);
54 fullPathsPanel.add(editFullPathsRulePanel, BorderLayout.NORTH);
56 sharedLayeredPane.add(nonFullPathsJPanel, Integer.valueOf(0));
57 sharedLayeredPane.add(fullPathsPanel, Integer.valueOf(1));
58 nonFullPathsJPanel.setVisible(
true);
59 ruleDescription.setText(Bundle.NewRuleSetPanel_attributeRule_description());
60 fullPathsPanel.setVisible(
false);
63 private JPanel createPanel() {
64 JPanel panel =
new JPanel(
new BorderLayout());
65 panel.setSize(800, 650);
74 @Messages({
"NewRuleSetPanel.attributeRule.name=Attribute",
75 "NewRuleSetPanel.fullPathRule.name=Full Path",
76 "NewRuleSetPanel.attributeRule.description=Search for files based on one or more attributes or metadata fields.",
77 "NewRuleSetPanel.fullPathRule.description=Search for files based on full exact match path."})
78 @SuppressWarnings(
"unchecked")
80 private
void initComponents() {
82 chooseLabel =
new javax.swing.JLabel();
83 chooseComboBox =
new javax.swing.JComboBox<>();
84 sharedLayeredPane =
new javax.swing.JLayeredPane();
85 ruleDescription =
new javax.swing.JLabel();
87 org.openide.awt.Mnemonics.setLocalizedText(chooseLabel,
org.openide.util.NbBundle.getMessage(NewRulePanel.class,
"NewRulePanel.chooseLabel.text"));
89 chooseComboBox.setMaximumRowCount(2);
90 chooseComboBox.setModel(
new javax.swing.DefaultComboBoxModel<>(
new String[] {Bundle.NewRuleSetPanel_attributeRule_name(), Bundle.NewRuleSetPanel_fullPathRule_name()}));
91 chooseComboBox.addActionListener(
new java.awt.event.ActionListener() {
92 public void actionPerformed(java.awt.event.ActionEvent evt) {
93 chooseComboBoxActionPerformed(evt);
97 javax.swing.GroupLayout sharedLayeredPaneLayout =
new javax.swing.GroupLayout(sharedLayeredPane);
98 sharedLayeredPane.setLayout(sharedLayeredPaneLayout);
99 sharedLayeredPaneLayout.setHorizontalGroup(
100 sharedLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
101 .addGap(0, 0, Short.MAX_VALUE)
103 sharedLayeredPaneLayout.setVerticalGroup(
104 sharedLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105 .addGap(0, 467, Short.MAX_VALUE)
108 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
109 this.setLayout(layout);
110 layout.setHorizontalGroup(
111 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112 .addGroup(layout.createSequentialGroup()
114 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
115 .addComponent(chooseLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
116 .addComponent(chooseComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
117 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
118 .addComponent(ruleDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 562, javax.swing.GroupLayout.PREFERRED_SIZE)
119 .addContainerGap(114, Short.MAX_VALUE))
120 .addGroup(layout.createSequentialGroup()
122 .addComponent(sharedLayeredPane)
125 layout.setVerticalGroup(
126 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127 .addGroup(layout.createSequentialGroup()
129 .addComponent(chooseLabel)
130 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
131 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
132 .addComponent(chooseComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
133 .addComponent(ruleDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
134 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
135 .addComponent(sharedLayeredPane)
140 private void chooseComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
141 int index = chooseComboBox.getSelectedIndex();
142 if (chooseComboBox.getItemAt(index).equals(Bundle.NewRuleSetPanel_attributeRule_name())) {
143 nonFullPathsJPanel.setVisible(
true);
144 editNonFullPathsRulePanel.setOkButton();
145 ruleDescription.setText(Bundle.NewRuleSetPanel_attributeRule_description());
146 fullPathsPanel.setVisible(
false);
147 }
else if (chooseComboBox.getItemAt(index).equals(Bundle.NewRuleSetPanel_fullPathRule_name())) {
148 nonFullPathsJPanel.setVisible(
false);
149 ruleDescription.setText(Bundle.NewRuleSetPanel_fullPathRule_description());
150 fullPathsPanel.setVisible(
true);
151 editFullPathsRulePanel.setOkButton();
153 logger.log(Level.WARNING,
"Rule type selected was not one of the expected rule types");
154 nonFullPathsJPanel.setVisible(
false);
155 fullPathsPanel.setVisible(
false);
156 ruleDescription.setText(
"");
162 private javax.swing.JComboBox<String> chooseComboBox;
163 private javax.swing.JLabel chooseLabel;
164 private javax.swing.JLabel ruleDescription;
165 private javax.swing.JLayeredPane sharedLayeredPane;
168 ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
169 ImmutablePair<String, LogicalImagerRule> ruleMap;
170 if (chooseComboBox.getSelectedIndex() == 0) {
171 ruleMap = editNonFullPathsRulePanel.toRule();
173 ruleMap = editFullPathsRulePanel.toRule();
synchronized static Logger getLogger(String name)