Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
RawDSInputPanel.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.datasourceprocessors;
20 
21 import java.io.File;
22 import java.util.Calendar;
23 import java.util.List;
24 import javax.swing.JFileChooser;
25 import javax.swing.JPanel;
26 import javax.swing.event.DocumentEvent;
27 import javax.swing.event.DocumentListener;
28 import org.openide.util.NbBundle.Messages;
36 
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
41 final class RawDSInputPanel extends JPanel implements DocumentListener {
42  private static final long TWO_GB = 2000000000L;
43  private static final long serialVersionUID = 1L; //default
44  private final String PROP_LASTINPUT_PATH = "LBL_LastInputFile_PATH";
45  private JFileChooser fc;
46  private JFileChooserFactory chooserHelper = new JFileChooserFactory();
47  // Externally supplied name is used to store settings
48  private final String contextName;
52  private RawDSInputPanel(String context) {
53  initComponents();
54 
55  errorLabel.setVisible(false);
56  this.contextName = context;
57  }
58 
62  static synchronized RawDSInputPanel createInstance(String context) {
63  RawDSInputPanel instance = new RawDSInputPanel(context);
64 
65  instance.postInit();
66  instance.createTimeZoneList();
67 
68  return instance;
69  }
70 
71  //post-constructor initialization to properly initialize listener support
72  //without leaking references of uninitialized objects
73  private void postInit() {
74  pathTextField.getDocument().addDocumentListener(this);
75  }
76 
81  private void createTimeZoneList() {
82  List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
83  for (String timeZone : timeZoneList) {
84  timeZoneComboBox.addItem(timeZone);
85  }
86 
87  // set the selected timezone
88  timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
89  }
90 
96  @SuppressWarnings("unchecked")
97  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
98  private void initComponents() {
99 
100  infileTypeButtonGroup = new javax.swing.ButtonGroup();
101  pathLabel = new javax.swing.JLabel();
102  pathTextField = new javax.swing.JTextField();
103  browseButton = new javax.swing.JButton();
104  j2GBBreakupRadioButton = new javax.swing.JRadioButton();
105  jBreakFileUpLabel = new javax.swing.JLabel();
106  jNoBreakupRadioButton = new javax.swing.JRadioButton();
107  errorLabel = new javax.swing.JLabel();
108  timeZoneLabel = new javax.swing.JLabel();
109  timeZoneComboBox = new javax.swing.JComboBox<>();
110 
111  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathLabel.text")); // NOI18N
112 
113  pathTextField.setText(org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathTextField.text")); // NOI18N
114 
115  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.browseButton.text")); // NOI18N
116  browseButton.addActionListener(new java.awt.event.ActionListener() {
117  public void actionPerformed(java.awt.event.ActionEvent evt) {
118  browseButtonActionPerformed(evt);
119  }
120  });
121 
122  infileTypeButtonGroup.add(j2GBBreakupRadioButton);
123  j2GBBreakupRadioButton.setSelected(true);
124  org.openide.awt.Mnemonics.setLocalizedText(j2GBBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.j2GBBreakupRadioButton.text")); // NOI18N
125  j2GBBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
126  public void actionPerformed(java.awt.event.ActionEvent evt) {
127  j2GBBreakupRadioButtonActionPerformed(evt);
128  }
129  });
130 
131  org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jBreakFileUpLabel.text")); // NOI18N
132 
133  infileTypeButtonGroup.add(jNoBreakupRadioButton);
134  org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jNoBreakupRadioButton.text")); // NOI18N
135  jNoBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
136  public void actionPerformed(java.awt.event.ActionEvent evt) {
137  jNoBreakupRadioButtonActionPerformed(evt);
138  }
139  });
140 
141  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
142  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.errorLabel.text")); // NOI18N
143 
144  org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.timeZoneLabel.text")); // NOI18N
145 
146  timeZoneComboBox.setMaximumRowCount(30);
147 
148  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
149  this.setLayout(layout);
150  layout.setHorizontalGroup(
151  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152  .addGroup(layout.createSequentialGroup()
153  .addComponent(pathTextField)
154  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
155  .addComponent(browseButton))
156  .addGroup(layout.createSequentialGroup()
157  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158  .addComponent(pathLabel)
159  .addGroup(layout.createSequentialGroup()
160  .addComponent(timeZoneLabel)
161  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
163  .addGap(0, 0, Short.MAX_VALUE))
164  .addGroup(layout.createSequentialGroup()
165  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addComponent(jBreakFileUpLabel)
167  .addComponent(errorLabel)
168  .addGroup(layout.createSequentialGroup()
169  .addGap(10, 10, 10)
170  .addComponent(j2GBBreakupRadioButton)
171  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
172  .addComponent(jNoBreakupRadioButton)))
173  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
174  );
175  layout.setVerticalGroup(
176  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177  .addGroup(layout.createSequentialGroup()
178  .addComponent(pathLabel)
179  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
180  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
181  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182  .addComponent(browseButton))
183  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
185  .addComponent(timeZoneLabel)
186  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
187  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188  .addComponent(errorLabel)
189  .addGap(5, 5, 5)
190  .addComponent(jBreakFileUpLabel)
191  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
192  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193  .addComponent(jNoBreakupRadioButton)
194  .addComponent(j2GBBreakupRadioButton))
195  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
196  );
197  }// </editor-fold>//GEN-END:initComponents
198  @SuppressWarnings("deprecation")
199  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
200  if (fc == null) {
201  fc = chooserHelper.getChooser();
202  fc.setDragEnabled(false);
203  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
204  fc.setMultiSelectionEnabled(false);
205  }
206 
207  String oldText = pathTextField.getText();
208  // set the current directory of the FileChooser if the ImagePath Field is valid
209  File currentDir = new File(oldText);
210  if (currentDir.exists()) {
211  fc.setCurrentDirectory(currentDir);
212  }
213 
214  int retval = fc.showOpenDialog(this);
215  if (retval == JFileChooser.APPROVE_OPTION) {
216  String path = fc.getSelectedFile().getPath();
217  pathTextField.setText(path);
218  }
219  }//GEN-LAST:event_browseButtonActionPerformed
220 
221  private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_j2GBBreakupRadioButtonActionPerformed
222  // TODO add your handling code here:
223  }//GEN-LAST:event_j2GBBreakupRadioButtonActionPerformed
224 
225  private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNoBreakupRadioButtonActionPerformed
226  // TODO add your handling code here:
227  }//GEN-LAST:event_jNoBreakupRadioButtonActionPerformed
228 
229  // Variables declaration - do not modify//GEN-BEGIN:variables
230  private javax.swing.JButton browseButton;
231  private javax.swing.JLabel errorLabel;
232  private javax.swing.ButtonGroup infileTypeButtonGroup;
233  private javax.swing.JRadioButton j2GBBreakupRadioButton;
234  private javax.swing.JLabel jBreakFileUpLabel;
235  private javax.swing.JRadioButton jNoBreakupRadioButton;
236  private javax.swing.JLabel pathLabel;
237  private javax.swing.JTextField pathTextField;
238  private javax.swing.JComboBox<String> timeZoneComboBox;
239  private javax.swing.JLabel timeZoneLabel;
240  // End of variables declaration//GEN-END:variables
246  String getImageFilePath() {
247  return pathTextField.getText();
248  }
249 
250  void reset() {
251  //reset the UI elements to default
252  pathTextField.setText(null);
253  j2GBBreakupRadioButton.setSelected(true);
254  }
255 
256  long getChunkSize() {
257  if (jNoBreakupRadioButton.isSelected()) {
258  return -1;
259  } else { //if have more choices here, the selection of each radiobutton should be checked
260  return TWO_GB;
261  }
262  }
263 
264  String getTimeZone() {
265  String tz = timeZoneComboBox.getSelectedItem().toString();
266  return tz.substring(tz.indexOf(")") + 2).trim();
267  }
268 
274  boolean validatePanel() {
275  errorLabel.setVisible(false);
276  String path = getImageFilePath();
277  if (path == null || path.isEmpty()) {
278  return false;
279  }
280 
281  // display warning if there is one (but don't disable "next" button)
282  warnIfPathIsInvalid(path);
283 
284  boolean isExist = new File(path).exists();
285 
286  return (isExist);
287  }
288 
295  @Messages({"RawDSInputPanel.error.text=Path to multi-user data source is on \"C:\" drive",
296  "RawDSInputPanel.noOpenCase.errMsg=Exception while getting open case."})
297  private void warnIfPathIsInvalid(String path) {
298  try {
299  if (!PathValidator.isValidForCaseType(path, Case.getCurrentCaseThrows().getCaseType())) {
300  errorLabel.setVisible(true);
301  errorLabel.setText(Bundle.RawDSInputPanel_error_text());
302  }
303  } catch (NoCurrentCaseException ex) {
304  errorLabel.setVisible(true);
305  errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
306  }
307  }
308 
309  void storeSettings() {
310  String inFilePath = getImageFilePath();
311  if (null != inFilePath) {
312  String imagePath = inFilePath.substring(0, inFilePath.lastIndexOf(File.separator) + 1);
313  ModuleSettings.setConfigSetting(contextName, PROP_LASTINPUT_PATH, imagePath);
314  }
315  }
316 
317  void readSettings() {
318  String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
319  if (null != inFilePath) {
320  if (!inFilePath.isEmpty()) {
321  pathTextField.setText(inFilePath);
322  }
323  }
324  }
325 
333  @Override
334  public void insertUpdate(DocumentEvent e) {
335  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
336  }
337 
338  @Override
339  public void removeUpdate(DocumentEvent e) {
340  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
341  }
342 
343  @Override
344  public void changedUpdate(DocumentEvent e) {
345  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
346  }
347 
351  void select() {
352  pathTextField.requestFocusInWindow();
353  }
354 }

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