Autopsy  4.16.0
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-2018 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 java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26 import org.openide.DialogDisplayer;
27 import org.openide.NotifyDescriptor;
28 import org.openide.util.NbBundle;
30 
34 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
35 class ProfilePanel extends IngestModuleGlobalSettingsPanel {
36 
37  @NbBundle.Messages({"ProfilePanel.title.text=Profile",
38  "ProfilePanel.profileDescLabel.text=Description:",
39  "ProfilePanel.profileNameLabel.text=Profile Name:",
40  "ProfilePanel.newProfileText=NewEmptyProfile",
41  "ProfilePanel.messages.profilesMustBeNamed=Ingest profile must be named.",
42  "ProfilePanel.messages.profileNameContainsIllegalCharacter=Profile name contains an illegal character"})
43 
44  private final IngestJobSettingsPanel ingestSettingsPanel;
45  private final IngestJobSettings settings;
46  private IngestProfile profile;
47  private final static String NEW_PROFILE_NAME = NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.newProfileText");
48  private static final List<String> ILLEGAL_NAME_CHARS = Collections.unmodifiableList(new ArrayList<>(Arrays.asList("\\", "/", ":", "*", "?", "\"", "<", ">")));
49 
53  ProfilePanel() {
54  initComponents();
55  setName(org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.title.text"));
56  settings = new IngestJobSettings(NEW_PROFILE_NAME);
57  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
58  ingestSettingsPanel.setPastJobsButtonVisible(false);
59  jPanel1.add(ingestSettingsPanel, 0);
60 
61  }
62 
63  ProfilePanel(IngestProfile selectedProfile) {
64  initComponents();
65  setName(org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.title.text"));
66  profile = selectedProfile;
67  profileDescArea.setText(profile.getDescription());
68  profileNameField.setText(profile.getName());
69  settings = new IngestJobSettings(selectedProfile.getName());
70  ingestSettingsPanel = new IngestJobSettingsPanel(settings);
71  ingestSettingsPanel.setPastJobsButtonVisible(false);
72  jPanel1.add(ingestSettingsPanel, 0);
73  }
74 
82  String getProfileName() {
83  return profileNameField.getText().trim();
84  }
85 
86  String getProfileDesc() {
87  return profileDescArea.getText();
88  }
89 
90  IngestJobSettings getSettings() {
91  return ingestSettingsPanel.getSettings();
92  }
93 
99  @SuppressWarnings("unchecked")
100  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
101  private void initComponents() {
102 
103  jScrollPane1 = new javax.swing.JScrollPane();
104  jPanel2 = new javax.swing.JPanel();
105  profileNameField = new javax.swing.JTextField();
106  profileDescLabel = new javax.swing.JLabel();
107  profileDescPane = new javax.swing.JScrollPane();
108  profileDescArea = new javax.swing.JTextArea();
109  profileNameLabel = new javax.swing.JLabel();
110  jPanel1 = new javax.swing.JPanel();
111 
112  jScrollPane1.setPreferredSize(new java.awt.Dimension(650, 323));
113 
114  org.openide.awt.Mnemonics.setLocalizedText(profileDescLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileDescLabel.text")); // NOI18N
115 
116  profileDescArea.setColumns(20);
117  profileDescArea.setLineWrap(true);
118  profileDescArea.setRows(8);
119  profileDescArea.setWrapStyleWord(true);
120  profileDescArea.setMinimumSize(new java.awt.Dimension(164, 44));
121  profileDescArea.setName(""); // NOI18N
122  profileDescPane.setViewportView(profileDescArea);
123 
124  org.openide.awt.Mnemonics.setLocalizedText(profileNameLabel, org.openide.util.NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.profileNameLabel.text")); // NOI18N
125 
126  jPanel1.setMinimumSize(new java.awt.Dimension(625, 450));
127  jPanel1.setPreferredSize(new java.awt.Dimension(625, 450));
128  jPanel1.setLayout(new java.awt.BorderLayout());
129 
130  javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
131  jPanel2.setLayout(jPanel2Layout);
132  jPanel2Layout.setHorizontalGroup(
133  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
134  .addGroup(jPanel2Layout.createSequentialGroup()
135  .addGap(6, 6, 6)
136  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
137  .addComponent(profileDescLabel)
138  .addComponent(profileNameLabel))
139  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
140  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
141  .addComponent(profileDescPane)
142  .addComponent(profileNameField))
143  .addGap(5, 5, 5))
144  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
145  );
146  jPanel2Layout.setVerticalGroup(
147  jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148  .addGroup(jPanel2Layout.createSequentialGroup()
149  .addGap(8, 8, 8)
150  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
151  .addComponent(profileNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
152  .addComponent(profileNameLabel))
153  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154  .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155  .addComponent(profileDescLabel)
156  .addComponent(profileDescPane, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
157  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
158  .addGap(2, 2, 2))
159  );
160 
161  jScrollPane1.setViewportView(jPanel2);
162 
163  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
164  this.setLayout(layout);
165  layout.setHorizontalGroup(
166  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 627, Short.MAX_VALUE)
168  );
169  layout.setVerticalGroup(
170  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
172  );
173  }// </editor-fold>//GEN-END:initComponents
174  @Override
175  public void removePropertyChangeListener(PropertyChangeListener l) {
176  ingestSettingsPanel.removePropertyChangeListener(l);
177  }
178 
179  @Override
180  public void addPropertyChangeListener(PropertyChangeListener l) {
181  super.addPropertyChangeListener(l);
182  /*
183  * There is at least one look and feel library that follows the bad
184  * practice of calling overrideable methods in a constructor, e.g.:
185  *
186  * at
187  * javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:83)
188  * at
189  * javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:63)
190  * at javax.swing.JComponent.setUI(JComponent.java:666) at
191  * javax.swing.JPanel.setUI(JPanel.java:153) at
192  * javax.swing.JPanel.updateUI(JPanel.java:126) at
193  * javax.swing.JPanel.<init>(JPanel.java:86) at
194  * javax.swing.JPanel.<init>(JPanel.java:109) at
195  * javax.swing.JPanel.<init>(JPanel.java:117)
196  *
197  * When this happens, the following child components of this JPanel
198  * subclass have not been constructed yet, since this panel's
199  * constructor has not been called yet.
200  */
201  if (null != ingestSettingsPanel) {
202  ingestSettingsPanel.addPropertyChangeListener(l);
203  }
204  }
205  // Variables declaration - do not modify//GEN-BEGIN:variables
206  private javax.swing.JPanel jPanel1;
207  private javax.swing.JPanel jPanel2;
208  private javax.swing.JScrollPane jScrollPane1;
209  private javax.swing.JTextArea profileDescArea;
210  private javax.swing.JLabel profileDescLabel;
211  private javax.swing.JScrollPane profileDescPane;
212  private javax.swing.JTextField profileNameField;
213  private javax.swing.JLabel profileNameLabel;
214  // End of variables declaration//GEN-END:variables
215 
219  @Override
220  public void saveSettings() {
221  if (profile == null) {
222  IngestProfile.renameProfile(settings.getExecutionContext(), getProfileName());
223  } else if (!profile.getName().equals(getProfileName())) {
224  IngestProfile.renameProfile(profile.getName(), getProfileName());
225  }
226  profile = new IngestProfile(getProfileName(), profileDescArea.getText(), ingestSettingsPanel.getSettings().getFileFilter().getName());
227  IngestProfile.saveProfile(profile);
228  ingestSettingsPanel.getSettings().saveAs(getProfileName());
229  }
230 
234  void store() {
235  saveSettings();
236  }
237 
238  void load() {
239  }
240 
246  boolean isValidDefinition() {
247  if (getProfileName().isEmpty()) {
248  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
249  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profilesMustBeNamed"),
250  NotifyDescriptor.WARNING_MESSAGE);
251  DialogDisplayer.getDefault().notify(notifyDesc);
252  return false;
253  }
254  if (!containsOnlyLegalChars(getProfileName(), ILLEGAL_NAME_CHARS)) {
255  NotifyDescriptor notifyDesc = new NotifyDescriptor.Message(
256  NbBundle.getMessage(ProfilePanel.class, "ProfilePanel.messages.profileNameContainsIllegalCharacter"),
257  NotifyDescriptor.WARNING_MESSAGE);
258  DialogDisplayer.getDefault().notify(notifyDesc);
259  return false;
260  }
261  return true;
262  }
263 
273  private static boolean containsOnlyLegalChars(String toBeChecked, List<String> illegalChars) {
274  for (String illegalChar : illegalChars) {
275  if (toBeChecked.contains(illegalChar)) {
276  return false;
277  }
278  }
279  return true;
280  }
281 }

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