Autopsy 4.22.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 */
19package org.sleuthkit.autopsy.ingest;
20
21import java.beans.PropertyChangeListener;
22import org.openide.DialogDisplayer;
23import org.openide.NotifyDescriptor;
24import org.openide.util.NbBundle;
25import org.sleuthkit.autopsy.ingest.IngestProfiles.IngestProfile;
26
30@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
31class 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(IngestProfiles.getExecutionContext(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(IngestProfiles.getExecutionContext(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
89 String getIngestProfileName() {
90 if (profile != null) {
91 return profile.getName();
92 } else {
93 return NEW_PROFILE_NAME;
94 }
95 }
96
102 @SuppressWarnings("unchecked")
103 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
104 private void initComponents() {
105
106 jScrollPane1 = new javax.swing.JScrollPane();
107 jPanel2 = new javax.swing.JPanel();
108 profileNameField = new javax.swing.JTextField();
109 profileDescLabel = new javax.swing.JLabel();
110 profileDescPane = new javax.swing.JScrollPane();
111 profileDescArea = new javax.swing.JTextArea();
112 profileNameLabel = new javax.swing.JLabel();
113 jPanel1 = new javax.swing.JPanel();
114
115 jScrollPane1.setPreferredSize(new java.awt.Dimension(650, 323));
116
117 org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileDescLabel.text")); // NOI18N
118
119 profileDescArea.setColumns(20);
120 profileDescArea.setLineWrap(true);
121 profileDescArea.setRows(8);
122 profileDescArea.setWrapStyleWord(true);
123 profileDescArea.setMinimumSize(new java.awt.Dimension(164, 44));
124 profileDescArea.setName(""); // NOI18N
125 profileDescPane.setViewportView(profileDescArea);
126
127 org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileNameLabel.text")); // NOI18N
128
129 jPanel1.setMinimumSize(new java.awt.Dimension(625, 450));
130 jPanel1.setPreferredSize(new java.awt.Dimension(625, 450));
131 jPanel1.setLayout(new java.awt.BorderLayout());
132
133 javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
134 jPanel2.setLayout(jPanel2Layout);
135 jPanel2Layout.setHorizontalGroup(
136 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addGroup(jPanel2Layout.createSequentialGroup()
138 .addGap(6, 6, 6)
139 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
140 .addComponent(profileDescLabel)
141 .addComponent(profileNameLabel))
142 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
143 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144 .addComponent(profileDescPane)
145 .addComponent(profileNameField))
146 .addGap(5, 5, 5))
147 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
148 );
149 jPanel2Layout.setVerticalGroup(
150 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
151 .addGroup(jPanel2Layout.createSequentialGroup()
152 .addGap(8, 8, 8)
153 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
154 .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
155 .addComponent(profileNameLabel))
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
157 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addComponent(profileDescLabel)
159 .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
160 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
161 .addGap(2, 2, 2))
162 );
163
164 jScrollPane1.setViewportView(jPanel2);
165
166 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
167 this.setLayout(layout);
168 layout.setHorizontalGroup(
169 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
170 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
171 );
172 layout.setVerticalGroup(
173 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
174 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
175 );
176 }// </editor-fold>//GEN-END:initComponents
177 @Override
178 public void removePropertyChangeListener(PropertyChangeListener l) {
179 ingestSettingsPanel.removePropertyChangeListener(l);
180 }
181
182 @Override
183 public void addPropertyChangeListener(PropertyChangeListener l) {
184 super.addPropertyChangeListener(l);
185 /*
186 * There is at least one look and feel library that follows the bad
187 * practice of calling overrideable methods in a constructor, e.g.:
188 *
189 * at
190 * javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:83)
191 * at
192 * javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:63)
193 * at javax.swing.JComponent.setUI(JComponent.java:666) at
194 * javax.swing.JPanel.setUI(JPanel.java:153) at
195 * javax.swing.JPanel.updateUI(JPanel.java:126) at
196 * javax.swing.JPanel.<init>(JPanel.java:86) at
197 * javax.swing.JPanel.<init>(JPanel.java:109) at
198 * javax.swing.JPanel.<init>(JPanel.java:117)
199 *
200 * When this happens, the following child components of this JPanel
201 * subclass have not been constructed yet, since this panel's
202 * constructor has not been called yet.
203 */
204 if (null != ingestSettingsPanel) {
205 ingestSettingsPanel.addPropertyChangeListener(l);
206 }
207 }
208 // Variables declaration - do not modify//GEN-BEGIN:variables
209 private javax.swing.JPanel jPanel1;
210 private javax.swing.JPanel jPanel2;
211 private javax.swing.JScrollPane jScrollPane1;
212 private javax.swing.JTextArea profileDescArea;
213 private javax.swing.JLabel profileDescLabel;
214 private javax.swing.JScrollPane profileDescPane;
215 private javax.swing.JTextField profileNameField;
216 private javax.swing.JLabel profileNameLabel;
217 // End of variables declaration//GEN-END:variables
218
222 @Override
223 public void saveSettings() {
224 if (profile == null) {
225 IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
226 } else if (!profile.getName().equals(getProfileName())) {
227 IngestProfile.renameProfile(profile.getName(), getProfileName());
228 }
229 profile = new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
230 IngestProfile.saveProfile(profile);
231 ingestSettingsPanel.getSettings().saveAs(IngestProfiles.getExecutionContext(getProfileName()));
232 }
233
237 boolean store() {
238 if (!isValidDefinition(false)) {
239 return false;
240 }
241 saveSettings();
242 return true;
243 }
244
245 void load() {
246 }
247
255 boolean isValidDefinition(boolean dispayWarnings) {
256 String profileName = getProfileName();
257 if (profileName.isEmpty()) {
258 if (dispayWarnings) {
259 NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
260 NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profilesMustBeNamed"),
261 NotifyDescriptor.WARNING_MESSAGE);
262 DialogDisplayer.getDefault().notify(notifyDesc);
263 }
264 return false;
265 }
266
267 // check if the name contains illegal characters
268 String sanitizedName = profileName.replaceAll("[^A-Za-z0-9_]", "");
269 if (!(profileName.equals(sanitizedName))) {
270 if (dispayWarnings) {
271 NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
272 NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"),
273 NotifyDescriptor.WARNING_MESSAGE);
274 DialogDisplayer.getDefault().notify(notifyDesc);
275 }
276 return false;
277 }
278 return true;
279 }
280}

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.