Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ProfilePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2021 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.ingest;
20 
21 import java.beans.PropertyChangeListener;
22 import org.openide.DialogDisplayer;
23 import org.openide.NotifyDescriptor;
24 import org.openide.util.NbBundle;
26 
30 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
31 class ProfilePanel extends IngestModuleGlobalSettingsPanel {
32 
33  @NbBundle.Messages({"ProfilePanel.title.text=Profile",
34  "ProfilePanel.profileDescLabel.text=Description:",
35  "ProfilePanel.profileNameLabel.text=Profile Name:",
36  "ProfilePanel.newProfileText=NewEmptyProfile",
37  "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
38  "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character. Only \nletters, digits, and underscore characters are allowed."})
39 
40  private final IngestJobSettingsPanel ingestSettingsPanel;
41  private final IngestJobSettings settings;
42  private IngestProfile profile;
43  private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.newProfileText");
44 
48  ProfilePanel() {
49  initComponents();
50  setName(org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.title.text"));
51  settings = new IngestJobSettings(NEW_PROFILE_NAME);
52  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
53  ingestSettingsPanel.setPastJobsButtonVisible(false);
54  jPanel1.add(ingestSettingsPanel, 0);
55 
56  }
57 
58  ProfilePanel(IngestProfile selectedProfile) {
59  initComponents();
60  setName(org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.title.text"));
61  profile = selectedProfile;
62  profileDescArea.setText(profile.getDescription());
63  profileNameField.setText(profile.getName());
64  settings = new IngestJobSettings(selectedProfile.getName());
65  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
66  ingestSettingsPanel.setPastJobsButtonVisible(false);
67  jPanel1.add(ingestSettingsPanel, 0);
68  }
69 
77  String getProfileName() {
78  return profileNameField.getText().trim();
79  }
80 
81  String getProfileDesc() {
82  return profileDescArea.getText();
83  }
84 
85  IngestJobSettings getSettings() {
86  return ingestSettingsPanel.getSettings();
87  }
88 
94  @SuppressWarnings("unchecked")
95  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
96  private void initComponents() {
97 
98  jScrollPane1 = new javax.swing.JScrollPane();
99  jPanel2 = new javax.swing.JPanel();
100  profileNameField = new javax.swing.JTextField();
101  profileDescLabel = new javax.swing.JLabel();
102  profileDescPane = new javax.swing.JScrollPane();
103  profileDescArea = new javax.swing.JTextArea();
104  profileNameLabel = new javax.swing.JLabel();
105  jPanel1 = new javax.swing.JPanel();
106 
107  jScrollPane1.setPreferredSize(new java.awt.Dimension(650, 323));
108 
109  org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileDescLabel.text")); // NOI18N
110 
111  profileDescArea.setColumns(20);
112  profileDescArea.setLineWrap(true);
113  profileDescArea.setRows(8);
114  profileDescArea.setWrapStyleWord(true);
115  profileDescArea.setMinimumSize(new java.awt.Dimension(164, 44));
116  profileDescArea.setName(""); // NOI18N
117  profileDescPane.setViewportView(profileDescArea);
118 
119  org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileNameLabel.text")); // NOI18N
120 
121  jPanel1.setMinimumSize(new java.awt.Dimension(625, 450));
122  jPanel1.setPreferredSize(new java.awt.Dimension(625, 450));
123  jPanel1.setLayout(new java.awt.BorderLayout());
124 
125  javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
126  jPanel2.setLayout(jPanel2Layout);
127  jPanel2Layout.setHorizontalGroup(
128  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129  .addGroup(jPanel2Layout.createSequentialGroup()
130  .addGap(6, 6, 6)
131  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
132  .addComponent(profileDescLabel)
133  .addComponent(profileNameLabel))
134  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
135  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
136  .addComponent(profileDescPane)
137  .addComponent(profileNameField))
138  .addGap(5, 5, 5))
139  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
140  );
141  jPanel2Layout.setVerticalGroup(
142  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
143  .addGroup(jPanel2Layout.createSequentialGroup()
144  .addGap(8, 8, 8)
145  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
146  .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
147  .addComponent(profileNameLabel))
148  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
149  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
150  .addComponent(profileDescLabel)
151  .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
152  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
153  .addGap(2, 2, 2))
154  );
155 
156  jScrollPane1.setViewportView(jPanel2);
157 
158  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
159  this.setLayout(layout);
160  layout.setHorizontalGroup(
161  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
163  );
164  layout.setVerticalGroup(
165  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
167  );
168  }// </editor-fold>//GEN-END:initComponents
169  @Override
170  public void removePropertyChangeListener(PropertyChangeListener l) {
171  ingestSettingsPanel.removePropertyChangeListener(l);
172  }
173 
174  @Override
175  public void addPropertyChangeListener(PropertyChangeListener l) {
176  super.addPropertyChangeListener(l);
177  /*
178  * There is at least one look and feel library that follows the bad
179  * practice of calling overrideable methods in a constructor, e.g.:
180  *
181  * at
182  * javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:83)
183  * at
184  * javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:63)
185  * at javax.swing.JComponent.setUI(JComponent.java:666) at
186  * javax.swing.JPanel.setUI(JPanel.java:153) at
187  * javax.swing.JPanel.updateUI(JPanel.java:126) at
188  * javax.swing.JPanel.<init>(JPanel.java:86) at
189  * javax.swing.JPanel.<init>(JPanel.java:109) at
190  * javax.swing.JPanel.<init>(JPanel.java:117)
191  *
192  * When this happens, the following child components of this JPanel
193  * subclass have not been constructed yet, since this panel's
194  * constructor has not been called yet.
195  */
196  if (null != ingestSettingsPanel) {
197  ingestSettingsPanel.addPropertyChangeListener(l);
198  }
199  }
200  // Variables declaration - do not modify//GEN-BEGIN:variables
201  private javax.swing.JPanel jPanel1;
202  private javax.swing.JPanel jPanel2;
203  private javax.swing.JScrollPane jScrollPane1;
204  private javax.swing.JTextArea profileDescArea;
205  private javax.swing.JLabel profileDescLabel;
206  private javax.swing.JScrollPane profileDescPane;
207  private javax.swing.JTextField profileNameField;
208  private javax.swing.JLabel profileNameLabel;
209  // End of variables declaration//GEN-END:variables
210 
214  @Override
215  public void saveSettings() {
216  if (profile == null) {
217  IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
218  } else if (!profile.getName().equals(getProfileName())) {
219  IngestProfile.renameProfile(profile.getName(), getProfileName());
220  }
221  profile = new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
222  IngestProfile.saveProfile(profile);
223  ingestSettingsPanel.getSettings().saveAs(getProfileName());
224  }
225 
229  boolean store() {
230  if (!isValidDefinition(false)) {
231  return false;
232  }
233  saveSettings();
234  return true;
235  }
236 
237  void load() {
238  }
239 
247  boolean isValidDefinition(boolean dispayWarnings) {
248  String profileName = getProfileName();
249  if (profileName.isEmpty()) {
250  if (dispayWarnings) {
251  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
252  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profilesMustBeNamed"),
253  NotifyDescriptor.WARNING_MESSAGE);
254  DialogDisplayer.getDefault().notify(notifyDesc);
255  }
256  return false;
257  }
258 
259  // check if the name contains illegal characters
260  String sanitizedName = profileName.replaceAll("[^A-Za-z0-9_]", "");
261  if (!(profileName.equals(sanitizedName))) {
262  if (dispayWarnings) {
263  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
264  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"),
265  NotifyDescriptor.WARNING_MESSAGE);
266  DialogDisplayer.getDefault().notify(notifyDesc);
267  }
268  return false;
269  }
270  return true;
271  }
272 }

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.