Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.text.NumberFormat;
22 import javax.swing.DefaultComboBoxModel;
23 import javax.swing.JFormattedTextField;
24 import javax.swing.event.DocumentEvent;
25 import javax.swing.event.DocumentListener;
26 import org.netbeans.spi.options.OptionsPanelController;
27 import org.openide.util.NbBundle;
29 
33 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
34 final class IngestSettingsPanel extends IngestModuleGlobalSettingsPanel {
35 
36  IngestSettingsPanel() {
37  initComponents();
38  int availableProcessors = Runtime.getRuntime().availableProcessors();
39  Integer fileIngestThreadCountChoices[];
40  int recommendedFileIngestThreadCount;
41  if (availableProcessors >= 8) {
42  fileIngestThreadCountChoices = new Integer[]{1, 2, 4, 6, 8};
43  recommendedFileIngestThreadCount = 4;
44  } else if (availableProcessors >= 6) {
45  fileIngestThreadCountChoices = new Integer[]{1, 2, 4, 6};
46  recommendedFileIngestThreadCount = 4;
47  } else if (availableProcessors >= 4) {
48  fileIngestThreadCountChoices = new Integer[]{1, 2, 4};
49  recommendedFileIngestThreadCount = 2;
50  } else if (availableProcessors >= 2) {
51  fileIngestThreadCountChoices = new Integer[]{1, 2};
52  recommendedFileIngestThreadCount = 1;
53  } else {
54  fileIngestThreadCountChoices = new Integer[]{1};
55  recommendedFileIngestThreadCount = 1;
56  }
57  numberOfFileIngestThreadsComboBox.setModel(new DefaultComboBoxModel<>(fileIngestThreadCountChoices));
58  restartRequiredLabel.setText(NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.restartRequiredLabel.text", recommendedFileIngestThreadCount));
59  // TODO listen to changes in form fields and call controller.changed()
60  DocumentListener docListener = new DocumentListener() {
61 
62  @Override
63  public void insertUpdate(DocumentEvent e) {
64  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
65  }
66 
67  @Override
68  public void removeUpdate(DocumentEvent e) {
69  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
70  }
71 
72  @Override
73  public void changedUpdate(DocumentEvent e) {
74  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
75  }
76  };
77  this.jFormattedTextFieldProcTimeOutHrs.getDocument().addDocumentListener(docListener);
78  this.ingestWarningLabel.setVisible(false);
79  }
80 
84  void load() {
85  numberOfFileIngestThreadsComboBox.setSelectedItem(UserPreferences.numberOfFileIngestThreads());
86  if (UserPreferences.getIsTimeOutEnabled()) {
87  // user specified time out
88  jCheckBoxEnableProcTimeout.setSelected(true);
89  jFormattedTextFieldProcTimeOutHrs.setEditable(true);
90  int timeOutHrs = UserPreferences.getProcessTimeOutHrs();
91  jFormattedTextFieldProcTimeOutHrs.setValue((long) timeOutHrs);
92  } else {
93  // never time out
94  jCheckBoxEnableProcTimeout.setSelected(false);
95  jFormattedTextFieldProcTimeOutHrs.setEditable(false);
96  int timeOutHrs = UserPreferences.getProcessTimeOutHrs();
97  jFormattedTextFieldProcTimeOutHrs.setValue((long) timeOutHrs);
98  }
99  }
100 
104  void store() {
105  UserPreferences.setNumberOfFileIngestThreads((Integer) numberOfFileIngestThreadsComboBox.getSelectedItem());
106 
107  UserPreferences.setIsTimeOutEnabled(jCheckBoxEnableProcTimeout.isSelected());
108  if (jCheckBoxEnableProcTimeout.isSelected()) {
109  // only store time out if it is enabled
110  long timeOutHrs = (long) jFormattedTextFieldProcTimeOutHrs.getValue();
111  UserPreferences.setProcessTimeOutHrs((int) timeOutHrs);
112  }
113  }
114 
115  boolean valid() {
116  return true;
117  }
118 
124  void enableButtons(boolean isEnabled) {
125  numberOfFileIngestThreadsComboBox.setEnabled(isEnabled);
126  jFormattedTextFieldProcTimeOutHrs.setEnabled(isEnabled);
127  jCheckBoxEnableProcTimeout.setEnabled(isEnabled);
128  ingestWarningLabel.setVisible(!isEnabled);
129  }
130 
136  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
137  private void initComponents() {
138 
139  jScrollPane1 = new javax.swing.JScrollPane();
140  jPanel1 = new javax.swing.JPanel();
141  jLabelNumThreads = new javax.swing.JLabel();
142  numberOfFileIngestThreadsComboBox = new javax.swing.JComboBox<>();
143  restartRequiredLabel = new javax.swing.JLabel();
144  jLabelSetProcessTimeOut = new javax.swing.JLabel();
145  jCheckBoxEnableProcTimeout = new javax.swing.JCheckBox();
146  jFormattedTextFieldProcTimeOutHrs = new JFormattedTextField(NumberFormat.getIntegerInstance());
147  jLabelProcessTimeOutUnits = new javax.swing.JLabel();
148  ingestWarningLabel = new javax.swing.JLabel();
149 
150  setPreferredSize(new java.awt.Dimension(693, 413));
151 
152  jScrollPane1.setBorder(null);
153 
154  jPanel1.setPreferredSize(new java.awt.Dimension(664, 400));
155 
156  org.openide.awt.Mnemonics.setLocalizedText(jLabelNumThreads, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.jLabelNumThreads.text")); // NOI18N
157 
158  numberOfFileIngestThreadsComboBox.addActionListener(new java.awt.event.ActionListener() {
159  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  numberOfFileIngestThreadsComboBoxActionPerformed(evt);
161  }
162  });
163 
164  restartRequiredLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/warning16.png"))); // NOI18N
165  org.openide.awt.Mnemonics.setLocalizedText(restartRequiredLabel, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.restartRequiredLabel.text")); // NOI18N
166 
167  org.openide.awt.Mnemonics.setLocalizedText(jLabelSetProcessTimeOut, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.jLabelSetProcessTimeOut.text")); // NOI18N
168 
169  org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxEnableProcTimeout, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.jCheckBoxEnableProcTimeout.text")); // NOI18N
170  jCheckBoxEnableProcTimeout.addActionListener(new java.awt.event.ActionListener() {
171  public void actionPerformed(java.awt.event.ActionEvent evt) {
172  jCheckBoxEnableProcTimeoutActionPerformed(evt);
173  }
174  });
175 
176  jFormattedTextFieldProcTimeOutHrs.setText(org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.jFormattedTextFieldProcTimeOutHrs.text")); // NOI18N
177  jFormattedTextFieldProcTimeOutHrs.addActionListener(new java.awt.event.ActionListener() {
178  public void actionPerformed(java.awt.event.ActionEvent evt) {
179  jFormattedTextFieldProcTimeOutHrsActionPerformed(evt);
180  }
181  });
182 
183  org.openide.awt.Mnemonics.setLocalizedText(jLabelProcessTimeOutUnits, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.jLabelProcessTimeOutUnits.text")); // NOI18N
184 
185  ingestWarningLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/modules/hashdatabase/warning16.png"))); // NOI18N
186  org.openide.awt.Mnemonics.setLocalizedText(ingestWarningLabel, org.openide.util.NbBundle.getMessage(IngestSettingsPanel.class, "IngestSettingsPanel.ingestWarningLabel.text")); // NOI18N
187 
188  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
189  jPanel1.setLayout(jPanel1Layout);
190  jPanel1Layout.setHorizontalGroup(
191  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192  .addGroup(jPanel1Layout.createSequentialGroup()
193  .addContainerGap()
194  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
195  .addGroup(jPanel1Layout.createSequentialGroup()
196  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197  .addGroup(jPanel1Layout.createSequentialGroup()
198  .addGap(10, 10, 10)
199  .addComponent(numberOfFileIngestThreadsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
200  .addGap(18, 18, 18)
201  .addComponent(restartRequiredLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
202  .addGroup(jPanel1Layout.createSequentialGroup()
203  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addComponent(jLabelNumThreads)
205  .addComponent(jLabelSetProcessTimeOut)
206  .addGroup(jPanel1Layout.createSequentialGroup()
207  .addGap(10, 10, 10)
208  .addComponent(jCheckBoxEnableProcTimeout)
209  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210  .addComponent(jFormattedTextFieldProcTimeOutHrs, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
211  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
212  .addComponent(jLabelProcessTimeOutUnits)))
213  .addGap(213, 213, 213)))
214  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
215  .addGroup(jPanel1Layout.createSequentialGroup()
216  .addComponent(ingestWarningLabel)
217  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
218  );
219  jPanel1Layout.setVerticalGroup(
220  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221  .addGroup(jPanel1Layout.createSequentialGroup()
222  .addGap(30, 30, 30)
223  .addComponent(jLabelNumThreads)
224  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
225  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
226  .addComponent(numberOfFileIngestThreadsComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
227  .addComponent(restartRequiredLabel))
228  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
229  .addComponent(jLabelSetProcessTimeOut)
230  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
231  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232  .addComponent(jCheckBoxEnableProcTimeout)
233  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
234  .addComponent(jFormattedTextFieldProcTimeOutHrs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
235  .addComponent(jLabelProcessTimeOutUnits)))
236  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
237  .addComponent(ingestWarningLabel)
238  .addContainerGap(257, Short.MAX_VALUE))
239  );
240 
241  jScrollPane1.setViewportView(jPanel1);
242 
243  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
244  this.setLayout(layout);
245  layout.setHorizontalGroup(
246  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
248  );
249  layout.setVerticalGroup(
250  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251  .addComponent(jScrollPane1)
252  );
253  }// </editor-fold>//GEN-END:initComponents
254 
255  private void jFormattedTextFieldProcTimeOutHrsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldProcTimeOutHrsActionPerformed
256  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
257  }//GEN-LAST:event_jFormattedTextFieldProcTimeOutHrsActionPerformed
258 
259  private void jCheckBoxEnableProcTimeoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEnableProcTimeoutActionPerformed
260  jFormattedTextFieldProcTimeOutHrs.setEditable(jCheckBoxEnableProcTimeout.isSelected());
261  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
262  }//GEN-LAST:event_jCheckBoxEnableProcTimeoutActionPerformed
263 
264  private void numberOfFileIngestThreadsComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_numberOfFileIngestThreadsComboBoxActionPerformed
265  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
266  }//GEN-LAST:event_numberOfFileIngestThreadsComboBoxActionPerformed
267 
268  // Variables declaration - do not modify//GEN-BEGIN:variables
269  private javax.swing.JLabel ingestWarningLabel;
270  private javax.swing.JCheckBox jCheckBoxEnableProcTimeout;
271  private javax.swing.JFormattedTextField jFormattedTextFieldProcTimeOutHrs;
272  private javax.swing.JLabel jLabelNumThreads;
273  private javax.swing.JLabel jLabelProcessTimeOutUnits;
274  private javax.swing.JLabel jLabelSetProcessTimeOut;
275  private javax.swing.JPanel jPanel1;
276  private javax.swing.JScrollPane jScrollPane1;
277  private javax.swing.JComboBox<Integer> numberOfFileIngestThreadsComboBox;
278  private javax.swing.JLabel restartRequiredLabel;
279  // End of variables declaration//GEN-END:variables
280 
281  @Override
282  public void saveSettings() {
283  this.store();
284  }
285 }

Copyright © 2012-2022 Basis Technology. Generated on: Wed Oct 5 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.