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

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.