Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
NewRulePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.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;
29 
33 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
34 class NewRulePanel extends javax.swing.JPanel {
35 
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;
41 
45  NewRulePanel(JButton okButton, JButton cancelButton) {
46  initComponents();
47 
48  nonFullPathsJPanel = createPanel();
49  editNonFullPathsRulePanel = new EditNonFullPathsRulePanel(okButton, cancelButton, "", new LogicalImagerRule(), false);
50  nonFullPathsJPanel.add(editNonFullPathsRulePanel, BorderLayout.NORTH);
51 
52  fullPathsPanel = createPanel();
53  editFullPathsRulePanel = new EditFullPathsRulePanel(okButton, cancelButton, "", new LogicalImagerRule(), false);
54  fullPathsPanel.add(editFullPathsRulePanel, BorderLayout.NORTH);
55 
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);
61  }
62 
63  private JPanel createPanel() {
64  JPanel panel = new JPanel(new BorderLayout());
65  panel.setSize(800, 650);
66  return panel;
67  }
68 
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")
79  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
80  private void initComponents() {
81 
82  chooseLabel = new javax.swing.JLabel();
83  chooseComboBox = new javax.swing.JComboBox<>();
84  sharedLayeredPane = new javax.swing.JLayeredPane();
85  ruleDescription = new javax.swing.JLabel();
86 
87  org.openide.awt.Mnemonics.setLocalizedText(chooseLabel, org.openide.util.NbBundle.getMessage(NewRulePanel.class, "NewRulePanel.chooseLabel.text")); // NOI18N
88 
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);
94  }
95  });
96 
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)
102  );
103  sharedLayeredPaneLayout.setVerticalGroup(
104  sharedLayeredPaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105  .addGap(0, 467, Short.MAX_VALUE)
106  );
107 
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()
113  .addGap(10, 10, 10)
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()
121  .addContainerGap()
122  .addComponent(sharedLayeredPane)
123  .addContainerGap())
124  );
125  layout.setVerticalGroup(
126  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127  .addGroup(layout.createSequentialGroup()
128  .addContainerGap()
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)
136  .addContainerGap())
137  );
138  }// </editor-fold>//GEN-END:initComponents
139 
140  private void chooseComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseComboBoxActionPerformed
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();
152  } else {
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("");
157  }
158 
159  }//GEN-LAST:event_chooseComboBoxActionPerformed
160 
161  // Variables declaration - do not modify//GEN-BEGIN:variables
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;
166  // End of variables declaration//GEN-END:variables
167 
168  ImmutablePair<String, LogicalImagerRule> toRule() throws IOException, NumberFormatException {
169  ImmutablePair<String, LogicalImagerRule> ruleMap;
170  if (chooseComboBox.getSelectedIndex() == 0) {
171  ruleMap = editNonFullPathsRulePanel.toRule();
172  } else {
173  ruleMap = editFullPathsRulePanel.toRule();
174  }
175  return ruleMap;
176  }
177 
178 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.